Skip to content

Commit

Permalink
net: sock: fix access via invalid file descriptor
Browse files Browse the repository at this point in the history
0day robot reported the following crash:
[   21.233581] BUG: unable to handle kernel NULL pointer dereference at 0000000000000007
[   21.234709] IP: [<ffffffff8156ebda>] sk_attach_bpf+0x39/0xc2

It's due to bpf_prog_get() returning ERR_PTR.
Check it properly.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Fixes: 89aa075 ("net: sock: allow eBPF programs to be attached to sockets")
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexei Starovoitov authored and David S. Miller committed Dec 11, 2014
1 parent f95b414 commit 198bf1b
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 @@ -1103,8 +1103,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
return -EPERM;

prog = bpf_prog_get(ufd);
if (!prog)
return -EINVAL;
if (IS_ERR(prog))
return PTR_ERR(prog);

if (prog->aux->prog_type != BPF_PROG_TYPE_SOCKET_FILTER) {
/* valid fd, but invalid program type */
Expand Down

0 comments on commit 198bf1b

Please sign in to comment.