]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Do not allow btf_ctx_access with __int128 types
authorJohn Fastabend <john.fastabend@gmail.com>
Wed, 24 Jun 2020 22:20:39 +0000 (15:20 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 25 Jun 2020 14:17:05 +0000 (16:17 +0200)
commit238ec08f7d711cf4e9e799ae97b9649baf6e7985
treeb02a3af3bee5967515fb0ca85d736b83b975f897
parent2c13ae982c47b32e7f7330f2ac76758ef4c05a83
bpf: Do not allow btf_ctx_access with __int128 types

To ensure btf_ctx_access() is safe the verifier checks that the BTF
arg type is an int, enum, or pointer. When the function does the
BTF arg lookup it uses the calculation 'arg = off / 8'  using the
fact that registers are 8B. This requires that the first arg is
in the first reg, the second in the second, and so on. However,
for __int128 the arg will consume two registers by default LLVM
implementation. So this will cause the arg layout assumed by the
'arg = off / 8' calculation to be incorrect.

Because __int128 is uncommon this patch applies the easiest fix and
will force int types to be sizeof(u64) or smaller so that they will
fit in a single register.

v2: remove unneeded parens per Andrii's feedback

Fixes: 953d2350a30a0 ("bpf: Implement accurate raw_tp context access via BTF")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/159303723962.11287.13309537171132420717.stgit@john-Precision-5820-Tower
include/linux/btf.h
kernel/bpf/btf.c