From patchwork Thu Sep 29 22:29:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 12994692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC61BC433F5 for ; Thu, 29 Sep 2022 22:31:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72ED38D000B; Thu, 29 Sep 2022 18:31:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DEEF8D0007; Thu, 29 Sep 2022 18:31:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57FE48D000B; Thu, 29 Sep 2022 18:31:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 49EA68D0007 for ; Thu, 29 Sep 2022 18:31:28 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AC5AD1413B2 for ; Thu, 29 Sep 2022 22:31:27 +0000 (UTC) X-FDA: 79966570614.10.C8F3848 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf24.hostedemail.com (Postfix) with ESMTP id 0CA97180013 for ; Thu, 29 Sep 2022 22:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490687; x=1696026687; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=u9CznCATrsGnwa8pqTQLU3Taz6CK/euF7IU8I3CM4v4=; b=SPWjuh5+iFVJ+XTdS20s4WLziKgJcth43ph6Y7JAluihDsMReYRZ9JVC NnDtcfZqr0CEw5zkQ7hxEM+16sUNjUfT2AIma+/lqY7c3lTUI/jcBlNZX fAWY5Uej+PKFIIQs47F9Dy6T7kj9KxSQAYAEod9L9N7cH6m19PjIrBNHW 7kBUupuW0ZAtvvDocShW23v1pt/Ghpb1x1lU6GWwbs66vqDX/rn2jz3kD Y1y7rNBpJFSSg82joad3/Ri4sA3ZF41vTkUsFfUadcraNQs4xJ78z9lpB +vHQnWr4/MQJudsvsQOzz/4Dbev9SiRznC4nNNmk2fE6ok8oS2qfMAp3Z g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="302015655" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="302015655" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:31:06 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="691016413" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="691016413" Received: from sergungo-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.251.25.88]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:31:04 -0700 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Cc: rick.p.edgecombe@intel.com, Mike Rapoport Subject: [OPTIONAL/RFC v2 38/39] x86/cet/shstk: Add ARCH_CET_UNLOCK Date: Thu, 29 Sep 2022 15:29:35 -0700 Message-Id: <20220929222936.14584-39-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664490687; a=rsa-sha256; cv=none; b=RHlMptEL6SWGbcz/08G0OQUt74pDg94+zbJ+Ww9+PH3p8sIto4OR5QhQv+ZFI3kuHq9qOP EWQCuTrBGGRqXC51CfSNgMz3yUghvzs3E+t4ipjy/lqKo44qC5b/eMTitbGBHdU2uW22Xq Lomoyual4ZXb845YIIFJY7R8xZnb9Hw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=SPWjuh5+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664490687; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=efT3MnxieyXninwXrxTo6VFUs2I4x2OETTRzAB+4ThM=; b=gEXpowICawXjWvwJrnRUKmNRRurtQ2c8/26UtoSluEkGEOqpkVekDMIUlyClyeImAAxMH7 NbaMsdhkjU1gp1LQ/qFe6Gjj+/ia6QezmXnt6hR65wRl3H5VO0Boj6RFux+hcV/CHf/PMa KOcwRKjyjW/J1Q8LDA2gy6pL0LS5ego= X-Rspamd-Queue-Id: 0CA97180013 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=SPWjuh5+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com X-Rspamd-Server: rspam03 X-Stat-Signature: qaqgt9j6ah1d8t38menpcgwrhrxd3ex4 X-HE-Tag: 1664490686-961850 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Mike Rapoport Userspace loaders may lock features before a CRIU restore operation has the chance to set them to whatever state is required by the process being restored. Allow a way for CRIU to unlock features. Add it as an arch_prctl() like the other CET operations, but restrict it being called by the ptrace arch_pctl() interface. Signed-off-by: Mike Rapoport [Merged into recent API changes, added commit log and docs] Signed-off-by: Rick Edgecombe --- v2: - New patch Documentation/x86/cet.rst | 3 +++ arch/x86/include/uapi/asm/prctl.h | 1 + arch/x86/kernel/process_64.c | 1 + arch/x86/kernel/shstk.c | 9 +++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/x86/cet.rst b/Documentation/x86/cet.rst index 4a0dfb6830f9..6b270a24ebc3 100644 --- a/Documentation/x86/cet.rst +++ b/Documentation/x86/cet.rst @@ -81,6 +81,9 @@ arch_prctl(ARCH_CET_DISABLE, unsigned int feature) arch_prctl(ARCH_CET_LOCK, unsigned int features) Lock in features at their current enabled or disabled status. +arch_prctl(ARCH_CET_UNLOCK, unsigned int features) + Unlock features. + The return values are as following: On success, return 0. On error, errno can be:: diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index d811f0c5fc4f..2f4d81ab4849 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -25,6 +25,7 @@ #define ARCH_CET_ENABLE 0x4001 #define ARCH_CET_DISABLE 0x4002 #define ARCH_CET_LOCK 0x4003 +#define ARCH_CET_UNLOCK 0x4004 #define CET_SHSTK 0x1 #define CET_WRSS 0x2 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index be544b4b4c8b..fbb2062dd0d2 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -834,6 +834,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_CET_ENABLE: case ARCH_CET_DISABLE: case ARCH_CET_LOCK: + case ARCH_CET_UNLOCK: return cet_prctl(task, option, arg2); default: ret = -EINVAL; diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index 0efec02dbe6b..af1255164f0c 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -464,9 +464,14 @@ long cet_prctl(struct task_struct *task, int option, unsigned long features) return 0; } - /* Don't allow via ptrace */ - if (task != current) + /* Only allow via ptrace */ + if (task != current) { + if (option == ARCH_CET_UNLOCK) { + task->thread.features_locked &= ~features; + return 0; + } return -EINVAL; + } /* Do not allow to change locked features */ if (features & task->thread.features_locked)