netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] af_key: Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
@ 2025-07-03  9:16 Haoxiang Li
  2025-07-04  6:12 ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-07-03  9:16 UTC (permalink / raw)
  To: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, horms
  Cc: netdev, linux-kernel, Haoxiang Li

Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
to prevent potential errors.

Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 net/key/af_key.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/key/af_key.c b/net/key/af_key.c
index efc2a91f4c48..e7318cea1f3a 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3335,6 +3335,9 @@ 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)
+			goto out;
+
 		*dir = security_xfrm_policy_alloc(&xp->security, uctx, GFP_ATOMIC);
 		kfree(uctx);
 
-- 
2.25.1


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

* Re: [PATCH] af_key: Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
  2025-07-03  9:16 [PATCH] af_key: Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx() Haoxiang Li
@ 2025-07-04  6:12 ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2025-07-04  6:12 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: herbert, davem, edumazet, kuba, pabeni, horms, netdev,
	linux-kernel

On Thu, Jul 03, 2025 at 05:16:46PM +0800, Haoxiang Li wrote:
> Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx()
> to prevent potential errors.
> 
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
>  net/key/af_key.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/key/af_key.c b/net/key/af_key.c
> index efc2a91f4c48..e7318cea1f3a 100644
> --- a/net/key/af_key.c
> +++ b/net/key/af_key.c
> @@ -3335,6 +3335,9 @@ 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)
> +			goto out;

pfkey_sadb2xfrm_user_sec_ctx() does this check already.

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

end of thread, other threads:[~2025-07-04  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03  9:16 [PATCH] af_key: Add check for the return value of pfkey_sadb2xfrm_user_sec_ctx() Haoxiang Li
2025-07-04  6:12 ` Steffen Klassert

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).