All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: xfrm: fix memory leak in xfrm_user_rcv_msg
@ 2021-06-25 10:23 ` Pavel Skripkin
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Skripkin @ 2021-06-25 10:23 UTC (permalink / raw)
  To: steffen.klassert, herbert, davem, 0x7f454c46
  Cc: netdev, linux-kernel, linux-kernel-mentees, Pavel Skripkin,
	syzbot+fb347cf82c73a90efcca

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: syzbot+fb347cf82c73a90efcca@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---

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(+)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index f0aecee4d539..ff60ff804074 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] net: xfrm: fix memory leak in xfrm_user_rcv_msg
@ 2021-06-25 10:23 ` Pavel Skripkin
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Skripkin @ 2021-06-25 10:23 UTC (permalink / raw)
  To: steffen.klassert, herbert, davem, 0x7f454c46
  Cc: netdev, linux-kernel-mentees, linux-kernel, syzbot+fb347cf82c73a90efcca

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: syzbot+fb347cf82c73a90efcca@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---

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(+)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index f0aecee4d539..ff60ff804074 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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;
-- 
2.32.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: xfrm: fix memory leak in xfrm_user_rcv_msg
  2021-06-25 10:23 ` Pavel Skripkin
@ 2021-06-30  6:51   ` Steffen Klassert
  -1 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2021-06-30  6:51 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: herbert, davem, 0x7f454c46, netdev, linux-kernel,
	linux-kernel-mentees, syzbot+fb347cf82c73a90efcca

On Fri, Jun 25, 2021 at 01:23:54PM +0300, Pavel Skripkin wrote:
> 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: syzbot+fb347cf82c73a90efcca@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>

Applied, thanks a lot!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: xfrm: fix memory leak in xfrm_user_rcv_msg
@ 2021-06-30  6:51   ` Steffen Klassert
  0 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2021-06-30  6:51 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: herbert, netdev, 0x7f454c46, linux-kernel, linux-kernel-mentees,
	davem, syzbot+fb347cf82c73a90efcca

On Fri, Jun 25, 2021 at 01:23:54PM +0300, Pavel Skripkin wrote:
> 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: syzbot+fb347cf82c73a90efcca@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>

Applied, thanks a lot!
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-30  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 10:23 [PATCH] net: xfrm: fix memory leak in xfrm_user_rcv_msg Pavel Skripkin
2021-06-25 10:23 ` Pavel Skripkin
2021-06-30  6:51 ` Steffen Klassert
2021-06-30  6:51   ` Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.