Skip to contentSkip to conversation

netrom: hold sock when setting skb->destructor

PATCH In review Cong Wang 2 participants 2 messages Jul 23, 2019 – Jul 24, 2019

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 netrom: hold sock when setting skb->destructor

sock_efree() releases the sock refcnt, if we don't hold this refcnt when setting skb->destructor to it, the refcnt would not be balanced. This leads to several bug reports from syzbot.

I have checked other users of sock_efree(), all of them hold the sock refcnt.

Fixes c8c8218ec5af ("netrom: fix a memory leak in nr_rx_frame()")
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Cc Ralf Baechle <[email protected]>
---
 net/netrom/af_netrom.c | 1 +
 1 file changed, 1 insertion(+)
net/netrom/af_netrom.c +1 -0
index 96740d389377..c4f54ad2b98a 100644
@@ -967,6 +967,7 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
 
 	window = skb->data[20];
 
+	sock_hold(make);
 	skb->sk             = make;
 	skb->destructor     = sock_efree;
 	make->sk_state	    = TCP_ESTABLISHED;
Signature · 1 line
2.21.0
maintainer
#1 lore raw

From: Cong Wang <[email protected]>
Date: Mon, 22 Jul 2019 20:41:22 -0700

Quoted 7 lines

sock_efree() releases the sock refcnt, if we don't hold this refcnt when setting skb->destructor to it, the refcnt would not be balanced. This leads to several bug reports from syzbot.

I have checked other users of sock_efree(), all of them hold the sock refcnt.

Quoted 7 lines
Fixes c8c8218ec5af ("netrom: fix a memory leak in nr_rx_frame()")
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Reported-and-tested-by <[email protected]>
Cc Ralf Baechle <[email protected]>

Applied and queued up for -stable.