Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	<netdev@vger.kernel.org>
Subject: [PATCH 1/6] net: xfrm: fix memory leak in xfrm_user_rcv_msg
Date: Wed, 4 Aug 2021 09:03:24 +0200	[thread overview]
Message-ID: <20210804070329.1357123-2-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20210804070329.1357123-1-steffen.klassert@secunet.com>

From: Pavel Skripkin <paskripkin@gmail.com>

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>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 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 b47d613409b7..7aff641c717d 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.25.1


  reply	other threads:[~2021-08-04  7:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04  7:03 pull request (net): ipsec 2021-08-04 Steffen Klassert
2021-08-04  7:03 ` Steffen Klassert [this message]
2021-08-04 10:10   ` [PATCH 1/6] net: xfrm: fix memory leak in xfrm_user_rcv_msg patchwork-bot+netdevbpf
2021-08-04  7:03 ` [PATCH 2/6] Revert "xfrm: policy: Read seqcount outside of rcu-read side in xfrm_policy_lookup_bytype" Steffen Klassert
2021-08-04  7:03 ` [PATCH 3/6] xfrm: Fix RCU vs hash_resize_mutex lock inversion Steffen Klassert
2021-08-04  7:03 ` [PATCH 4/6] net/xfrm/compat: Copy xfrm_spdattr_type_t atributes Steffen Klassert
2021-08-04  7:03 ` [PATCH 5/6] selftests/net/ipsec: Add test for xfrm_spdattr_type_t Steffen Klassert
2021-08-04  7:03 ` [PATCH 6/6] net: xfrm: Fix end of loop tests for list_for_each_entry Steffen Klassert
2021-08-04 10:10 ` pull request (net): ipsec 2021-08-04 patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210804070329.1357123-2-steffen.klassert@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH 1/6] net: xfrm: fix memory leak in xfrm_user_rcv_msg' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).