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 3D688C4321E for ; Sat, 3 Dec 2022 02:57:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFDD86B0071; Fri, 2 Dec 2022 21:57:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B877C6B0072; Fri, 2 Dec 2022 21:57:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A02DA6B0073; Fri, 2 Dec 2022 21:57:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 905B36B0071 for ; Fri, 2 Dec 2022 21:57:29 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5EE21120382 for ; Sat, 3 Dec 2022 02:57:29 +0000 (UTC) X-FDA: 80199484218.09.293908E Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf30.hostedemail.com (Postfix) with ESMTP id 049108000F for ; Sat, 3 Dec 2022 02:57:28 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=K2FfUaFy; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.45 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670036249; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iYhtF06rN01RiKVEwYrT8rPN0UmjLM22d78NkfSy5+o=; b=b9aWWcsdkNyQCDz1qedlbhU5R3k+iwP86RRXUJdmNSn/fplmccpRSN6xE01k8s1MLszvkp zVd+u7fLrctVgmdVr8uZfSZc4WSe2RgP2Yc0o8kLW2hkHyAQevu7A8x1UVj8d+c6Ul2I0j 0SOxeERpmVDpxIN7cX3RhHbjGDktc4U= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=K2FfUaFy; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.45 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670036249; a=rsa-sha256; cv=none; b=QhSXnB8GQQkOktXCgxCUNapMXa+P+eJtav0Aaa8gXweXHVoKT4tpV3ccim93Kgwp9IGx1s M+5zlPvesEnjzztpiuxe5y2RJPZfb3i+Nl6/HabtwX+BA7zXsiSyEuUOCaRUPjNyfrZG0J UEnU4elwUDg13od97ZUpdblCd5jwvoU= Received: by mail-pj1-f45.google.com with SMTP id x13-20020a17090a46cd00b00218f611b6e9so6723862pjg.1 for ; Fri, 02 Dec 2022 18:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iYhtF06rN01RiKVEwYrT8rPN0UmjLM22d78NkfSy5+o=; b=K2FfUaFyurPTkWOam4j+V72ut4fmD7TRNO64G3a4dBllPRstKCKXLTONhpMSIHWNfh LU0I4KJfF6+4lY1r3y7ihKn16vV3SDNcKKijAo6PGaXpzrMiVHhu40kJavVZbq6IYVBF n65aP1y46hMojSq8pi5plIXamOGD1p/1n4EWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iYhtF06rN01RiKVEwYrT8rPN0UmjLM22d78NkfSy5+o=; b=ZOiGI9lR+xJoz3OPzDVwX9lizyyvfDIeWO5oc5FIC/xFAa/uQoj61NoS89yqwBXbb+ k890uufcKy0CKeT+jtzkcRjnvz0C7OQSVv1Dn5YwggKQebQGGuQgR2GEQwnRTPbkFg+f Cml/M0COULrAIBYIT0X8DgCCW4Rj6b2xe7z2tKXDvUbLqHEDJPK9ZRSra/0tBuYLvx0e dnFel2KFc+HdGVQSd4tkU8WBunLUFHeZzXk0exbPjsA9SvBBP9TB8u/tn9+FA9qhG1L3 +h6mcmF+ZcxLcj9FysAN4r16HV1JHplKG8FlQUq5ZrsaCndFH0qmvjvWMB5+1Nx0+1R3 Vi7A== X-Gm-Message-State: ANoB5pnh7vRkxfw/z7qPD18LyMkk0SGuIG9Dt2zFhuszOvJzDjgKsjDp 04HwZdHsjBLgJrzrKPSQ9SMq5Q== X-Google-Smtp-Source: AA0mqf4ghrT/87SBIW4BkPBsnLTei7c1aVwVG1GGksav+yaMNE43gjtLSRrT7w5HIU312oIjd2vtlA== X-Received: by 2002:a17:902:7604:b0:189:c380:7c8d with SMTP id k4-20020a170902760400b00189c3807c8dmr3103679pll.136.1670036248021; Fri, 02 Dec 2022 18:57:28 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q100-20020a17090a17ed00b002196b5a0efesm4692751pja.47.2022.12.02.18.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:57:27 -0800 (PST) Date: Fri, 2 Dec 2022 18:57:26 -0800 From: Kees Cook To: Rick Edgecombe Cc: 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 , 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 Subject: Re: [PATCH v4 39/39] x86/shstk: Add ARCH_SHSTK_STATUS Message-ID: <202212021857.938659D@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-40-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-40-rick.p.edgecombe@intel.com> X-Stat-Signature: za4amymqhnebqij64esd4r8xzptnjgnr X-Rspam-User: X-Spamd-Result: default: False [0.10 / 9.00]; BAYES_HAM(-6.00)[100.00%]; SORBS_IRL_BL(3.00)[209.85.216.45:from]; SUSPICIOUS_RECIPS(1.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[38]; ARC_NA(0.00)[]; R_DKIM_ALLOW(0.00)[chromium.org:s=google]; MIME_TRACE(0.00)[0:+]; TAGGED_RCPT(0.00)[]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; DKIM_TRACE(0.00)[chromium.org:+]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17:c]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 049108000F X-Rspamd-Server: rspam06 X-HE-Tag: 1670036248-866329 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: On Fri, Dec 02, 2022 at 04:36:06PM -0800, Rick Edgecombe wrote: > 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 incovienent 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 > Requested-by: Mike Rapoport > Signed-off-by: Rick Edgecombe > --- > > v4: > - New patch > > Documentation/x86/shstk.rst | 6 ++++++ > arch/x86/include/asm/shstk.h | 4 ++-- > arch/x86/include/uapi/asm/prctl.h | 1 + > arch/x86/kernel/process_64.c | 1 + > arch/x86/kernel/shstk.c | 8 +++++++- > 5 files changed, 17 insertions(+), 3 deletions(-) > > diff --git a/Documentation/x86/shstk.rst b/Documentation/x86/shstk.rst > index 0d7d1ccfff06..b3eb87046c27 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 following: > On success, return 0. On error, errno can be:: > > @@ -84,6 +89,7 @@ The return values are as following: > -EOPNOTSUPP if the feature is not supported by the hardware or > disabled by kernel parameter. > -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 c82f22fd5e6d..23bfb63c597d 100644 > --- a/arch/x86/include/asm/shstk.h > +++ b/arch/x86/include/asm/shstk.h > @@ -15,7 +15,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, > @@ -31,7 +31,7 @@ static inline bool shstk_enabled(void) > } > #else > static inline long shstk_prctl(struct task_struct *task, int option, > - unsigned long features) { return -EINVAL; } > + unsigned long arg2) { return -EINVAL; } > static inline void reset_thread_features(void) {} > static inline int shstk_alloc_thread_stack(struct task_struct *p, > unsigned long clone_flags, > diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h > index 0c95688cf58e..abe3fe6db6d2 100644 > --- a/arch/x86/include/uapi/asm/prctl.h > +++ b/arch/x86/include/uapi/asm/prctl.h > @@ -31,6 +31,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 2be6e01fb144..5dcf5426241b 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -922,6 +922,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 95579f7bace3..05f8dcc19dbc 100644 > --- a/arch/x86/kernel/shstk.c > +++ b/arch/x86/kernel/shstk.c > @@ -448,8 +448,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); > + } Doesn't need the braces, but that's fine by me. Reviewed-by: Kees Cook > + > if (option == ARCH_SHSTK_LOCK) { > task->thread.features_locked |= features; > return 0; > -- > 2.17.1 > -- Kees Cook