From mboxrd@z Thu Jan 1 00:00:00 1970 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 D1427C64ED8 for ; Mon, 27 Feb 2023 22:32:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CC906B00AF; Mon, 27 Feb 2023 17:32:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 97CE06B00B0; Mon, 27 Feb 2023 17:32:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F5D06B00B1; Mon, 27 Feb 2023 17:32:05 -0500 (EST) 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 528AF6B00B0 for ; Mon, 27 Feb 2023 17:32:05 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 24493140948 for ; Mon, 27 Feb 2023 22:32:05 +0000 (UTC) X-FDA: 80514521010.01.53A89B1 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf07.hostedemail.com (Postfix) with ESMTP id 269894000C for ; Mon, 27 Feb 2023 22:32:02 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VJfwSzu0; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf07.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 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=1677537123; 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=s3SKx8uA87FhB8rouLjfRqrxDp5yHfGp17WLKTIWOmg=; b=oxcuNAI3VmO+BVvjSKw80VeX3IjBqFXF1mNY7pjZJz/IYnFhzFzxTenNUVabd8vZkQ/YCl B+CxbgGRS4uUPr6x6N0nEFOAvP/fN/0DxQ0dhLPlZ6uj9jbl7F9k+QllR+u/yOV8TVP35x VQI8k4SCwxDJHjFU21MnwWRGuEn99zU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VJfwSzu0; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf07.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677537123; a=rsa-sha256; cv=none; b=mHC4ucTyjqL1HtWtX9dq8x2btZVnXZ+nE5uTbngRDzIg58Vtohj9/Q0i+NgfOb3NL0moF2 xXNWOk9izK5ZB3LjK0vjfUeXk3e6IyoYjWLDt1GWNxMTPRkyUxVuQvRKbbv2p8bJGZzT+E xPp/llE5laFYWlgHVXzQpT+d5lEaOuY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537123; x=1709073123; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dUBKpkq7gq2yOqJjADRSuNiVlevkRQtTmCsetlkcYh0=; b=VJfwSzu0Zj+YbUyeWPqv/F/UsZsFJ2JoPo2f1bso8OLj0/iObvkmuzXr 1KtVLXb3+AntPhYvCrHg9d7FhibyXIeK4OC7YzrQQhotFjoBBTJkUWFDE sNvfeooDFLtAta5Zz9afFcthpRdg67XSGyJjrPTY2EcuMhWDkQaKVQYvt IbKAHHw93HM5JMjof0OZy69+6QYPeexP+wzUbYpLGUjO0L6mH+yc5KSSB d2JkozeUKIh49OO6eI9fa0fUh/TetzztK9ozkNaZwFk5HhLzzEJUDQNtq kH3Bv7coN1e33xshqR1V+Yn26of3TGVif+2v8kAcQi8QT5A+623PAs3uc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313658007" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313658007" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024827" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024827" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:37 -0800 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 Cc: rick.p.edgecombe@intel.com Subject: [PATCH v7 41/41] x86/shstk: Add ARCH_SHSTK_STATUS Date: Mon, 27 Feb 2023 14:29:57 -0800 Message-Id: <20230227222957.24501-42-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 269894000C X-Stat-Signature: bt9uft31rhxi7kmzo95k1cfpyokumjwj X-HE-Tag: 1677537122-899982 X-HE-Meta: U2FsdGVkX19MspJwkd+q7i2dUYOC17WqxV60bB3dcB20sbxZEMkGTPOg72MMYLNbk1S6ff4HQlgQLEQlf6l9GCCAxcO5tYeD4Uwd8Q8UpoPvYwz7JS3LlxLnN/2h21JTGGs5i/5s2cYxXKrmEa7F8zu826bRF1R6FEv3taiDoYNP3B76tIpFzYTOxlcWZuvyPqsziM0pSDFJB1cykE8AyK6uLgh1xSuGGdvDDBV96JPIIjbb86Vzfsz8jU8eCUy84ZUZ2N5heP9WhFjqvDzSdcVJvs9BWeXUpxv3RkjjGq8Oo+IlySKi718IimO3oEGwtJy7wbTgTZWP+z/Nvjmzhl+Y2XIAlay7GZdiE7kyMQpIx1lY5UVnpCGVQCPfnla/ohWB/wSwMC8wbAd3GOF54weNJ1mBR88c4jkv+x8m25YwQ8H4A7RyYOnxq1JJekVDwpIKRYzLXSVn9Ymz3I9Ut3h7YvvKkcBz0k6ADJIkGqv1tB9FvqThHOOW58Ymf/13mPkKEY98tXWxUWc9D6x6uwjo3OHwtxUJoWuU4CK/t3IhHhCB9nkxr1ZsKWlzj4V2Fb6CSrQIgv0c4w/W8X9sQTRakYD7DjbR2YcS0FFkE5DPxcdxdlqySgqoEvwsiPmr8STDlVcFDwySRTIzhy3tjG/HMKTcJZQ58BtnOanw0XxZo9Le8Jc3zLDuTjdUFgYYBWLYeqFLd8dk1bYq5otc51qxSRPtopiUV6W44UhO7PR5ORea2Sfv90n4K8SKmKwNOBYEr/fXTAkXt/eH3hWQpQ1UlJyFtJSBFWd0uYcXlx3L+JsUuqurTTZUWdJInm0iwolxsixI5R8ZPvUyCzUj6fY2GaBdwGw8lgvBwX7ntffstfipBXshxsJqWFjWpQGxlevdJld+aBsSxG1KDQX6Jsl40E8xCFuwdMJX2ZJ9nEZCSkaYS129Nim/jeIVCVTsGKldb1+4LS9qNQMNcMj HBB+JkQO t7v7YTKj03La85g+EqI6tWw7wRep8vUd3nZYB5b3fhK3tXawdqmqJFqaKISj5eCsVGBjhb8ULVAWD217teBjr7hlf0j+wDcBk+j6T9mBYqV8vLilL8cxLRX+zxgDjORU5L1AX5DDy3dq7Ahb3dudgsKCB9qq7jDjatcCUtxgTz4ctfzW9EQHGi1uuJGLLQ+X/ybQHzqAe30/RTLKNTiX6colB9Q49UuTVDPCEM61VJ/Kv2s4DoUp13Jxa1xZm7153s0BaQHeenzDHvB2HyXoFhl19YGPthHWUxLsCzqmJdkryp4vUxNA+SJO2CE3OnWZnEvwgWKrsk89auD7Xm560rudZKRHs7c3hrqQzODXPmOgZPfDve+0IBDaEdgAYpuNXtJTW8C6hMiQwi/x37xQ6sN+deg== 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. Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Kees Cook Suggested-by: Mike Rapoport Signed-off-by: Rick Edgecombe --- 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 e8ed5fc0f7ae..7f4af798794e 100644 --- a/Documentation/x86/shstk.rst +++ b/Documentation/x86/shstk.rst @@ -77,6 +77,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:: @@ -84,6 +89,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 acee68d30a07..be9267897211 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); int 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 d368854fa9c4..dde43caf196e 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 3197ff824809..4069d5bbbe8c 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -444,8 +444,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; -- 2.17.1