Skip to content

Commit ec69daa

Browse files
Tetsuo HandaAlexei Starovoitov
authored andcommitted
bpf: Fix reference count leak in bpf_prog_test_run_xdp()
syzbot is reporting unregister_netdevice: waiting for sit0 to become free. Usage count = 2 problem. A debug printk() patch found that a refcount is obtained at xdp_convert_md_to_buff() from bpf_prog_test_run_xdp(). According to commit ec94670 ("bpf: Support specifying ingress via xdp_md context in BPF_PROG_TEST_RUN"), the refcount obtained by xdp_convert_md_to_buff() will be released by xdp_convert_buff_to_md(). Therefore, we can consider that the error handling path introduced by commit 1c19499 ("bpf: introduce frags support to bpf_prog_test_run_xdp()") forgot to call xdp_convert_buff_to_md(). Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=881d65229ca4f9ae8c84 Fixes: 1c19499 ("bpf: introduce frags support to bpf_prog_test_run_xdp()") Signed-off-by: Tetsuo Handa <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 9df5fad commit ec69daa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

net/bpf/test_run.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,13 +1363,13 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
13631363

13641364
if (sinfo->nr_frags == MAX_SKB_FRAGS) {
13651365
ret = -ENOMEM;
1366-
goto out;
1366+
goto out_put_dev;
13671367
}
13681368

13691369
page = alloc_page(GFP_KERNEL);
13701370
if (!page) {
13711371
ret = -ENOMEM;
1372-
goto out;
1372+
goto out_put_dev;
13731373
}
13741374

13751375
frag = &sinfo->frags[sinfo->nr_frags++];
@@ -1381,7 +1381,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
13811381
if (copy_from_user(page_address(page), data_in + size,
13821382
data_len)) {
13831383
ret = -EFAULT;
1384-
goto out;
1384+
goto out_put_dev;
13851385
}
13861386
sinfo->xdp_frags_size += data_len;
13871387
size += data_len;
@@ -1396,6 +1396,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
13961396
ret = bpf_test_run_xdp_live(prog, &xdp, repeat, batch_size, &duration);
13971397
else
13981398
ret = bpf_test_run(prog, &xdp, repeat, &retval, &duration, true);
1399+
out_put_dev:
13991400
/* We convert the xdp_buff back to an xdp_md before checking the return
14001401
* code so the reference count of any held netdevice will be decremented
14011402
* even if the test run failed.

0 commit comments

Comments
 (0)