]> git.baikalelectronics.ru Git - kernel.git/commit
net: bpf: arm64: address randomize and write protect JIT code
authorDaniel Borkmann <dborkman@redhat.com>
Tue, 16 Sep 2014 07:48:50 +0000 (08:48 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Mon, 20 Oct 2014 16:47:03 +0000 (17:47 +0100)
commit3aba6f9dd5f9a5e45b7b4f2aa12a97fde557b9c8
treef2497f02c9435911adbdb66fd95e0dc6051acd78
parent30c928fe55dbd16c043366b5f935303aa1dab98a
net: bpf: arm64: address randomize and write protect JIT code

This is the ARM64 variant for 51d1d536b5a ("x86: bpf_jit_comp: secure bpf
jit against spraying attacks").

Thanks to commit 38a5b6e6d200 ("arm64: Add CONFIG_DEBUG_SET_MODULE_RONX
support") which added necessary infrastructure, we can now implement
RO marking of eBPF generated JIT image pages and randomize start offset
for the JIT code, so that it does not reside directly on a page boundary
anymore. Likewise, the holes are filled with illegal instructions: here
we use BRK #0x100 (opcode 0xd4202000) to trigger a fault in the kernel
(unallocated BRKs would trigger a fault through do_debug_exception). This
seems more reliable as we don't have a guaranteed undefined instruction
space on ARM64.

This is basically the ARM64 variant of what we already have in ARM via
commit 65d9210e7720 ("net: bpf: arm: address randomize and write protect
JIT code"). Moreover, this commit also presents a merge resolution due to
conflicts with commit adb097d31beb ("net: bpf: make eBPF interpreter images
read-only") as we don't use kfree() in bpf_jit_free() anymore to release
the locked bpf_prog structure, but instead bpf_prog_unlock_free() through
a different allocator.

JIT tested on aarch64 with BPF test suite.

Reference: http://mainisusuallyafunction.blogspot.com/2012/11/attacking-hardened-linux-systems-with.html
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Reviewed-by: Zi Shen Lim <zlim.lnx@gmail.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/net/bpf_jit_comp.c