From patchwork Sun Mar 19 00:15:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13180168 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 DC23EC76196 for ; Sun, 19 Mar 2023 00:17:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C4D1280027; Sat, 18 Mar 2023 20:17:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E2C280001; Sat, 18 Mar 2023 20:17:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C7E7280027; Sat, 18 Mar 2023 20:17:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 45F3B280001 for ; Sat, 18 Mar 2023 20:17:04 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2C1441C6408 for ; Sun, 19 Mar 2023 00:17:04 +0000 (UTC) X-FDA: 80583732768.06.067F3CC Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf26.hostedemail.com (Postfix) with ESMTP id 2F0DF140009 for ; Sun, 19 Mar 2023 00:17:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Th8bpQt/"; spf=pass (imf26.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679185022; 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=hX1tIQjv6wLpquj+NXtr3HDoyM4MQw0DYXnBn2j4x04=; b=NNy4sqzAj46rmi+d1xwb/7VB4ml2i3aYtiJWlowUByV39CeMcwZu1X8oGdN5mGdWzySNjK 5yhmJgMmYKzJKw2mf6s5UFZqmLzVj9wv3Ef0VmVIZY0JEhtWMlrONClIcxMt8TjmiJLAuW wcRGNt7I7ezLTD6PZDmX01lDDnfEgVk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Th8bpQt/"; spf=pass (imf26.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679185022; a=rsa-sha256; cv=none; b=zNh3jNGAJ8vEaZx4JU986oidDdHI97uo83txOJt1X/koAgSs8qQAAxZA2ZqZki8I19pywv 6u3YkzN0BXnSy9bqLya3vUkkysjwTgc3mzoLFN+0MqQC3NIrQuY/1wYOxyemwPTXWf1UlT gqBuhkzOtyIzOZv/efYcYeK914aNRd4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679185022; x=1710721022; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=NaxDC9okCEIT/JhArq/4DzJUEPU99GVMAiUn52jAzaM=; b=Th8bpQt/zHORMCzNayQLUs3HPcvbNyCa+HZqugCQh5UfylDgwu5rhD0F /U95TSYjhv7ICdJvpMe18UxzCqsiv3Z4q/kUIlduiObFgYdH5+3wWjD0l 2hHJTI8XffQFhyAlgK1imJmkB/FKorj3uvteXeR2ESJeZyr3XaW86maKm WLf+a4dG8DXseVfBePUAN0EKU4cLt01vdVAED4cavaDd0tAX9MT27EPkp YK9SJLTdIbuUGCr/voypQOGxHwCvM2wTYaDofI/H5o2L7/VLKzUbORaMM mIiJWuc2FnGys1+MqyiF4bjwENy2/+Fg4RDvXj6u6cCPnFD1rp+R75XA/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338491638" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338491638" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:17:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="749673030" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="749673030" Received: from bmahatwo-mobl1.gar.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.135.34.5]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:59 -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 , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com, szabolcs.nagy@arm.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH v8 40/40] x86/shstk: Add ARCH_SHSTK_STATUS Date: Sat, 18 Mar 2023 17:15:35 -0700 Message-Id: <20230319001535.23210-41-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com> References: <20230319001535.23210-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2F0DF140009 X-Stat-Signature: x6zha3wgmy3ipoctfxs4tq1i98uhzscs X-Rspam-User: X-HE-Tag: 1679185022-972268 X-HE-Meta: U2FsdGVkX1+J53zbqDbjgGqhjRaKKaC9KNYnaUm+MOC/prYiwYQ18blMaIiNRHk4gq26CIbVa7yxVZYRYH6LTFkFzXyPE+tS7rD/HqI1hZI++JDDOKfBEclPPxr1RDakoAgQVx5ZR3ACooT4DR0XCZV0Tos63vPgTrLMUHVCi5WVf/nMEQihT15wq/G5I6lqeKXvaAa3C6Wh7ycz1Fv8gG4uvn2FA+yS46v9Bfhf1HiMvMjDzkfJGnsyBrGqlwzWygD/8PhZ8oooPsab+lNu3dvfLgQmFxPm5WsXDjJrCiw9fzet/sy2U7+Xdfzu9wMij47x3JoVGVaU4dB1rPEys6NPI5Jf5Bdx8zEWUXhGLvEriV7xtdhOThoZQH+eynPQY3xNb15oehKRrTxHfsoYiqlXJcD6Yvur78siOVq7x5bYZyfSxMFpbRKgJUGt4pMAgwgSTEk+N4eXyKen87QxBLhcIbgREaEixN0ocqnGyDGTtOknWOCNcsWjIyKvEM1kC4JHLaNktWo9sDuK/oZUyeoBN8u5k9Ov1zeGbh5cVhxaschFpB6zS6AJoeJc/7A2HsjKRmDCHFJWB1DEtTiNJbMHIjda8VeXSomuva3229JfYJJ+HBPTOWb4S+ExZlSpgmmvnGT65tGCFU4LxDho7TxO9msMX8rkVQXILmv+yzio98yBpY3elMYcvHAQB0CnxGL8mXGuaWPgJdvV85N4547fycTstU1dSuzY+xJVas4AIFkBMiTLhQRGXSajwBbK158CA0bOd0AHogKI+4THi8XYSfhfUB0VwTb/DZjcTbe6ih5glUo3r+2qb3BYTh2B1sJAv4D9LtAaqJIPEj/YL7Y+whswpqyqawxCk0CWR/etwVe2hulL7FTSeT6rcw+4LHo0ckFdkVkMW4T9AzltzSQdzjOtlshADOau1pSUqEp5DWv72MwN4iyoRVjAF+TZaEenyv13FkcudrqXp0W rx3vv2uh ughqVq81I9XbinTCmU1zM+mEXox+itv8G1tWpvbsQBnxXGcyQzsp97RRXf+A/mk6GUaFhnSwXtBfvFLhuJ8gyLh8Beojp6y1UDaOmlful3SIHeCgAoSJLgsyxOd0bbu26965UaEZorTZV8YCgpzVFarV3f/+hYtGGtfgSBuTgSEPBgy59nlRByftCgpHNnPdukPuhKVQqwDV8HZvIvx3l5xy1XYamuPyEaBoaV6RYERUuI0ime6cAyb4y21OSlclYTtaR1JaUidii5g9sCC7LQvRkpIDN+DgtnmSBktq+4RNbVnFMJLZDfsTRW6X8Y2vlwlo4mfzQhr/7VORbwcIua9TbqKIr5cZDS9Zkcq6SZw+hBDhrw+UpS3DYjZ/muYCniYFV2J/VRuCAap/wRSD96rsi+w== 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: CRIU and GDB need to get the current shadow stack and WRSS enablement status. This information is already available via /proc/pid/status, but this is inconvenient for CRIU because it involves parsing the text output in an area of the code where this is difficult. Provide a status arch_prctl(), ARCH_SHSTK_STATUS for retrieving the status. Have arg2 be a userspace address, and make the new arch_prctl simply copy the features out to userspace. Suggested-by: Mike Rapoport Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook --- v5: - Fix typo in commit log v4: - New patch --- Documentation/x86/shstk.rst | 6 ++++++ arch/x86/include/asm/shstk.h | 2 +- arch/x86/include/uapi/asm/prctl.h | 1 + arch/x86/kernel/process_64.c | 1 + arch/x86/kernel/shstk.c | 8 +++++++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/x86/shstk.rst b/Documentation/x86/shstk.rst index f3553cc8c758..60260e809baf 100644 --- a/Documentation/x86/shstk.rst +++ b/Documentation/x86/shstk.rst @@ -79,6 +79,11 @@ arch_prctl(ARCH_SHSTK_UNLOCK, unsigned long features) Unlock features. 'features' is a mask of all features to unlock. All bits set are processed, unset bits are ignored. Only works via ptrace. +arch_prctl(ARCH_SHSTK_STATUS, unsigned long addr) + Copy the currently enabled features to the address passed in addr. The + features are described using the bits passed into the others in + 'features'. + The return values are as follows. On success, return 0. On error, errno can be:: @@ -86,6 +91,7 @@ be:: -ENOTSUPP if the feature is not supported by the hardware or kernel. -EINVAL arguments (non existing feature, etc) + -EFAULT if could not copy information back to userspace The feature's bits supported are:: diff --git a/arch/x86/include/asm/shstk.h b/arch/x86/include/asm/shstk.h index ecb23a8ca47d..42fee8959df7 100644 --- a/arch/x86/include/asm/shstk.h +++ b/arch/x86/include/asm/shstk.h @@ -14,7 +14,7 @@ struct thread_shstk { u64 size; }; -long shstk_prctl(struct task_struct *task, int option, unsigned long features); +long shstk_prctl(struct task_struct *task, int option, unsigned long arg2); void reset_thread_features(void); unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned long clone_flags, unsigned long stack_size); diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index 200efbbe5809..1b85bc876c2d 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -26,6 +26,7 @@ #define ARCH_SHSTK_DISABLE 0x5002 #define ARCH_SHSTK_LOCK 0x5003 #define ARCH_SHSTK_UNLOCK 0x5004 +#define ARCH_SHSTK_STATUS 0x5005 /* ARCH_SHSTK_ features bits */ #define ARCH_SHSTK_SHSTK (1ULL << 0) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 69d4ccaef56f..31241930b60c 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -836,6 +836,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_SHSTK_DISABLE: case ARCH_SHSTK_LOCK: case ARCH_SHSTK_UNLOCK: + case ARCH_SHSTK_STATUS: return shstk_prctl(task, option, arg2); default: ret = -EINVAL; diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index ad336ab55ace..1f767c509ee9 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -452,8 +452,14 @@ SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsi return alloc_shstk(addr, aligned_size, size, set_tok); } -long shstk_prctl(struct task_struct *task, int option, unsigned long features) +long shstk_prctl(struct task_struct *task, int option, unsigned long arg2) { + unsigned long features = arg2; + + if (option == ARCH_SHSTK_STATUS) { + return put_user(task->thread.features, (unsigned long __user *)arg2); + } + if (option == ARCH_SHSTK_LOCK) { task->thread.features_locked |= features; return 0;