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, szabolcs.nagy@arm.com
Cc: rick.p.edgecombe@intel.com, Mike Rapoport <rppt@linux.ibm.com>
Subject: [PATCH v8 39/40] x86/shstk: Add ARCH_SHSTK_UNLOCK
Date: Sat, 18 Mar 2023 17:15:34 -0700 [thread overview]
Message-ID: <20230319001535.23210-40-rick.p.edgecombe@intel.com> (raw)
In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com>
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.
[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>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Pengfei Xu <pengfei.xu@intel.com>
Tested-by: John Allen <john.allen@amd.com>
Tested-by: Kees Cook <keescook@chromium.org>
---
v8:
- Remove Mike's ack from his own patch (Boris)
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(-)
diff --git a/Documentation/x86/shstk.rst b/Documentation/x86/shstk.rst
index f09afa504ec0..f3553cc8c758 100644
--- a/Documentation/x86/shstk.rst
+++ b/Documentation/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 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 9bbad1763e33..69d4ccaef56f 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 ee89c4206ac9..ad336ab55ace 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -459,9 +459,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)
--
2.17.1
next prev parent reply other threads:[~2023-03-19 0:17 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-19 0:14 [PATCH v8 00/40] Shadow stacks for userspace Rick Edgecombe
2023-03-19 0:14 ` [PATCH v8 01/40] Documentation/x86: Add CET shadow stack description Rick Edgecombe
2023-03-19 0:14 ` [PATCH v8 02/40] x86/shstk: Add Kconfig option for shadow stack Rick Edgecombe
2023-03-19 0:14 ` [PATCH v8 03/40] x86/cpufeatures: Add CPU feature flags for shadow stacks Rick Edgecombe
2023-03-19 0:14 ` [PATCH v8 04/40] x86/cpufeatures: Enable CET CR4 bit for shadow stack Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 05/40] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 06/40] x86/fpu: Add helper for modifying xstate Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 07/40] x86/traps: Move control protection handler to separate file Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 08/40] x86/shstk: Add user control-protection fault handler Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 09/40] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 10/40] x86/mm: Move pmd_write(), pud_write() up in the file Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 11/40] mm: Introduce pte_mkwrite_kernel() Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 12/40] s390/mm: Introduce pmd_mkwrite_kernel() Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 13/40] mm: Make pte_mkwrite() take a VMA Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 14/40] x86/mm: Introduce _PAGE_SAVED_DIRTY Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 15/40] x86/mm: Update ptep/pmdp_set_wrprotect() for _PAGE_SAVED_DIRTY Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 16/40] x86/mm: Start actually marking _PAGE_SAVED_DIRTY Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 17/40] mm: Move VM_UFFD_MINOR_BIT from 37 to 38 Rick Edgecombe
2023-03-20 10:55 ` David Hildenbrand
2023-03-19 0:15 ` [PATCH v8 18/40] mm: Introduce VM_SHADOW_STACK for shadow stack memory Rick Edgecombe
2023-03-20 10:55 ` David Hildenbrand
2023-03-19 0:15 ` [PATCH v8 19/40] x86/mm: Check shadow stack page fault errors Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 20/40] x86/mm: Teach pte_mkwrite() about stack memory Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 21/40] mm: Add guard pages around a shadow stack Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 22/40] mm/mmap: Add shadow stack pages to memory accounting Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 23/40] mm: Re-introduce vm_flags to do_mmap() Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 24/40] mm: Don't allow write GUPs to shadow stack memory Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 25/40] x86/mm: Introduce MAP_ABOVE4G Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 26/40] mm: Warn on shadow stack memory in wrong vma Rick Edgecombe
2023-03-20 11:00 ` David Hildenbrand
2023-03-19 0:15 ` [PATCH v8 27/40] x86/mm: Warn if create Write=0,Dirty=1 with raw prot Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 28/40] x86: Introduce userspace API for shadow stack Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 29/40] x86/shstk: Add user-mode shadow stack support Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 30/40] x86/shstk: Handle thread shadow stack Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 31/40] x86/shstk: Introduce routines modifying shstk Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 32/40] x86/shstk: Handle signals for shadow stack Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 33/40] x86/shstk: Introduce map_shadow_stack syscall Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 34/40] x86/shstk: Support WRSS for userspace Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 35/40] x86: Expose thread features in /proc/$PID/status Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 36/40] x86/shstk: Wire in shadow stack interface Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 37/40] selftests/x86: Add shadow stack test Rick Edgecombe
2023-03-19 0:15 ` [PATCH v8 38/40] x86: Add PTRACE interface for shadow stack Rick Edgecombe
2023-03-19 0:15 ` Rick Edgecombe [this message]
2023-03-19 0:15 ` [PATCH v8 40/40] x86/shstk: Add ARCH_SHSTK_STATUS Rick Edgecombe
2023-03-19 14:00 ` [PATCH v8 00/40] Shadow stacks for userspace Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230319001535.23210-40-rick.p.edgecombe@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=bsingharora@gmail.com \
--cc=christina.schimpe@intel.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=debug@rivosinc.com \
--cc=dethoma@microsoft.com \
--cc=eranian@google.com \
--cc=esyr@redhat.com \
--cc=fweimer@redhat.com \
--cc=gorcunov@gmail.com \
--cc=hjl.tools@gmail.com \
--cc=hpa@zytor.com \
--cc=jamorris@linux.microsoft.com \
--cc=jannh@google.com \
--cc=john.allen@amd.com \
--cc=kcc@google.com \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mike.kravetz@oracle.com \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=oleg@redhat.com \
--cc=pavel@ucw.cz \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=rppt@linux.ibm.com \
--cc=szabolcs.nagy@arm.com \
--cc=tglx@linutronix.de \
--cc=weijiang.yang@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).