Skip to contentSkip to conversation

net: xfrm: fix memory leak in xfrm_user_rcv_msg

PATCH Applied Pavel Skripkin 2 participants 2 messages Jun 25, 2021 – Jun 30, 2021

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

PATCH 1/1 net: xfrm: fix memory leak in xfrm_user_rcv_msg

Syzbot reported memory leak in xfrm_user_rcv_msg(). The problem was is non-freed skb's frag_list.

In skb_release_all() skb_release_data() will be called only in case of skb->head != NULL, but netlink_skb_destructor() sets head to NULL. So, allocated frag_list skb should be freed manualy, since consume_skb() won't take care of it

Fixes 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Reported-and-tested-by [email protected]

---

One thing I'm not sure about is did I choose the rigth place to free this skb, maybe we can move this clean up a little bit deeper, like in xfrm_alloc_userspi()?

---
 net/xfrm/xfrm_user.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
net/xfrm/xfrm_user.c +10 -0
index f0aecee4d539..ff60ff804074 100644
@@ -2811,6 +2811,16 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
 
 	err = link->doit(skb, nlh, attrs);
 
+	/* We need to free skb allocated in xfrm_alloc_compat() before
+	 * returning from this function, because consume_skb() won't take
+	 * care of frag_list since netlink destructor sets
+	 * sbk->head to NULL. (see netlink_skb_destructor())
+	 */
+	if (skb_has_frag_list(skb)) {
+		kfree_skb(skb_shinfo(skb)->frag_list);
+		skb_shinfo(skb)->frag_list = NULL;
+	}
+
 err:
 	kvfree(nlh64);
 	return err;
Signature · 1 line
2.32.0
maintainer Applied
#1 lore raw
Quoted 11 lines · Pavel Skripkin

Syzbot reported memory leak in xfrm_user_rcv_msg(). The problem was is non-freed skb's frag_list.

In skb_release_all() skb_release_data() will be called only in case of skb->head != NULL, but netlink_skb_destructor() sets head to NULL. So, allocated frag_list skb should be freed manualy, since consume_skb() won't take care of it

Fixes 5106f4a8acff ("xfrm/compat: Add 32=>64-bit messages translator")
Reported-and-tested-by [email protected]

Applied, thanks a lot!