From patchwork Wed Aug 2 22:19:25 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: 130229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp808348vqx; Wed, 2 Aug 2023 17:10:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9PiLWI5B92+cxUczLQ97U1ht8LH9RsKDv96MA5l0s3H6qcLe3MhnfSKW5qFusw5uahSdt X-Received: by 2002:a05:6a20:7fa5:b0:137:3eba:b81f with SMTP id d37-20020a056a207fa500b001373ebab81fmr21472848pzj.3.1691021404498; Wed, 02 Aug 2023 17:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691021404; cv=none; d=google.com; s=arc-20160816; b=vFDGUq4SYQfMr0Hv3D96No0y0CLOraILz4UiSxWk3HaUfGLHG+Jhq7jq12rNuoSnf+ oXlSzpQqsy/Lkh8D9rXwVuZ4/sTMWIUNNUi0yNktxpPP1bZQ/Y22U/jN8Nuyv8x1vq34 FwoqbekoGXMcUKO79dJ1qvUYVdgxBEQNqQbbs5l00Dh4eol9WqTPyve7hu54ct1C+6Cd PkYJGdcVX+PJq+NpaYD2hOCQvyZeVsEz7AsJFgX5iTy7PXH4TPFFNY8/8WqF6OfKVs0J tnDwx6DkhYCP77SbZbSNJ7vxF8jvJmCujUVLeGSnxwzuYuuDHZ3jYD8mWMc/XveovbjH SjSg== 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=4E/G06uHPkpK//F/IJZHWnjR5EPqdEo6JHivIa3wrzY=; fh=9CydxvJ+8+/UKlEjsSbD90Bk/f8edqeJWXIObPRWJRY=; b=kd8Knx31kqIktRSMa/SLBDmGeYn7PL38aqaLC9rqgSKvMGu8LX6rG4wuYKUAdkDXqL lw09NJh+eg0Zu2Joe8f2PuAedGZggklpk3WeuedkB//Lp6eSXCYyTvqkL/+GuO7JUn6y sVyldcWUIPRzyEHPM2C8evDHGcC3lVTzWz1JSSLWdQ5ke62N3fGHfZuq/AaTZE+Rj5AV ew3VXyVA+/ioctNBrH1EEw0h9cZNFwjEwSaY9uHPSk52gF1rsnx/ZhcVPFTeUlLaU+vU +Esd5dxMsgD4MTXYYqVrTEGOUbUcV1DtHPpwGOw1yBVr3jLwrKj8WoGgZyGOM4c8HCGM VVjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NxsmXEW7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 x12-20020a170902ec8c00b001b9c120a39csi12026505plg.357.2023.08.02.17.09.30; Wed, 02 Aug 2023 17:10:04 -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=NxsmXEW7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233746AbjHBWTp (ORCPT + 99 others); Wed, 2 Aug 2023 18:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231414AbjHBWTa (ORCPT ); Wed, 2 Aug 2023 18:19:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46445272B; Wed, 2 Aug 2023 15:19:28 -0700 (PDT) Date: Wed, 02 Aug 2023 22:19:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691014766; 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=4E/G06uHPkpK//F/IJZHWnjR5EPqdEo6JHivIa3wrzY=; b=NxsmXEW7Xs+ILRRSrV0YPt9SBv97bqRmDAEpA0jm82F0usU28D60dow65BTHRyXozdf4p4 lyDLe2TLWsRgE8nfGAKB/DsJnHy4Iv1xB3Hb/iYONYsH6kG7wOpM+DDXpDcteGDf2VZDV5 PsX1tGENg4S7P8DtkIucTfO4WzpRCk1NtbO9YBzhZz6hsRQFW1Ae3rFTfC7NsrkBkFkMjd /+UBZ71M2FEvz3EJCH0xY7s7OwwlOZrXMDFr1E66PbD0GYrC0Bzi1IphjaQb1fLKmJuPPE 28tgiViehevHoREeJqTbB8e5EZZTJOZhjILWtNMf9sLfRTmsMbaRmIQjN4s2zA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691014766; 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=4E/G06uHPkpK//F/IJZHWnjR5EPqdEo6JHivIa3wrzY=; b=zGHt9Uk8zipN+ei78C+iHO9UeNXqNQWlPPegLNrFjO5dyJa++f6FzKHlwPjcxBiDsMWWKx u2kjkuSUcLzNDhBg== 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: <169101476562.28540.7349079429427785804.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: 1773164460032927735 X-GMAIL-MSGID: 1773164460032927735 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 680ed2f15e70d079c8148589a3ce9426fc0ff914 Gitweb: https://git.kernel.org/tip/680ed2f15e70d079c8148589a3ce9426fc0ff914 Author: Mike Rapoport AuthorDate: Mon, 12 Jun 2023 17:11:07 -07:00 Committer: Dave Hansen CommitterDate: Wed, 02 Aug 2023 15:01:51 -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)