mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: Young Xiao <92siuyang@gmail.com>
Cc: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] af_key: Fix memory leak in key_notify_policy.
Date: Fri, 14 Jun 2019 10:53:46 +0200	[thread overview]
Message-ID: <20190614085346.GN17989@gauss3.secunet.de> (raw)
In-Reply-To: <1560500786-572-1-git-send-email-92siuyang@gmail.com>

On Fri, Jun 14, 2019 at 04:26:26PM +0800, Young Xiao wrote:
> We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails.
> Fix this by freeing it on error.
> 
> Signed-off-by: Young Xiao <92siuyang@gmail.com>
> ---
>  net/key/af_key.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/key/af_key.c b/net/key/af_key.c
> index 4af1e1d..ec414f6 100644
> --- a/net/key/af_key.c
> +++ b/net/key/af_key.c
> @@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
>  	}
>  	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
>  	if (err < 0)
> +		kfree_skb(out_skb);
>  		goto out;

Did you test this?

You need to add braces, otherwise 'goto out' will happen unconditionally.

>  
>  	out_hdr = (struct sadb_msg *) out_skb->data;
> @@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
>  
>  	err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
>  	if (err < 0)
> +		kfree_skb(out_skb);
>  		return err;

Same here.

  reply	other threads:[~2019-06-14  8:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14  8:26 Young Xiao
2019-06-14  8:53 ` Steffen Klassert [this message]
2019-06-14  9:59   ` Jeremy Sowden

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=20190614085346.GN17989@gauss3.secunet.de \
    --to=steffen.klassert@secunet.com \
    --cc=92siuyang@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®