Return-path: Received: from mga17.intel.com ([192.55.52.151]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fJPwA-0001m0-Sx for speck@linutronix.de; Thu, 17 May 2018 22:55:47 +0200 From: Dave Hansen Subject: [MODERATED] Generic eBPF hardening Message-ID: Date: Thu, 17 May 2018 13:55:38 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tTVaCrduF5K56L5CkMhADFwdQZocBSyBr"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --tTVaCrduF5K56L5CkMhADFwdQZocBSyBr Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable I'm hoping Alexei is on the list now. Andi Kleen and I were talking about ways to generally harden eBPF. We were a bit concerned that eBPF could leave around attacker-controlled values on the stack that might allow later, speculatively-executed kernel code to be exploited. One thing I wanted to clarify: The eBPF stack (BPF_REG_FP) *is* the kernel stack, correct? I see this code getting generated by emit_prologue(), for instance: > /* sub rsp, rounded_stack_depth + AUX_STACK_SPACE */ > EMIT3_off32(0x48, 0x81, 0xEC, > round_up(stack_depth, 8) + AUX_STACK_SPACE); Or does that only apply to the JIT? One cheap, simple, mitigation for that would be to zero any kernel stack that could have eBPF data in it during BPF_EXIT. I guess we could do that after the 'leave' but before the 'ret' in the x86 JIT. We could also zero out all of the eBPF contents in the hardware registers at this point. That would help reduce the gadgets in the kernel that could be exploited. For speculative store bypass, specifically, would it make sense to do an MFENCE at BFP_EXIT for unprivileged programs that do writes to the stack? That way, the result of any BPF stores will be known before we start running kernel code again. We would not need any of these for privileged programs. --tTVaCrduF5K56L5CkMhADFwdQZocBSyBr--