x86/shstk: Add ARCH_SHSTK_UNLOCK
authorMike Rapoport <rppt@linux.ibm.com>
Tue, 13 Jun 2023 00:11:07 +0000 (17:11 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Wed, 2 Aug 2023 22:01:51 +0000 (15:01 -0700)
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 <rppt@linux.ibm.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Tested-by: Pengfei Xu <pengfei.xu@intel.com>
Tested-by: John Allen <john.allen@amd.com>
Tested-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/all/20230613001108.3040476-42-rick.p.edgecombe%40intel.com
Documentation/arch/x86/shstk.rst
arch/x86/include/uapi/asm/prctl.h
arch/x86/kernel/process_64.c
arch/x86/kernel/shstk.c

index f09afa504ec0d15f3bee5959f6eeac9002941c2d..f3553cc8c758bad9175d8ef690c021fee736e850 100644 (file)
@@ -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::
 
index eedfde3b63be19725e2ce86552aff61b761f6a6e..3189c4a96468a3c67447fe73269d620f7408421b 100644 (file)
@@ -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)
index 0f89aa0186d1e9c844cb71553c8674673bc21ae3..e6db21c470aa3a0c44f3c6135899ac9e2255671f 100644 (file)
@@ -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;
index d723cdc934749827775f5756cbe39cd2b7737240..d43b7a9c57ced004b9ea92af69ebd589a3a245cb 100644 (file)
@@ -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)