Netdev List
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Qihang <q.h.hack.winter@gmail.com>
Cc: netdev@vger.kernel.org, steffen.klassert@secunet.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, stable@vger.kernel.org
Subject: Re: [PATCH net v3] xfrm: interface: validate the IP header on xmit
Date: Wed, 23 Sep 2026 13:38:19 +1000	[thread overview]
Message-ID: <arNJq55gryoQp64j@gondor.apana.org.au> (raw)
In-Reply-To: <20260923032456.45814-1-q.h.hack.winter@gmail.com>

On Wed, Sep 23, 2026 at 11:24:56AM +0800, Qihang wrote:
>
> diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c
> index 688306b..5cc906a 100644
> --- a/net/xfrm/xfrm_interface_core.c
> +++ b/net/xfrm/xfrm_interface_core.c
> @@ -531,6 +531,9 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
>  
>  	memset(&fl, 0, sizeof(fl));
>  
> +	if (!pskb_inet_may_pull(skb))
> +		goto tx_err;
> +
>  	switch (skb->protocol) {
>  	case htons(ETH_P_IPV6):
>  		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
> @@ -548,6 +551,9 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
>  		}
>  		break;
>  	case htons(ETH_P_IP):
> +		if (ip_hdr(skb)->ihl < 5 ||
> +		    !pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4))
> +			goto tx_err;

Thank you for the quick fix!

I haven't looked at this deeply but should we verify the IPv6 case
as well?

Also we should try to do the same verification that a packet would
normally get upon entry into the IP stack.  So that means checking
iph->version as well.  The standard entry point is ip_rcv_core and
the same checks should apply whether you went through there or one
of these non-standard entry points.

Perhaps we should abstract out the verifications from ip_rcv_core
so that it can be done by all these entry points in a uniform way.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2026-09-23  3:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  3:24 [PATCH net v3] xfrm: interface: validate the IP header on xmit Qihang
2026-09-23  3:38 ` Herbert Xu [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=arNJq55gryoQp64j@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=q.h.hack.winter@gmail.com \
    --cc=stable@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