Thread (3 messages) flat view 3 messages, 2 authors, 2022-09-19
STALE1456d

[PATCH] ipv4: ping: Fix potential use-after-free bug

From: Liang He <hidden>
Date: 2022-09-16 10:11:05
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

In ping_unhash(), we should move sock_put(sk) after any possible
access point as the put function may free the object.

Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: Liang He <redacted>
---

 I have found other places containing similar code patterns.

 net/ipv4/ping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index b83c2bd9d722..f90c86d37ffc 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -157,10 +157,10 @@ void ping_unhash(struct sock *sk)
 	spin_lock(&ping_table.lock);
 	if (sk_hashed(sk)) {
 		hlist_nulls_del_init_rcu(&sk->sk_nulls_node);
-		sock_put(sk);
 		isk->inet_num = 0;
 		isk->inet_sport = 0;
 		sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
+		sock_put(sk);
 	}
 	spin_unlock(&ping_table.lock);
 }
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help