]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix potential array overflow in bpf_trampoline_get_progs()
authorYuntao Wang <ytcoode@gmail.com>
Sat, 30 Apr 2022 13:08:03 +0000 (21:08 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 12 May 2022 04:24:20 +0000 (21:24 -0700)
commit3b52714c8cd998df877a2a347025492c328b7a44
tree7fe531debdf3412e10287ed5d4745c6a6eafdd57
parent702c8a7fb7a04405a935a2428387a9f29c336e59
bpf: Fix potential array overflow in bpf_trampoline_get_progs()

The cnt value in the 'cnt >= BPF_MAX_TRAMP_PROGS' check does not
include BPF_TRAMP_MODIFY_RETURN bpf programs, so the number of
the attached BPF_TRAMP_MODIFY_RETURN bpf programs in a trampoline
can exceed BPF_MAX_TRAMP_PROGS.

When this happens, the assignment '*progs++ = aux->prog' in
bpf_trampoline_get_progs() will cause progs array overflow as the
progs field in the bpf_tramp_progs struct can only hold at most
BPF_MAX_TRAMP_PROGS bpf programs.

Fixes: b1c01d5c664f ("bpf: Refactor trampoline update code")
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Link: https://lore.kernel.org/r/20220430130803.210624-1-ytcoode@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/trampoline.c