Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Fix overflow in BTF sanity checks

btf_header's str_off+str_len or type_off+type_len can overflow as they
are u32s. This will lead to bypassing the sanity checks during BTF
parsing, resulting in crashes afterwards. Fix by using 64-bit signed
integers for comparison.

Fixes: d8123624506c ("libbpf: Fix BTF data layout checks and allow empty BTF")
Reported-by: Evgeny Vereshchagin <evvers@ya.ru>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211023003157.726961-1-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
5245dafe 1c508843

+2 -2
+2 -2
tools/lib/bpf/btf.c
··· 241 241 } 242 242 243 243 meta_left = btf->raw_size - sizeof(*hdr); 244 - if (meta_left < hdr->str_off + hdr->str_len) { 244 + if (meta_left < (long long)hdr->str_off + hdr->str_len) { 245 245 pr_debug("Invalid BTF total size:%u\n", btf->raw_size); 246 246 return -EINVAL; 247 247 } 248 248 249 - if (hdr->type_off + hdr->type_len > hdr->str_off) { 249 + if ((long long)hdr->type_off + hdr->type_len > hdr->str_off) { 250 250 pr_debug("Invalid BTF data sections layout: type data at %u + %u, strings data at %u + %u\n", 251 251 hdr->type_off, hdr->type_len, hdr->str_off, hdr->str_len); 252 252 return -EINVAL;