]> 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)
commite594f1543b271d675a5310764bc478cfd1a33789
treef2497f02c9435911adbdb66fd95e0dc6051acd78
parentd6251a244eb3b4f37c103abdc113e042527458d9
net: bpf: arm64: address randomize and write protect JIT code

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

Thanks to commit e3f5484597b2 ("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 3e9588df24cb ("net: bpf: arm: address randomize and write protect
JIT code"). Moreover, this commit also presents a merge resolution due to
conflicts with commit 073a09ee970b ("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