From patchwork Wed Jul 19 22:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 122900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2770109vqt; Wed, 19 Jul 2023 16:24:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlGPK7etNAbzdXFS4QqCDsD3Y57yE01lMEGNXmHcCTI8W+2q8NKrHZbyQurRLRg2z1rjy3Ix X-Received: by 2002:a17:90a:7442:b0:262:d4c8:cb3c with SMTP id o2-20020a17090a744200b00262d4c8cb3cmr373025pjk.49.1689809057803; Wed, 19 Jul 2023 16:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689809057; cv=none; d=google.com; s=arc-20160816; b=iTqSymw/YrGi4ya/0gcBdkaB2DVA6mO1/lgh3SbDEAhzVqG9/mDxL2g2rPunsSbMTc tmJFwq/WoQuF+X9MAbYmVdiNXi3aimVEqtUDHVjhx1CgTGuKDhNTXQ5o4mKKk+K8GRlz UAyahWC7CNMyy4KHxDKEmfswV+hvDB9a7IETmMHU6Q2BEYxewYqVxWo9QPfLRKpuGt24 efAKNle3CInD8RyAsopCiRYmJ2GtfaX+Jgbf5TpdvpZCEDk0uuqpB1kXfUTnLrn5AsJG NX1+Ki2q0OqXiJTkeWcfz99NEFVFEGwU8gSx3kqwTWaNe+/5ipxFbNssQ5ntrI3bf40j KXcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=UN2SDOgdv7rU1izaYhIRz6cUckHmge7FlYV7cgyLgnA=; fh=9CydxvJ+8+/UKlEjsSbD90Bk/f8edqeJWXIObPRWJRY=; b=eO1Qwr2DGQ7DuSfchbPZxH2fwZ5x2nWIVVfyiPj9dkC4NoQgXAbnffRDNcwnND3MW0 W46VvvyJE/KfAMSu0YRazoRBFZrJaf9Qv16CUw2NzyI+Rj2N0rLxvbBbjskDODzlLtAi p3Qme9kG3cNYIv9eklE8gIGyg3nqKxMbErvwRlQoozjGPJZC8Ek711SyfbOsqyZvOlfx Yi0cuSXeQjvfQoGYk1G3T3Ah3/l1DQ+ieLqykTeIFR2wYg6HGs2/c6CX7wuAmexquiWZ WrUQQ3XFkm7EDz6+x4YQWb2mijfJfLryqCZ1TpjhkuNZCrgDAcY4iEttozPyPknNXeLr b1OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ur+cGPVL; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a17090a660d00b0025eee012ca4si2331979pjj.30.2023.07.19.16.24.05; Wed, 19 Jul 2023 16:24:17 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=ur+cGPVL; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbjGSWra (ORCPT + 99 others); Wed, 19 Jul 2023 18:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjGSWr3 (ORCPT ); Wed, 19 Jul 2023 18:47:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AB311FF3; Wed, 19 Jul 2023 15:47:28 -0700 (PDT) Date: Wed, 19 Jul 2023 22:47:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689806846; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=UN2SDOgdv7rU1izaYhIRz6cUckHmge7FlYV7cgyLgnA=; b=ur+cGPVLgvAVxGxXOV8iIclKAV5I61zQoAU4ZWCSXK/HqszXPf3H2yerFfywd8rNpHWI4h CtmCtHkKEhrWBz/EiO97CeyS2GewXUB3gK+AVI0iiu2DP0ieW1Jhw49d6gHX4tX1tvP9Rk RZnHnitBFApMZOvd5SiNij8WZPID9bpjKWZQLkyAMRsH3ij+dd6LdTHlm6D+Ws++UqsnUl oSr/J2Lut6DpFGn8x6UbLj5WW7r5MPsUXmz1oyO8HyV39e4MeEhAPCaWy1FVH4/UdFlbbk 1oBMMPINn2YPF9829Fld1LHBcs/U0p2TOuwE6FxzcXWabyxrqUOacA6YvkGAqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689806846; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=UN2SDOgdv7rU1izaYhIRz6cUckHmge7FlYV7cgyLgnA=; b=DkT9YISmj6u4QKEXZv5GIYVj5vx/gwzBKryM38O+iLHQY2ZbTKqHymgttIIMQqlowrw4S7 DMvgy3ZOTmTAILDQ== From: "tip-bot2 for Mike Rapoport" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/shstk: Add ARCH_SHSTK_UNLOCK Cc: Mike Rapoport , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , David Hildenbrand , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168980684626.28540.11776066412349595969.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771893222125631052 X-GMAIL-MSGID: 1771893222125631052 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 4dcc93572066233bf47ec5684d7cea5c1fdce311 Gitweb: https://git.kernel.org/tip/4dcc93572066233bf47ec5684d7cea5c1fdce311 Author: Mike Rapoport AuthorDate: Mon, 12 Jun 2023 17:11:07 -07:00 Committer: Rick Edgecombe CommitterDate: Tue, 11 Jul 2023 14:14:15 -07:00 x86/shstk: Add ARCH_SHSTK_UNLOCK 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. [Merged into recent API changes, added commit log and docs] Signed-off-by: Mike Rapoport Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Reviewed-by: David Hildenbrand Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230613001108.3040476-42-rick.p.edgecombe%40intel.com --- Documentation/arch/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(-) diff --git a/Documentation/arch/x86/shstk.rst b/Documentation/arch/x86/shstk.rst index f09afa5..f3553cc 100644 --- a/Documentation/arch/x86/shstk.rst +++ b/Documentation/arch/x86/shstk.rst @@ -75,6 +75,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 eedfde3..3189c4a 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -33,6 +33,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 0f89aa0..e6db21c 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -899,6 +899,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 d723cdc..d43b7a9 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -489,9 +489,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)