netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Junrui Luo <moonafterrain@outlook.com>,
	 "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	 Simon Horman <horms@kernel.org>,
	 Herbert Xu <herbert@gondor.apana.org.au>
Cc: netdev@vger.kernel.org,  linux-kernel@vger.kernel.org,
	 Yuhao Jiang <danisjiang@gmail.com>,
	 Junrui Luo <moonafterrain@outlook.com>
Subject: Re: [PATCH net] skb_checksum_help: fix out-of-bounds access
Date: Wed, 10 Dec 2025 08:55:17 -0500	[thread overview]
Message-ID: <willemdebruijn.kernel.3905bafb42307@gmail.com> (raw)
In-Reply-To: <MEYPR01MB7886119A494C646719A3F77CAFA0A@MEYPR01MB7886.ausprd01.prod.outlook.com>

Junrui Luo wrote:
> The skb_checksum_help() function does not validate negative offset
> values returned by skb_checksum_start_offset(). This can occur when
> __skb_pull() is called on a packet, increasing the headroom while
> leaving csum_start unchanged.

Do you have a specific example where this happens?
 
> A negative offset causes out-of-bounds memory access:
> - skb_checksum() reads before skb->data when computing the checksum
> - skb_checksum_help() writes before skb->data

I don't think this is true out-of-bounds as long as the data access
starts greater than or equal to skb->head, which it will.

There are known cases where such negative skb offsets are
intentional. I don't think this is one of them, but needs a careful
analysis.

The use in skb_checksum does seem to indicate that this is not
intentional indeed. Checksumming a packet where the L4 header would
lie outside the data.

    csum = skb_checksum(skb, offset, skb->len - offset, 0);

> Add validation to detect and reject negative offsets.
> 
> Reported-by: Yuhao Jiang <danisjiang@gmail.com>
> Reported-by: Junrui Luo <moonafterrain@outlook.com>
> Fixes: 663ead3bb8d5 ("[NET]: Use csum_start offset instead of skb_transport_header")
> Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
> ---
>  net/core/dev.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 9094c0fb8c68..30161b9240a2 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -3574,6 +3574,11 @@ int skb_checksum_help(struct sk_buff *skb)
>  
>  	offset = skb_checksum_start_offset(skb);
>  	ret = -EINVAL;
> +	if (unlikely(offset < 0)) {
> +		DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false);
> +		WARN_ONCE(true, "offset (%d) < 0\n", offset);
> +		goto out;
> +	}
>  	if (unlikely(offset >= skb_headlen(skb))) {
>  		DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false);
>  		WARN_ONCE(true, "offset (%d) >= skb_headlen() (%u)\n",
> 
> ---
> base-commit: cfd4039213e7b5a828c5b78e1b5235cac91af53d
> change-id: 20251210-fixes-ef9fa1c91916
> 
> Best regards,
> -- 
> Junrui Luo <moonafterrain@outlook.com>
> 



  reply	other threads:[~2025-12-10 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  2:47 [PATCH net] skb_checksum_help: fix out-of-bounds access Junrui Luo
2025-12-10 13:55 ` Willem de Bruijn [this message]
2025-12-12  3:30   ` Junrui Luo
2025-12-12  8:25     ` Eric Dumazet

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=willemdebruijn.kernel.3905bafb42307@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=danisjiang@gmail.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=moonafterrain@outlook.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).