Linux kernel source tree
Go to file
Hou Tao 797d73ee23 bpf: Check the remaining info_cnt before repeating btf fields
When trying to repeat the btf fields for array of nested struct, it
doesn't check the remaining info_cnt. The following splat will be
reported when the value of ret * nelems is greater than BTF_FIELDS_MAX:

  ------------[ cut here ]------------
  UBSAN: array-index-out-of-bounds in ../kernel/bpf/btf.c:3951:49
  index 11 is out of range for type 'btf_field_info [11]'
  CPU: 6 UID: 0 PID: 411 Comm: test_progs ...... 6.11.0-rc4+ #1
  Tainted: [O]=OOT_MODULE
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ...
  Call Trace:
   <TASK>
   dump_stack_lvl+0x57/0x70
   dump_stack+0x10/0x20
   ubsan_epilogue+0x9/0x40
   __ubsan_handle_out_of_bounds+0x6f/0x80
   ? kallsyms_lookup_name+0x48/0xb0
   btf_parse_fields+0x992/0xce0
   map_create+0x591/0x770
   __sys_bpf+0x229/0x2410
   __x64_sys_bpf+0x1f/0x30
   x64_sys_call+0x199/0x9f0
   do_syscall_64+0x3b/0xc0
   entry_SYSCALL_64_after_hwframe+0x4b/0x53
  RIP: 0033:0x7fea56f2cc5d
  ......
   </TASK>
  ---[ end trace ]---

Fix it by checking the remaining info_cnt in btf_repeat_fields() before
repeating the btf fields.

Fixes: 64e8ee8148 ("bpf: look into the types of the fields of a struct type recursively.")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20241008071114.3718177-2-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2024-10-09 16:32:46 -07:00
arch Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
block
certs
crypto
Documentation NFS Client Updates for Linux 6.12 2024-09-24 15:44:18 -07:00
drivers Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
fs NFS Client Updates for Linux 6.12 2024-09-24 15:44:18 -07:00
include bpf: Make sure internal and UAPI bpf_redirect flags don't overlap 2024-10-01 21:40:12 +02:00
init
io_uring for-6.12/io_uring-20240922 2024-09-24 11:11:38 -07:00
ipc struct fd layout change (and conversion to accessor helpers) 2024-09-23 09:35:36 -07:00
kernel bpf: Check the remaining info_cnt before repeating btf fields 2024-10-09 16:32:46 -07:00
lib Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
LICENSES
mm lsm/stable-6.12 PR 20240923 2024-09-24 10:18:15 -07:00
net bpf: Make sure internal and UAPI bpf_redirect flags don't overlap 2024-10-01 21:40:12 +02:00
rust
samples Landlock updates for v6.12-rc1 2024-09-24 10:40:11 -07:00
scripts Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
security bpf-next-6.12-struct-fd 2024-09-24 14:54:26 -07:00
sound firewire updates for v6.12 2024-09-23 12:55:27 -07:00
tools bpf: selftests: send packet to devmap redirect XDP 2024-10-02 13:51:43 -07:00
usr
virt struct fd layout change (and conversion to accessor helpers) 2024-09-23 09:35:36 -07:00
.clang-format
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
.mailmap Summary 2024-09-24 11:08:40 -07:00
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS Description for this pull request: 2024-09-24 15:26:04 -07:00
Makefile Kbuild updates for v6.12 2024-09-24 13:02:06 -07:00
README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the reStructuredText markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.