mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Haoxiang Li <haoxiang_li2024@163.com>,
	steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] af_key: Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
Date: Thu, 10 Jul 2025 11:29:12 +0200	[thread overview]
Message-ID: <fe811639-7775-4666-b678-58f8a47b65ed@redhat.com> (raw)
In-Reply-To: <20250707160503.2834390-1-haoxiang_li2024@163.com>

On 7/7/25 6:05 PM, Haoxiang Li wrote:
> Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
> in pfkey_compile_policy(), and set proper error flag.
> 
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
> Changes in v2:
> - Set error flag '*dir' properly.
> - Hi, Steffen! I know that inside pfkey_sadb2xfrm_user_sec_ctx(), null
> value check has been done. This patch does the null value check after
> pfkey_sadb2xfrm_user_sec_ctx() being called in pfkey_compile_policy().
> Also, set proper error flag if pfkey_sadb2xfrm_user_sec_ctx() returns
> null. This patch code is similar to [1]. Thanks, Steffen!
> 
> [1]https://github.com/torvalds/linux/blob/master/net/key/af_key.c#L2404
> ---
>  net/key/af_key.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/key/af_key.c b/net/key/af_key.c
> index efc2a91f4c48..9cd14a31a427 100644
> --- a/net/key/af_key.c
> +++ b/net/key/af_key.c
> @@ -3335,6 +3335,11 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
>  		if ((*dir = verify_sec_ctx_len(p)))
>  			goto out;
>  		uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx, GFP_ATOMIC);
> +		if (!uctx) {
> +			*dir = -ENOMEM;
> +			goto out;
> +		}
> +
>  		*dir = security_xfrm_policy_alloc(&xp->security, uctx, GFP_ATOMIC);

AFAICS security_xfrm_policy_alloc() handle safely 'uctx' arguments ...

>  		kfree(uctx);

... and kfree, too.

This patch looks not needed.

/P


      reply	other threads:[~2025-07-10  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 16:05 Haoxiang Li
2025-07-10  9:29 ` Paolo Abeni [this message]

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=fe811639-7775-4666-b678-58f8a47b65ed@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=haoxiang_li2024@163.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /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®