Skip to content

Commit 217970f

Browse files
borkmannKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
bpf: Fix mprog detachment for empty mprog entry
syzbot reported an UBSAN array-index-out-of-bounds access in bpf_mprog_read() upon bpf_mprog_detach(). While it did not have a reproducer, I was able to manually reproduce through an empty mprog entry which just has miniq present. The latter is important given otherwise we get an ENOENT error as tcx detaches the whole mprog entry. The index 4294967295 was triggered via NULL dtuple.prog which then attempts to detach from the back. bpf_mprog_fetch() in this case did hit the idx == total and therefore tried to grab the entry at idx -1. Fix it by adding an explicit bpf_mprog_total() check in bpf_mprog_detach() and bail out early with ENOENT. Fixes: 053c8e1 ("bpf: Add generic attach/detach/query API for multi-progs") Reported-by: [email protected] Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 8530d49 commit 217970f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/mprog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ int bpf_mprog_detach(struct bpf_mprog_entry *entry,
337337
return -EINVAL;
338338
if (revision && revision != bpf_mprog_revision(entry))
339339
return -ESTALE;
340+
if (!bpf_mprog_total(entry))
341+
return -ENOENT;
340342
ret = bpf_mprog_tuple_relative(&rtuple, id_or_fd, flags,
341343
prog ? prog->type :
342344
BPF_PROG_TYPE_UNSPEC);

0 commit comments

Comments
 (0)