]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix handling of XADD on BTF memory
authorJann Horn <jannh@google.com>
Fri, 17 Apr 2020 00:00:07 +0000 (02:00 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 21 Apr 2020 01:41:34 +0000 (18:41 -0700)
commit314ed84f61ea55b4df5e1aa643287cc0743d1065
treed1f5c6273b9160b4a90058afdd0271063f610a4c
parent071755280b8a002c565d4a0cca8d67772c4c739a
bpf: Fix handling of XADD on BTF memory

check_xadd() can cause check_ptr_to_btf_access() to be executed with
atype==BPF_READ and value_regno==-1 (meaning "just check whether the access
is okay, don't tell me what type it will result in").
Handle that case properly and skip writing type information, instead of
indexing into the registers at index -1 and writing into out-of-bounds
memory.

Note that at least at the moment, you can't actually write through a BTF
pointer, so check_xadd() will reject the program after calling
check_ptr_to_btf_access with atype==BPF_WRITE; but that's after the
verifier has already corrupted memory.

This patch assumes that BTF pointers are not available in unprivileged
programs.

Fixes: 953d2350a30a ("bpf: Implement accurate raw_tp context access via BTF")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200417000007.10734-2-jannh@google.com
kernel/bpf/verifier.c