Skip to contentSkip to conversation

ipv4: fix NULL pointer dereference in __inet_put_port()

PATCH In review fanhui 2 participants 2 messages Mar 29, 2016

Subsystems (3)
lore
Share & tools
lore

fanhui

author
#0 lore raw

PATCH 1/1 ipv4: fix NULL pointer dereference in __inet_put_port()

There may be race condition when accessing inet_csk(sk)->icsk_bind_hash, which leads to a crash like this:

Unable to handle kernel NULL pointer dereference at virtual
address 00000010
......
[<ffffffc000929140>] inet_put_port+0x80/0xb8
[<ffffffc00092c4bc>] tcp_set_state+0xc4/0x110
[<ffffffc00092ce68>] tcp_done+0x60/0xb8
[<ffffffc000930718>] tcp_nuke_addr+0x22c/0x2a0
[<ffffffc000950558>] devinet_ioctl+0x294/0x680
[<ffffffc000951e68>] inet_ioctl+0xd4/0x100
[<ffffffc00089fd04>] sock_do_ioctl+0x40/0x70
[<ffffffc0008a0238>] sock_ioctl+0x288/0x2a8
[<ffffffc000193358>] do_vfs_ioctl+0x4b4/0x588
[<ffffffc000193494>] SyS_ioctl+0x68/0x94

......

---
 net/ipv4/inet_hashtables.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv4/inet_hashtables.c +3 -0
index bc68ece..742c618 100644
@@ -112,11 +112,14 @@ static void __inet_put_port(struct sock *sk)
 
 	spin_lock(&head->lock);
 	tb = inet_csk(sk)->icsk_bind_hash;
+	if (!tb)
+		goto out;
 	__sk_del_bind_node(sk);
 	tb->num_owners--;
 	inet_csk(sk)->icsk_bind_hash = NULL;
 	inet_sk(sk)->inet_num = 0;
 	inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
+out:
 	spin_unlock(&head->lock);
 }
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: fanhui <[email protected]>
Date: Tue, 29 Mar 2016 14:45:53 +0800

Quoted 1 line

[<ffffffc000930718>] tcp_nuke_addr+0x22c/0x2a0

Do not report or fix problems in non-mainline kernels.

Thank you.