Message ID | 20230227222957.24501-41-rick.p.edgecombe@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2684022wrd; Mon, 27 Feb 2023 14:38:15 -0800 (PST) X-Google-Smtp-Source: AK7set/nCgoRr8N1E8ttI/6mWbX1Ofcm1/GgOoZE+QLXeeA2PAAEewI3fXNtjUorcWIEa00LEMC6 X-Received: by 2002:a17:902:a606:b0:19c:fa22:e984 with SMTP id u6-20020a170902a60600b0019cfa22e984mr428605plq.48.1677537494896; Mon, 27 Feb 2023 14:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677537494; cv=none; d=google.com; s=arc-20160816; b=r0HXhiOD5GmX68p5A3Er8hbFTx1cbaaPD/vlo/XEaD0Qpij4mBwdtxlSaDmlqkC2IN yYY3nTmJ0A8XFZ4N8ar24P+lOz9bI9BrVRgD8sAe6RZyLN9YHEvj3fUVbwPWbDBA9foo 7dHkCdkJZMX6U92xKZCDRKiEjKTLnrjLlY6riT8QIstP3jQpofMcoVt5M0ERjYojwe0K TPqzRV1sotlVIdO2iXbkxeJgmG83ypJ0j2qf+UXWxXe/M8n60e8BSZQeWTMsZvSLwPaS xXGvH8LKYf6+Xeazp/VHXL1EcLp0eAa8T5wdRonomOx/IsgcQU/qtpoQ0ZnWL5tMgw54 /Mbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=njwT8/nseUUwtQUAH3WeQoFGEFftjwWBmHlQjdHCBPs=; b=jeleRn+o94GlEuLkaINc6ThnT3UnEdJmKZM42xkSBl4Y+XNGNLw9a8Ny0wgj7SRki5 /lxqmoCk08jUNldzdFH58Jp6eRTvY4KIe18A0LQFh69Tr0ssQ0hwDTSig+GTJ+pHyann K2ojtpuLDRcLVaXIsVNH320+nClpyESOKPa5N3gVdshyv5XwuClxHIt/0ihcTQsUncHj ErPO5TNe2rJ4McNekre+rq5cWhtcz4J2wJ2kfONCqGgWqqT2qGS3WfxhV/YskW0pGHSI w4ROvNc073BZb9Zo0C27UDqGiWK+D31ClyldftdfeBUgosKHPEfRV4+aVug6rbX2H6NO X9CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BQf3g2ka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a17090276c600b00194dd9cb062si7488067plt.396.2023.02.27.14.38.02; Mon, 27 Feb 2023 14:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BQf3g2ka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjB0Who (ORCPT <rfc822;wenzhi022@gmail.com> + 99 others); Mon, 27 Feb 2023 17:37:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjB0WhM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 27 Feb 2023 17:37:12 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 552B4EC46; Mon, 27 Feb 2023 14:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537187; x=1709073187; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ND8Cme6dUKUNgrJvq4rzFWKNWp2gSll9XobN53PYr6I=; b=BQf3g2ka1JPjRpogNPS+jUnNnytoIA3ZoZa/cIqizgDH2ZlXEgn76V63 /tMrSo1iPe2lAyi/gg+pAryAD3MM2fD01nHPr+U+qhRt8QqIMGP8wUzO4 thdWwmHXojHIPw53RhjGmt5tcYYHUNEDnOwJbB94fopJo4PJXGltPVCCi pwolrDZtk0qGOwzNks5ygKklHZUnaU/JnSrybGrxw+HlE1ZH/pUtDKVJs ZnR6c3/34RFlZv2nmicJQ81JLR37E9nKzGyRiSTetBQZ2w8DeBMivLzFp KmvkO/rDspxsVcRTgytgEwV8YkX3/gBDfOvUhGuP607WeR8FcqRH6pRM/ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657975" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657975" 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:37 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024819" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024819" 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:36 -0800 From: Rick Edgecombe <rick.p.edgecombe@intel.com> To: x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, 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 <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>, Balbir Singh <bsingharora@gmail.com>, Borislav Petkov <bp@alien8.de>, Cyrill Gorcunov <gorcunov@gmail.com>, Dave Hansen <dave.hansen@linux.intel.com>, Eugene Syromiatnikov <esyr@redhat.com>, Florian Weimer <fweimer@redhat.com>, "H . J . Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Mike Kravetz <mike.kravetz@oracle.com>, Nadav Amit <nadav.amit@gmail.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Machek <pavel@ucw.cz>, Peter Zijlstra <peterz@infradead.org>, Randy Dunlap <rdunlap@infradead.org>, Weijiang Yang <weijiang.yang@intel.com>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, John Allen <john.allen@amd.com>, 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, Mike Rapoport <rppt@linux.ibm.com> Subject: [PATCH v7 40/41] x86/shstk: Add ARCH_SHSTK_UNLOCK Date: Mon, 27 Feb 2023 14:29:56 -0800 Message-Id: <20230227222957.24501-41-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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759025555987349066?= X-GMAIL-MSGID: =?utf-8?q?1759025555987349066?= |
Series |
Shadow stacks for userspace
|
|
Commit Message
Edgecombe, Rick P
Feb. 27, 2023, 10:29 p.m. UTC
From: Mike Rapoport <rppt@linux.ibm.com> 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 shadow stack operations, but restrict it being called by the ptrace arch_pctl() interface. Tested-by: Pengfei Xu <pengfei.xu@intel.com> Tested-by: John Allen <john.allen@amd.com> Tested-by: Kees Cook <keescook@chromium.org> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> [Merged into recent API changes, added commit log and docs] Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> --- v4: - Add to docs that it is ptrace only. - Remove "CET" references v3: - Depend on CONFIG_CHECKPOINT_RESTORE (Kees) --- Documentation/x86/shstk.rst | 4 ++++ arch/x86/include/uapi/asm/prctl.h | 1 + arch/x86/kernel/process_64.c | 1 + arch/x86/kernel/shstk.c | 9 +++++++-- 4 files changed, 13 insertions(+), 2 deletions(-)
Comments
On Mon, Feb 27, 2023 at 02:29:56PM -0800, Rick Edgecombe wrote: > From: Mike Rapoport <rppt@linux.ibm.com> > > 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 shadow stack operations, but restrict it being > called by the ptrace arch_pctl() interface. > > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > Tested-by: John Allen <john.allen@amd.com> > Tested-by: Kees Cook <keescook@chromium.org> > Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> That tag is kinda implicit here. Unless he doesn't ACK his own patch. :-P > Reviewed-by: Kees Cook <keescook@chromium.org> > Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> > [Merged into recent API changes, added commit log and docs] > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> ... > diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c > index 2faf9b45ac72..3197ff824809 100644 > --- a/arch/x86/kernel/shstk.c > +++ b/arch/x86/kernel/shstk.c > @@ -451,9 +451,14 @@ long shstk_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) { Is that the only case? task != current means ptrace and there's no other way to do this from userspace? Isn't there some flag which says that task is ptraced? I think we should check that one too...
On Sat, 2023-03-11 at 16:11 +0100, Borislav Petkov wrote: > On Mon, Feb 27, 2023 at 02:29:56PM -0800, Rick Edgecombe wrote: > > From: Mike Rapoport <rppt@linux.ibm.com> > > > > 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 shadow stack operations, but restrict > > it being > > called by the ptrace arch_pctl() interface. > > > > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > > Tested-by: John Allen <john.allen@amd.com> > > Tested-by: Kees Cook <keescook@chromium.org> > > Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> > > That tag is kinda implicit here. Unless he doesn't ACK his own patch. > :-P Uhh, right. This was me mindlessly adding his ack to all the patches in the series. > > > Reviewed-by: Kees Cook <keescook@chromium.org> > > Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> > > [Merged into recent API changes, added commit log and docs] > > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> > > ... > > > diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c > > index 2faf9b45ac72..3197ff824809 100644 > > --- a/arch/x86/kernel/shstk.c > > +++ b/arch/x86/kernel/shstk.c > > @@ -451,9 +451,14 @@ long shstk_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) { > > Is that the only case? task != current means ptrace and there's no > other > way to do this from userspace? Not that I could see... > > Isn't there some flag which says that task is ptraced? I think we > should > check that one too... This is how the other arch_prctl()s handle it (if they do handle it, some don't). So I would think it would be nice to keep all the logic the same. I guess the flag might work based on the assumption that if the task is being ptraced, the arch_prctl() couldn't be coming from anywhere else. Maybe it should get a nicely named helper that they could all use and whatever best logic could be commented. Would this maybe be better as a future cleanup that did the change for them all?
On Mon, Mar 13, 2023 at 03:04:10AM +0000, Edgecombe, Rick P wrote: > This is how the other arch_prctl()s handle it (if they do handle it, > some don't). So I would think it would be nice to keep all the logic > the same. > > I guess the flag might work based on the assumption that if the task is > being ptraced, the arch_prctl() couldn't be coming from anywhere else. > Maybe it should get a nicely named helper that they could all use and > whatever best logic could be commented. > > Would this maybe be better as a future cleanup that did the change for > them all? Yeah, I'm just being overly paranoid. Because if there's another way to unlock that feature, then this whole "overhead" we're doing is for nothing.
diff --git a/Documentation/x86/shstk.rst b/Documentation/x86/shstk.rst index f2e6f323cf68..e8ed5fc0f7ae 100644 --- a/Documentation/x86/shstk.rst +++ b/Documentation/x86/shstk.rst @@ -73,6 +73,10 @@ arch_prctl(ARCH_SHSTK_LOCK, unsigned long features) are ignored. The mask is ORed with the existing value. So any feature bits set here cannot be enabled or disabled afterwards. +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. + The return values are as follows. 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 e31495668056..200efbbe5809 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -25,6 +25,7 @@ #define ARCH_SHSTK_ENABLE 0x5001 #define ARCH_SHSTK_DISABLE 0x5002 #define ARCH_SHSTK_LOCK 0x5003 +#define ARCH_SHSTK_UNLOCK 0x5004 /* 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 71094c8a305f..d368854fa9c4 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -835,6 +835,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_SHSTK_ENABLE: case ARCH_SHSTK_DISABLE: case ARCH_SHSTK_LOCK: + case ARCH_SHSTK_UNLOCK: return shstk_prctl(task, option, arg2); default: ret = -EINVAL; diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index 2faf9b45ac72..3197ff824809 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -451,9 +451,14 @@ long shstk_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_SHSTK_UNLOCK && IS_ENABLED(CONFIG_CHECKPOINT_RESTORE)) { + task->thread.features_locked &= ~features; + return 0; + } return -EINVAL; + } /* Do not allow to change locked features */ if (features & task->thread.features_locked)