bpf: fix OOB read when printing XDP link fdinfo
Subsystems (4)
v2 cover bpf: fix OOB read when printing XDP link fdinfo
See the first patch message for details. Same fix as before, except that the macro invocation is guarded by CONFIG_NET now.
Lorenz Bauer (1):
bpf: fix OOB read when printing XDP link fdinfo
include/linux/bpf_types.h | 1 + 1 file changed, 1 insertion(+)
Signature · 1 line
2.30.2
PATCH v2 1/1 bpf: fix OOB read when printing XDP link fdinfo
We got the following UBSAN report on one of our testing machines:
================================================================================
UBSAN: array-index-out-of-bounds in kernel/bpf/syscall.c:2389:24
index 6 is out of range for type 'char *[6]'
CPU: 43 PID: 930921 Comm: systemd-coredum Tainted: G O 5.10.48-cloudflare-kasan-2021.7.0 #1
Hardware name: <snip>
Call Trace:
dump_stack+0x7d/0xa3
ubsan_epilogue+0x5/0x40
__ubsan_handle_out_of_bounds.cold+0x43/0x48
? seq_printf+0x17d/0x250
bpf_link_show_fdinfo+0x329/0x380
? bpf_map_value_size+0xe0/0xe0
? put_files_struct+0x20/0x2d0
? __kasan_kmalloc.constprop.0+0xc2/0xd0
seq_show+0x3f7/0x540
seq_read_iter+0x3f8/0x1040
seq_read+0x329/0x500
? seq_read_iter+0x1040/0x1040
? __fsnotify_parent+0x80/0x820
? __fsnotify_update_child_dentry_flags+0x380/0x380
vfs_read+0x123/0x460
ksys_read+0xed/0x1c0
? __x64_sys_pwrite64+0x1f0/0x1f0
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
<snip>
================================================================================
================================================================================
UBSAN: object-size-mismatch in kernel/bpf/syscall.c:2384:2From the report, we can infer that some array access in bpf_link_show_fdinfo at index 6 is out of bounds. The obvious candidate is bpf_link_type_strs[BPF_LINK_TYPE_XDP] with BPF_LINK_TYPE_XDP == 6. It turns out that BPF_LINK_TYPE_XDP is missing from bpf_types.h and therefore doesn't have an entry in bpf_link_type_strs:
pos: 0
flags: 02000000
mnt_id: 13
link_type: (null)
link_id: 4
prog_tag: bcf7977d3b93787c
prog_id: 4
ifindex: 1--- include/linux/bpf_types.h | 1 + 1 file changed, 1 insertion(+)
include/linux/bpf_types.h +1 -0
@@ -134,4 +134,5 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_CGROUP, cgroup) BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)#ifdef CONFIG_NET BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns) +BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)#endif
Signature · 1 line
2.30.2
John Fastabend
reviewerQuoted 65 lines · Lorenz Bauer
We got the following UBSAN report on one of our testing machines:
================================================================================ UBSAN: array-index-out-of-bounds in kernel/bpf/syscall.c:2389:24 index 6 is out of range for type 'char *[6]' CPU: 43 PID: 930921 Comm: systemd-coredum Tainted: G O 5.10.48-cloudflare-kasan-2021.7.0 #1 Hardware name: <snip> Call Trace: dump_stack+0x7d/0xa3 ubsan_epilogue+0x5/0x40 __ubsan_handle_out_of_bounds.cold+0x43/0x48 ? seq_printf+0x17d/0x250 bpf_link_show_fdinfo+0x329/0x380 ? bpf_map_value_size+0xe0/0xe0 ? put_files_struct+0x20/0x2d0 ? __kasan_kmalloc.constprop.0+0xc2/0xd0 seq_show+0x3f7/0x540 seq_read_iter+0x3f8/0x1040 seq_read+0x329/0x500 ? seq_read_iter+0x1040/0x1040 ? __fsnotify_parent+0x80/0x820 ? __fsnotify_update_child_dentry_flags+0x380/0x380 vfs_read+0x123/0x460 ksys_read+0xed/0x1c0 ? __x64_sys_pwrite64+0x1f0/0x1f0 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 <snip> ================================================================================ ================================================================================ UBSAN: object-size-mismatch in kernel/bpf/syscall.c:2384:2From the report, we can infer that some array access in
bpf_link_show_fdinfoat index 6 is out of bounds. The obvious candidate is bpf_link_type_strs[BPF_LINK_TYPE_XDP] withBPF_LINK_TYPE_XDP== 6. It turns out thatBPF_LINK_TYPE_XDPis missing frombpf_types.hand therefore doesn't have an entry inbpf_link_type_strs:pos: 0 flags: 02000000 mnt_id: 13 link_type: (null) link_id: 4 prog_tag: bcf7977d3b93787c prog_id: 4 ifindex: 1Fixes aa8d3a716b59 ("bpf, xdp: Add bpf_link-based XDP attachment API")Signed-off-by Lorenz Bauer <[email protected]>--- include/linux/bpf_types.h | 1 + 1 file changed, 1 insertion(+)include/linux/bpf_types.h +1
-0@@ -134,4 +134,5 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_CGROUP, cgroup) BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)#ifdef CONFIG_NET BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns) +BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)#endif Signature · 1 line
2.30.2
Still lgtm.
Acked-by; John Fastabend <[email protected]>
Andrii Nakryiko
AppliedQuoted 7 lines · Lorenz Bauer
See the first patch message for details. Same fix as before, except that the macro invocation is guarded by
CONFIG_NETnow.Lorenz Bauer (1):
bpf: fix OOB read when printing XDP link fdinfo
Applied to bpf tree, thanks. There is no need to send a cover letter for a single patch, though, and it didn't contribute much to the description in this case, so I dropped it.
Quoted 6 lines
include/linux/bpf_types.h | 1 + 1 file changed, 1 insertion(+)--
2.30.2