Skip to content

Commit

Permalink
net: bpf: correctly handle errors in sk_attach_filter()
Browse files Browse the repository at this point in the history
Commit "net: bpf: make eBPF interpreter images read-only" has changed bpf_prog
to be vmalloc()ed but never handled some of the errors paths of the old code.

On error within sk_attach_filter (which userspace can easily trigger), we'd
kfree() the vmalloc()ed memory, and leak the internal bpf_work_struct.

Signed-off-by: Sasha Levin <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Acked-by: Hannes Frederic Sowa <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
sashalevin authored and davem330 committed Sep 13, 2014
1 parent 3fc8867 commit c0d1379
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,15 +1047,15 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
return -ENOMEM;

if (copy_from_user(prog->insns, fprog->filter, fsize)) {
kfree(prog);
__bpf_prog_free(prog);
return -EFAULT;
}

prog->len = fprog->len;

err = bpf_prog_store_orig_filter(prog, fprog);
if (err) {
kfree(prog);
__bpf_prog_free(prog);
return -ENOMEM;
}

Expand Down

0 comments on commit c0d1379

Please sign in to comment.