From: Willy Tarreau <w@1wt.eu>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Willy Tarreau <w@1wt.eu>, Andy Lutomirski <luto@kernel.org>,
Borislav Petkov <bp@alien8.de>, Brian Gerst <brgerst@gmail.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Josh Poimboeuf <jpoimboe@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Kees Cook <keescook@chromium.org>
Subject: [RFC PATCH v3 4/8] x86/arch_prctl: add ARCH_DISABLE_PTI_{NOW,NEXT} to enable/disable PTI
Date: Wed, 10 Jan 2018 20:28:16 +0100 [thread overview]
Message-ID: <1515612500-14505-5-git-send-email-w@1wt.eu> (raw)
In-Reply-To: <1515612500-14505-1-git-send-email-w@1wt.eu>
These two prctls adjust the current task flags allowing to disable page
table isolation respectively for the current process or for the one
resulting from the next execve().
Both settings depend on CONFIG_PER_PROCESS_PTI. It is not possible to
set the flags if the pti_adjust sysctl is lower than 1, nor if the task
isn't capable of CAP_SYS_RAWIO, though it is still possible to disable
them.
Setting the flags is not allowed anymore once the task has created new
threads, but it's still possible to disable them.
Signed-off-by: Willy Tarreau <w@1wt.eu>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
v3:
- depend on CONFIG_PER_PROCESS_PTI
- switch back to task flags
- use one task flag for the immediate task (config-based setting) and
one task flag for the task resulting from the next execve (wrapper-based
setting)
- check the pti_adjust sysctl
v2:
- use {set,clear}_thread_flag() as recommended by Peter
- use task->mm->context.pti_disable instead of task flag
- check for mm_users == 1
- check for CAP_SYS_RAWIO only when setting, not clearing
- make the code depend on CONFIG_PAGE_TABLE_ISOLATION
---
arch/x86/include/uapi/asm/prctl.h | 3 +++
arch/x86/kernel/process_64.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h
index 5a6aac9..1564f98 100644
--- a/arch/x86/include/uapi/asm/prctl.h
+++ b/arch/x86/include/uapi/asm/prctl.h
@@ -10,6 +10,9 @@
#define ARCH_GET_CPUID 0x1011
#define ARCH_SET_CPUID 0x1012
+#define ARCH_DISABLE_PTI_NOW 0x1021
+#define ARCH_DISABLE_PTI_NEXT 0x1022
+
#define ARCH_MAP_VDSO_X32 0x2001
#define ARCH_MAP_VDSO_32 0x2002
#define ARCH_MAP_VDSO_64 0x2003
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index c754662..b4de8aa 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -654,7 +654,37 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
ret = put_user(base, (unsigned long __user *)arg2);
break;
}
+#ifdef CONFIG_PER_PROCESS_PTI
+ case ARCH_DISABLE_PTI_NOW:
+ if (!task->mm || atomic_read(&task->mm->mm_users) > 1)
+ return -EPERM;
+
+ if (arg2 && (!capable(CAP_SYS_RAWIO) || pti_adjust < 1))
+ return -EPERM;
+
+ if (doit) {
+ if (arg2)
+ set_thread_flag(TIF_DISABLE_PTI_NOW);
+ else
+ clear_thread_flag(TIF_DISABLE_PTI_NOW);
+ }
+ break;
+ case ARCH_DISABLE_PTI_NEXT:
+ if (!task->mm || atomic_read(&task->mm->mm_users) > 1)
+ return -EPERM;
+
+ if (arg2 && (!capable(CAP_SYS_RAWIO) || pti_adjust < 1))
+ return -EPERM;
+
+ if (doit) {
+ if (arg2)
+ set_thread_flag(TIF_DISABLE_PTI_NEXT);
+ else
+ clear_thread_flag(TIF_DISABLE_PTI_NEXT);
+ }
+ break;
+#endif
#ifdef CONFIG_CHECKPOINT_RESTORE
# ifdef CONFIG_X86_X32_ABI
case ARCH_MAP_VDSO_X32:
--
1.7.12.1
next prev parent reply other threads:[~2018-01-10 19:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-10 19:28 [RFC PATCH v3 0/8] Per process PTI activation Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 1/8] x86/thread_info: add TIF_DISABLE_PTI_{NOW,NEXT} to disable PTI per task Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 2/8] x86/pti: add new config option PER_PROCESS_PTI Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 3/8] x86/pti: create the pti_adjust sysctl Willy Tarreau
2018-01-10 19:28 ` Willy Tarreau [this message]
2018-01-10 19:28 ` [RFC PATCH v3 5/8] exec: take care of disabling PTI upon execve() Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 6/8] x86/pti: don't mark the user PGD with _PAGE_NX Willy Tarreau
2018-01-10 19:54 ` Linus Torvalds
2018-01-10 19:59 ` Andy Lutomirski
2018-01-10 20:28 ` Woodhouse, David
2018-01-11 6:23 ` Willy Tarreau
2018-02-23 17:58 ` Konrad Rzeszutek Wilk
2018-02-23 19:30 ` Dave Hansen
2018-01-10 20:20 ` Dave Hansen
2018-01-11 6:27 ` Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 7/8] x86/entry/pti: avoid setting CR3 when it's already correct Willy Tarreau
2018-01-10 19:28 ` [RFC PATCH v3 8/8] x86/entry/pti: don't switch PGD when TIF_DISABLE_PTI_NOW is set Willy Tarreau
2018-01-10 19:35 ` [RFC PATCH v3 0/8] Per process PTI activation Linus Torvalds
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=1515612500-14505-5-git-send-email-w@1wt.eu \
--to=w@1wt.eu \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®