From: Peter Zijlstra <peterz@infradead.org>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org,
hch@infradead.org, sean.j.christopherson@intel.com,
mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org,
kenny@panix.com, jeyu@kernel.org, rasmus.villemoes@prevas.dk,
pbonzini@redhat.com, fenghua.yu@intel.com, xiaoyao.li@intel.com,
nadav.amit@gmail.com, thellstrom@vmware.com, tony.luck@intel.com,
rostedt@goodmis.org, gregkh@linuxfoundation.org,
jannh@google.com, keescook@chromium.org, David.Laight@aculab.com,
dcovelli@vmware.com, mhiramat@kernel.org
Subject: Re: [PATCH 0/4] x86/module: Out-of-tree module decode and sanitize
Date: Tue, 7 Apr 2020 22:45:30 +0200 [thread overview]
Message-ID: <20200407204530.GR2452@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <e6d9f83e-e88c-c079-50b3-ff8ad8682074@citrix.com>
On Tue, Apr 07, 2020 at 09:11:17PM +0100, Andrew Cooper wrote:
> Sorry - should have been more clear. By friends, I meant LGDT, LIDT,
> LLDT and LTR which are the 4 system table loading instructions. LLDT
> and LTR depend on being able to write into the GDT, but still have no
> business being used.
>
> Also, LMSW if you care about it, but its utility is somewhere close to 0
> these days, so probably not worth the cycles searching for.
>
> The Sxxx instructions have no business being used, but are also harmless
> and similarly, probably not worth spending cycles searching for.
>
> L{D,E,F,S}S are functional equivalents to "MOV val1, %sreg; mov val2,
> %reg" so harmless (also mode specific as to whether they are useable).
OK, LxDT + LTR it is.
> Other things to consider, while we're on a roll:
>
> WRMSR and RDMSR: There is a lot of damage which can be done with these,
> and at least forcing people to use the regular hooks will get proper
> paravirt support and/or exception support. That said, this might cause
> large carnage to out-of-tree modules which are a device driver for
> random platform things.
Yeah, I had already considered that, didn't want to touch that just yet.
> POPF: Don't really want someone being able to set IOPL3. However, this
> might quite easily show up as a false positive depending on how the
> irqsafe infrastructure gets inlined.
local_irq_restore() will be a POPF :/
> SYSRET/SYSEXIT/IRET: Don't want a module returning to userspace behind
> the kernels back.
Good thinking, let me add this.
> IRET may be a false positive for serialising
> purposes, as may be a write to CR2 for that matter.
We can out-of-line and export sync_core() for that.
> Looking over the list of other privileged instructions, CLTS,
> {,WB,WBNO}INVD, INVLPG and HLT might be candidates for "clearly doing
> something which shouldn't be done". Not on the list is INVPCID which
> falls into the same category.
>
> Come to think about it, it might be easier to gauge on CPL0 instructions
> and whitelist the ok ones, such as VMX and SVM for out-of-tree hypervisors.
Fair enough, I'll go over those tomorrow.
For now I ended up with:
---
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -282,6 +282,68 @@ static bool insn_is_mov_DRn(struct insn
return false;
}
+static bool insn_is_GDT_modifier(struct insn *insn)
+{
+ u8 modrm = insn->modrm.bytes[0];
+ u8 modrm_mod = X86_MODRM_MOD(modrm);
+ u8 modrm_reg = X86_MODRM_REG(modrm);
+
+ if (insn->opcode.bytes[0] != 0x0f)
+ return false;
+
+ switch (insn->opcode.bytes[1]) {
+ case 0x00: /* Grp6 */
+ switch (modrm_reg) {
+ /* case 0x0: SLDT */
+ case 0x2: /* LLDT */
+ case 0x3: /* LTR */
+ return true;
+
+ default:
+ break;
+ }
+ break;
+
+ case 0x01: /* Grp7 */
+ if (modrm_mod == 0x03)
+ break;
+
+ switch (modrm_reg) {
+ /* case 0x0: SGDT */
+ /* case 0x1: SIDT */
+ case 0x2: /* LGDT */
+ case 0x3: /* LIDT */
+ return true;
+
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return false;
+}
+
+static bool insn_is_xRET(struct insn *insn)
+{
+ u8 op1 = insn->opcode.bytes[0];
+ u8 op2 = insn->opcode.bytes[1];
+
+ if (op1 == 0xcf) /* IRET */
+ return true;
+
+ if (op1 != 0x0f)
+ return false;
+
+ if (op2 == 0x07 || op2 == 0x35) /* SYSRET, SYSEXIT */
+ return true;
+
+ return false;
+}
+
static int decode_module(struct module *mod, void *text, void *text_end, bool sld_safe)
{
bool allow_vmx = sld_safe || !split_lock_enabled();
next prev parent reply other threads:[~2020-04-07 20:46 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 11:02 [PATCH 0/4] x86/module: Out-of-tree module decode and sanitize Peter Zijlstra
2020-04-07 11:02 ` [PATCH 1/4] module: Expose load_info to arch module loader code Peter Zijlstra
2020-04-07 16:52 ` Kees Cook
2020-04-07 11:02 ` [PATCH 2/4] module: Convert module_finalize() to load_info Peter Zijlstra
2020-04-07 16:53 ` Kees Cook
2020-04-07 11:02 ` [PATCH 3/4] x86,module: Detect VMX vs SLD conflicts Peter Zijlstra
2020-04-07 14:35 ` Greg KH
2020-04-07 14:44 ` Paolo Bonzini
2020-04-07 14:55 ` Greg KH
2020-04-07 14:49 ` Steven Rostedt
2020-04-07 15:24 ` Peter Zijlstra
2020-04-07 15:28 ` Paolo Bonzini
2020-04-07 15:44 ` Greg KH
2020-04-07 16:51 ` Masami Hiramatsu
2020-04-07 17:16 ` Andrew Cooper
2020-04-07 23:59 ` Masami Hiramatsu
2020-04-08 7:25 ` Masami Hiramatsu
2020-04-07 18:26 ` kbuild test robot
2020-04-07 18:26 ` kbuild test robot
2020-04-07 21:25 ` David Laight
2020-04-07 23:15 ` Kees Cook
2020-04-08 2:10 ` Xiaoyao Li
2020-04-08 8:09 ` Masami Hiramatsu
2020-04-08 9:56 ` Peter Zijlstra
2020-04-08 10:15 ` Andrew Cooper
2020-04-10 11:25 ` Masami Hiramatsu
2020-04-07 11:02 ` [PATCH 4/4] x86,module: Detect CRn and DRn manipulation Peter Zijlstra
2020-04-07 17:01 ` Kees Cook
2020-04-07 18:13 ` Peter Zijlstra
2020-04-07 18:49 ` Kees Cook
2020-04-07 18:55 ` Nadav Amit
2020-04-07 19:38 ` Peter Zijlstra
2020-04-07 20:27 ` Nadav Amit
2020-04-07 20:50 ` Peter Zijlstra
2020-04-07 21:22 ` Nadav Amit
2020-04-07 21:27 ` Peter Zijlstra
2020-04-07 22:12 ` Paolo Bonzini
2020-04-07 23:51 ` Nadav Amit
2020-04-08 8:45 ` Peter Zijlstra
2020-04-08 5:18 ` Christoph Hellwig
2020-04-07 23:15 ` Andrew Cooper
2020-04-08 0:22 ` Paolo Bonzini
2020-04-08 8:37 ` Peter Zijlstra
2020-04-08 9:52 ` Andrew Cooper
2020-04-07 21:48 ` Steven Rostedt
2020-04-08 5:58 ` Jan Kiszka
2020-04-08 8:03 ` Paolo Bonzini
2020-04-08 8:58 ` Jan Kiszka
2020-04-08 9:04 ` Paolo Bonzini
2020-04-08 10:45 ` Jan Kiszka
2020-04-08 8:51 ` Peter Zijlstra
2020-04-08 8:59 ` Jan Kiszka
2020-04-08 9:25 ` David Laight
2020-04-08 11:13 ` Jan Kiszka
2020-04-08 11:17 ` David Laight
2020-04-08 9:13 ` Peter Zijlstra
2020-04-08 10:50 ` Jan Kiszka
2020-04-08 13:27 ` Steven Rostedt
2020-04-08 15:44 ` Peter Zijlstra
2020-04-08 15:46 ` Christoph Hellwig
2020-04-08 16:02 ` Sean Christopherson
2020-04-08 16:15 ` Paolo Bonzini
2020-04-09 8:56 ` Peter Zijlstra
2020-04-09 10:13 ` Nadav Amit
2020-04-09 21:13 ` Thomas Gleixner
2020-04-09 22:18 ` Steven Rostedt
2020-04-10 5:37 ` Nadav Amit
2020-04-08 15:54 ` Jessica Yu
2020-04-07 17:23 ` [PATCH 0/4] x86/module: Out-of-tree module decode and sanitize Andrew Cooper
2020-04-07 19:41 ` Peter Zijlstra
2020-04-07 20:11 ` Andrew Cooper
2020-04-07 20:45 ` Peter Zijlstra [this message]
2020-04-07 21:21 ` Andrew Cooper
2020-04-07 20:21 ` Andrew Cooper
2020-04-07 20:48 ` Peter Zijlstra
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=20200407204530.GR2452@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=David.Laight@aculab.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dcovelli@vmware.com \
--cc=fenghua.yu@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=jannh@google.com \
--cc=jeyu@kernel.org \
--cc=keescook@chromium.org \
--cc=kenny@panix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=pbonzini@redhat.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=rostedt@goodmis.org \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=thellstrom@vmware.com \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
--cc=xiaoyao.li@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.