ANDROID: bpf: validate bpf_func when BPF_JIT is enabled with CFI
authorSami Tolvanen <samitolvanen@google.com>
Wed, 4 Sep 2019 21:08:16 +0000 (14:08 -0700)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:24:58 +0000 (20:24 +0300)
commit542d0b7b5e48d44ad3986c149d552e890f425b72
tree248892f30eea4b3b664f8cf4eed8b1734d5d7a4a
parent3937c418e3bfc2ece2426241d30b214bf508157a
ANDROID: bpf: validate bpf_func when BPF_JIT is enabled with CFI

With CONFIG_BPF_JIT, the kernel makes indirect calls to dynamically
generated code, which the compile-time Control-Flow Integrity (CFI)
checking cannot validate. This change adds basic sanity checking to
ensure we are jumping to a valid location, which narrows down the
attack surface on the stored pointer.

In addition, this change adds a weak arch_bpf_jit_check_func function,
which architectures that implement BPF JIT can override to perform
additional validation, such as verifying that the pointer points to
the correct memory region.

Bug: 140377409
Change-Id: I8ebac6637ab6bd9db44716b1c742add267298669
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
include/linux/filter.h
kernel/bpf/core.c
net/Kconfig