From nobody Sun Feb 8 08:36:45 2026 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 02A9CC001DF for ; Wed, 2 Aug 2023 22:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbjHBWTq (ORCPT ); Wed, 2 Aug 2023 18:19:46 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 680ed2f15e70d079c8148589a3ce9426fc0ff914 Gitweb: https://git.kernel.org/tip/680ed2f15e70d079c8148589a3ce9426f= c0ff914 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.edgecomb= e%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/shst= k.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. =20 +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:: =20 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 =20 /* 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 opt= ion, 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 =3D -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; } =20 - /* Don't allow via ptrace */ - if (task !=3D current) + /* Only allow via ptrace */ + if (task !=3D current) { + if (option =3D=3D ARCH_SHSTK_UNLOCK && IS_ENABLED(CONFIG_CHECKPOINT_REST= ORE)) { + task->thread.features_locked &=3D ~features; + return 0; + } return -EINVAL; + } =20 /* Do not allow to change locked features */ if (features & task->thread.features_locked)