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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C869C64EC4 for ; Wed, 8 Mar 2023 10:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbjCHK23 (ORCPT ); Wed, 8 Mar 2023 05:28:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbjCHK2R (ORCPT ); Wed, 8 Mar 2023 05:28:17 -0500 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1869ECC; Wed, 8 Mar 2023 02:28:11 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A29E81EC0104; Wed, 8 Mar 2023 11:28:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1678271289; h=from:from: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; bh=QUSal8yLRZqvOQ34incj8gT6TWJsFqJ8/OvBTCTsShk=; b=qKM1WjO9F9dXO6k5BZ17YhP7pKauIgrnWTcEAhizPLCqjIUDtUBoqz9Vv7RlAmfM7ENNcX Np7CELn8CU+Qrg3p56Rww0dIFPR7Hx8s81XMMztPWSMC3ak4lXSGrlcQPEiXxVGph6KZkV fp3eA1tDCcaGYqrcE+cPk4ynDNL4gOU= Date: Wed, 8 Mar 2023 11:27:56 +0100 From: Borislav Petkov 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 , 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 Subject: Re: [PATCH v7 28/41] x86: Introduce userspace API for shadow stack Message-ID: References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> <20230227222957.24501-29-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230227222957.24501-29-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 27, 2023 at 02:29:44PM -0800, Rick Edgecombe wrote: > From: "Kirill A. Shutemov" > > Add three new arch_prctl() handles: > > - ARCH_SHSTK_ENABLE/DISABLE enables or disables the specified > feature. Returns 0 on success or an error. "... or a negative value on error." > - ARCH_SHSTK_LOCK prevents future disabling or enabling of the > specified feature. Returns 0 on success or an error ditto. What is the use case of the feature locking? I'm under the simple assumption that once shstk is enabled for an app, it remains so. I guess my question is rather, what's the use case for enabling shadow stack and then disabling it later for an app...? > The features are handled per-thread and inherited over fork(2)/clone(2), > but reset on exec(). > > This is preparation patch. It does not implement any features. That belongs under the "---" line I guess. > Tested-by: Pengfei Xu > Tested-by: John Allen > Tested-by: Kees Cook > Acked-by: Mike Rapoport (IBM) > Reviewed-by: Kees Cook > Signed-off-by: Kirill A. Shutemov > [tweaked with feedback from tglx] > Co-developed-by: Rick Edgecombe > Signed-off-by: Rick Edgecombe > > --- > v4: > - Remove references to CET and replace with shadow stack (Peterz) > > v3: > - Move shstk.c Makefile changes earlier (Kees) > - Add #ifdef around features_locked and features (Kees) > - Encapsulate features reset earlier in reset_thread_features() so > features and features_locked are not referenced in code that would be > compiled !CONFIG_X86_USER_SHADOW_STACK. (Kees) > - Fix typo in commit log (Kees) > - Switch arch_prctl() numbers to avoid conflict with LAM > > v2: > - Only allow one enable/disable per call (tglx) > - Return error code like a normal arch_prctl() (Alexander Potapenko) > - Make CET only (tglx) > --- > arch/x86/include/asm/processor.h | 6 +++++ > arch/x86/include/asm/shstk.h | 21 +++++++++++++++ > arch/x86/include/uapi/asm/prctl.h | 6 +++++ > arch/x86/kernel/Makefile | 2 ++ > arch/x86/kernel/process_64.c | 7 ++++- > arch/x86/kernel/shstk.c | 44 +++++++++++++++++++++++++++++++ > 6 files changed, 85 insertions(+), 1 deletion(-) > create mode 100644 arch/x86/include/asm/shstk.h > create mode 100644 arch/x86/kernel/shstk.c ... > +long shstk_prctl(struct task_struct *task, int option, unsigned long features) > +{ > + if (option == ARCH_SHSTK_LOCK) { > + task->thread.features_locked |= features; > + return 0; > + } > + > + /* Don't allow via ptrace */ > + if (task != current) > + return -EINVAL; > + > + /* Do not allow to change locked features */ > + if (features & task->thread.features_locked) > + return -EPERM; > + > + /* Only support enabling/disabling one feature at a time. */ > + if (hweight_long(features) > 1) > + return -EINVAL; > + > + if (option == ARCH_SHSTK_DISABLE) { > + return -EINVAL; > + } {} braces left over from some previous version. Can go now. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette