All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
To: Wentao Liang <vulab@iscas.ac.cn>
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] net: af_key: Add error check in set_sadb_address()
Date: Mon, 26 May 2025 10:58:39 +0200	[thread overview]
Message-ID: <aDQtPxmS3leVRJew@mev-dev.igk.intel.com> (raw)
In-Reply-To: <20250525155350.1948-1-vulab@iscas.ac.cn>

On Sun, May 25, 2025 at 11:53:50PM +0800, Wentao Liang wrote:
> The function set_sadb_address() calls the function
> pfkey_sockaddr_fill(), but does not check its return value.
> A proper implementation can be found in set_sadb_kmaddress().
> 
> Add an error check for set_sadb_address(), return error code
> if the function fails.
> 
> Fixes: e5b56652c11b ("key: Share common code path to fill sockaddr{}.")
> Cc: stable@vger.kernel.org # v2.6
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  net/key/af_key.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/net/key/af_key.c b/net/key/af_key.c
> index c56bb4f451e6..537c9604e356 100644
> --- a/net/key/af_key.c
> +++ b/net/key/af_key.c
> @@ -3474,15 +3474,17 @@ static int set_sadb_address(struct sk_buff *skb, int sasize, int type,
>  	switch (type) {
>  	case SADB_EXT_ADDRESS_SRC:
>  		addr->sadb_address_prefixlen = sel->prefixlen_s;
> -		pfkey_sockaddr_fill(&sel->saddr, 0,
> -				    (struct sockaddr *)(addr + 1),
> -				    sel->family);
> +		if (!pfkey_sockaddr_fill(&sel->saddr, 0,
> +					 (struct sockaddr *)(addr + 1),
> +					 sel->family))
> +			return -EINVAL;
>  		break;
>  	case SADB_EXT_ADDRESS_DST:
>  		addr->sadb_address_prefixlen = sel->prefixlen_d;
> -		pfkey_sockaddr_fill(&sel->daddr, 0,
> -				    (struct sockaddr *)(addr + 1),
> -				    sel->family);
> +		if (!pfkey_sockaddr_fill(&sel->daddr, 0,
> +					 (struct sockaddr *)(addr + 1),
> +					 sel->family))
> +			return -EINVAL;
>  		break;
>  	default:
>  		return -EINVAL;

There are few other calls to pfkey_sockaddr_fill() without checking, but
family is already checked in such case, so it is fine.

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

I am not sure if it should be a fix. If family is set there is no
problem. Probably it is set in all cases. Maybe you should target it to
net-next, but as I said, I am not sure.

Thanks

> -- 
> 2.42.0.windows.2

  reply	other threads:[~2025-05-26  8:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-25 15:53 [PATCH] net: af_key: Add error check in set_sadb_address() Wentao Liang
2025-05-26  8:58 ` Michal Swiatkowski [this message]
2025-05-29  1:53 ` Jakub Kicinski

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=aDQtPxmS3leVRJew@mev-dev.igk.intel.com \
    --to=michal.swiatkowski@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.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=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=vulab@iscas.ac.cn \
    /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 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.