Skip to contentSkip to conversation

xfrm: free skb if nlsk pointer is NULL

PATCH Applied Florian Westphal 2 participants 2 messages Jun 25, 2018

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

PATCH 1/1 xfrm: free skb if nlsk pointer is NULL

nlmsg_multicast() always frees the skb, so in case we cannot call it we must do that ourselves.

Fixes 21ee543edc0dea ("xfrm: fix race between netns cleanup and state expire notification")
---
 net/xfrm/xfrm_user.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/xfrm/xfrm_user.c +6 -4
index 080035f056d9..5fd44fadb195 100644
@@ -1025,10 +1025,12 @@ static inline int xfrm_nlmsg_multicast(struct net *net, struct sk_buff *skb,
 {
 	struct sock *nlsk = rcu_dereference(net->xfrm.nlsk);
 
-	if (nlsk)
-		return nlmsg_multicast(nlsk, skb, pid, group, GFP_ATOMIC);
-	else
-		return -1;
+	if (!nlsk) {
+		kfree_skb(skb);
+		return -EPIPE;
+	}
+
+	return nlmsg_multicast(nlsk, skb, pid, group, GFP_ATOMIC);
 }
 
 static inline unsigned int xfrm_spdinfo_msgsize(void)
Signature · 1 line
2.16.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Florian Westphal

nlmsg_multicast() always frees the skb, so in case we cannot call it we must do that ourselves.

Fixes 21ee543edc0dea ("xfrm: fix race between netns cleanup and state expire notification")

Applied, thanks Florian!