Skip to contentSkip to conversation

net: sock: fix access via invalid file descriptor

PATCH Applied Alexei Starovoitov 2 participants 2 messages Dec 11, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sock: fix access via invalid file descriptor

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.

Fixes 89aa075832b0 ("net: sock: allow eBPF programs to be attached to sockets")

---
Silly mistake. I was sure I've checked this error path. Apparently not :(

 net/core/filter.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
index 8cc3c03078b3..ec9baea10c16 100644
@@ -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 */
Signature · 1 line
1.7.9.5
maintainer Applied
#1 lore raw

From: Alexei Starovoitov <[email protected]>
Date: Wed, 10 Dec 2014 20:14:55 -0800

Quoted 4 lines

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
Quoted 8 lines

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

Fixes 89aa075832b0 ("net: sock: allow eBPF programs to be attached to sockets")

---
Silly mistake. I was sure I've checked this error path. Apparently not :(

Applied, thanks Alexei.