Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] vrf: pull the full IPv4 header on xmit
@ 2026-11-30 20:44 Xiang Mei
  2026-11-30 20:46 ` Xiang Mei
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Xiang Mei @ 2026-11-30 20:44 UTC (permalink / raw)
  To: David Ahern, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, stable, co+bfd69dd4e073f1e9, Xiang Mei

A frame sent on a VRF device with AF_PACKET carries an IPv4 header
written by the user.  vrf_process_v4_outbound() makes sure the first 20
bytes are there, but never checks that the packet is as long as the
header says it is (ihl * 4).

With a transport-mode ESP SA, xfrm4_transport_output() strips ihl * 4
bytes from the front of the packet.  If the packet is shorter than that,
skb->len wraps around to ~4G and ESP walks off the end of the
scatterlist.  An unprivileged user can do this inside a user + net
namespace:

  Oops: general protection fault, probably for non-canonical address ...
  KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
  RIP: 0010:scatterwalk_ffwd (crypto/scatterwalk.c:191)
  Call Trace:
   crypto_authenc_encrypt (crypto/authenc.c:201)
   crypto_aead_encrypt (crypto/aead.c:91)
   esp_output_tail (net/ipv4/esp4.c:600)
   esp_output (net/ipv4/esp4.c:675)
   xfrm_output_resume (net/xfrm/xfrm_output.c:562 net/xfrm/xfrm_output.c:597)
   xfrm_output (net/xfrm/xfrm_output.c:656 net/xfrm/xfrm_output.c:837)
   __xfrm4_output (net/ipv4/xfrm4_output.c:28)
   xfrm4_output (./include/linux/netfilter.h:314 net/ipv4/xfrm4_output.c:33)
   vrf_ip_local_out (./include/net/dst.h:471 drivers/net/vrf.c:485)
   vrf_xmit (drivers/net/vrf.c:537 ... drivers/net/vrf.c:568)
   dev_hard_start_xmit (net/core/dev.c:4084)
   __dev_queue_xmit (net/core/dev.c:5101)
   packet_xmit (net/packet/af_packet.c:274)
   packet_sendmsg (net/packet/af_packet.c:3209)
   __sock_sendmsg (net/socket.c:818)
   __sys_sendto (net/socket.c:2283)
   __x64_sys_sendto (net/socket.c:2286)
   do_syscall_64 (arch/x86/entry/syscall_64.c:89)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
  Kernel panic - not syncing: Fatal exception in interrupt

Drop the frame if ihl < 5 or not all ihl * 4 header bytes are present,
the same checks ip_rcv_core() does for received packets.

Cc: stable@vger.kernel.org
Fixes: 193125dbd8eb ("net: Introduce VRF device driver")
Reported-by: co+bfd69dd4e073f1e9@bugs.sh
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
 drivers/net/vrf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 79d433f49f80..d90b7e8fb158 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -499,6 +499,10 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
 	if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
 		goto err;
 
+	if (ip_hdr(skb)->ihl < 5 ||
+	    !pskb_may_pull(skb, ETH_HLEN + ip_hdr(skb)->ihl * 4))
+		goto err;
+
 	ip4h = ip_hdr(skb);
 
 	memset(&fl4, 0, sizeof(fl4));
-- 
2.43.0


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

* Re: [PATCH net v2] vrf: pull the full IPv4 header on xmit
  2026-11-30 20:44 [PATCH net v2] vrf: pull the full IPv4 header on xmit Xiang Mei
@ 2026-11-30 20:46 ` Xiang Mei
  2026-12-01 17:21 ` Nicolas Dichtel
  2026-12-01 20:45 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: Xiang Mei @ 2026-11-30 20:46 UTC (permalink / raw)
  To: David Ahern, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, nicolas.dichtel
  Cc: netdev, linux-kernel, stable, co+bfd69dd4e073f1e9

CC: Nicolas

Thanks for your review at
https://lore.kernel.org/netdev/32381389-f6ae-4a1e-b3ed-bcc445430a5a@6wind.com/
V2 is attached to this thread with your suggestions.

Xiang

On Mon, Nov 30, 2026 at 1:44 PM Xiang Mei <xmei5@asu.edu> wrote:
>
> A frame sent on a VRF device with AF_PACKET carries an IPv4 header
> written by the user.  vrf_process_v4_outbound() makes sure the first 20
> bytes are there, but never checks that the packet is as long as the
> header says it is (ihl * 4).
>
> With a transport-mode ESP SA, xfrm4_transport_output() strips ihl * 4
> bytes from the front of the packet.  If the packet is shorter than that,
> skb->len wraps around to ~4G and ESP walks off the end of the
> scatterlist.  An unprivileged user can do this inside a user + net
> namespace:
>
>   Oops: general protection fault, probably for non-canonical address ...
>   KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
>   RIP: 0010:scatterwalk_ffwd (crypto/scatterwalk.c:191)
>   Call Trace:
>    crypto_authenc_encrypt (crypto/authenc.c:201)
>    crypto_aead_encrypt (crypto/aead.c:91)
>    esp_output_tail (net/ipv4/esp4.c:600)
>    esp_output (net/ipv4/esp4.c:675)
>    xfrm_output_resume (net/xfrm/xfrm_output.c:562 net/xfrm/xfrm_output.c:597)
>    xfrm_output (net/xfrm/xfrm_output.c:656 net/xfrm/xfrm_output.c:837)
>    __xfrm4_output (net/ipv4/xfrm4_output.c:28)
>    xfrm4_output (./include/linux/netfilter.h:314 net/ipv4/xfrm4_output.c:33)
>    vrf_ip_local_out (./include/net/dst.h:471 drivers/net/vrf.c:485)
>    vrf_xmit (drivers/net/vrf.c:537 ... drivers/net/vrf.c:568)
>    dev_hard_start_xmit (net/core/dev.c:4084)
>    __dev_queue_xmit (net/core/dev.c:5101)
>    packet_xmit (net/packet/af_packet.c:274)
>    packet_sendmsg (net/packet/af_packet.c:3209)
>    __sock_sendmsg (net/socket.c:818)
>    __sys_sendto (net/socket.c:2283)
>    __x64_sys_sendto (net/socket.c:2286)
>    do_syscall_64 (arch/x86/entry/syscall_64.c:89)
>    entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
>   Kernel panic - not syncing: Fatal exception in interrupt
>
> Drop the frame if ihl < 5 or not all ihl * 4 header bytes are present,
> the same checks ip_rcv_core() does for received packets.
>
> Cc: stable@vger.kernel.org
> Fixes: 193125dbd8eb ("net: Introduce VRF device driver")
> Reported-by: co+bfd69dd4e073f1e9@bugs.sh
> Signed-off-by: Xiang Mei <xmei5@asu.edu>
> ---
>  drivers/net/vrf.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> index 79d433f49f80..d90b7e8fb158 100644
> --- a/drivers/net/vrf.c
> +++ b/drivers/net/vrf.c
> @@ -499,6 +499,10 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
>         if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
>                 goto err;
>
> +       if (ip_hdr(skb)->ihl < 5 ||
> +           !pskb_may_pull(skb, ETH_HLEN + ip_hdr(skb)->ihl * 4))
> +               goto err;
> +
>         ip4h = ip_hdr(skb);
>
>         memset(&fl4, 0, sizeof(fl4));
> --
> 2.43.0
>

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

* Re: [PATCH net v2] vrf: pull the full IPv4 header on xmit
  2026-11-30 20:44 [PATCH net v2] vrf: pull the full IPv4 header on xmit Xiang Mei
  2026-11-30 20:46 ` Xiang Mei
@ 2026-12-01 17:21 ` Nicolas Dichtel
  2026-12-01 20:45 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2026-12-01 17:21 UTC (permalink / raw)
  To: netdev

Le 30/11/2026 à 21:44, Xiang Mei a écrit :> A frame sent on a VRF device with
AF_PACKET carries an IPv4 header
> written by the user.  vrf_process_v4_outbound() makes sure the first 20
> bytes are there, but never checks that the packet is as long as the
> header says it is (ihl * 4).
> 
> With a transport-mode ESP SA, xfrm4_transport_output() strips ihl * 4
> bytes from the front of the packet.  If the packet is shorter than that,
> skb->len wraps around to ~4G and ESP walks off the end of the
> scatterlist.  An unprivileged user can do this inside a user + net
> namespace:
> 
>   Oops: general protection fault, probably for non-canonical address ...
>   KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
>   RIP: 0010:scatterwalk_ffwd (crypto/scatterwalk.c:191)
>   Call Trace:
>    crypto_authenc_encrypt (crypto/authenc.c:201)
>    crypto_aead_encrypt (crypto/aead.c:91)
>    esp_output_tail (net/ipv4/esp4.c:600)
>    esp_output (net/ipv4/esp4.c:675)
>    xfrm_output_resume (net/xfrm/xfrm_output.c:562 net/xfrm/xfrm_output.c:597)
>    xfrm_output (net/xfrm/xfrm_output.c:656 net/xfrm/xfrm_output.c:837)
>    __xfrm4_output (net/ipv4/xfrm4_output.c:28)
>    xfrm4_output (./include/linux/netfilter.h:314 net/ipv4/xfrm4_output.c:33)
>    vrf_ip_local_out (./include/net/dst.h:471 drivers/net/vrf.c:485)
>    vrf_xmit (drivers/net/vrf.c:537 ... drivers/net/vrf.c:568)
>    dev_hard_start_xmit (net/core/dev.c:4084)
>    __dev_queue_xmit (net/core/dev.c:5101)
>    packet_xmit (net/packet/af_packet.c:274)
>    packet_sendmsg (net/packet/af_packet.c:3209)
>    __sock_sendmsg (net/socket.c:818)
>    __sys_sendto (net/socket.c:2283)
>    __x64_sys_sendto (net/socket.c:2286)
>    do_syscall_64 (arch/x86/entry/syscall_64.c:89)
>    entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
>   Kernel panic - not syncing: Fatal exception in interrupt
> 
> Drop the frame if ihl < 5 or not all ihl * 4 header bytes are present,
> the same checks ip_rcv_core() does for received packets.
Nit: ip_rcv_core() also checks version != 4

> 
> Cc: stable@vger.kernel.org
> Fixes: 193125dbd8eb ("net: Introduce VRF device driver")
> Reported-by: co+bfd69dd4e073f1e9@bugs.sh
I did not found the report on netdev. checkpatch complains that Reported-by:
should be immediately followed by a Closes: or Link: tag pointing to the report.

The commit log should state how the issue was discovered, please see:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/maintainer-netdev.rst#n286

> Signed-off-by: Xiang Mei <xmei5@asu.edu>
Please also add a changelog below the "---" line, with a link to the
previous postings:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/maintainer-netdev.rst#n235

> ---
>  drivers/net/vrf.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> index 79d433f49f80..d90b7e8fb158 100644
> --- a/drivers/net/vrf.c
> +++ b/drivers/net/vrf.c
> @@ -499,6 +499,10 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
>  	if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
>  		goto err;
>  
> +	if (ip_hdr(skb)->ihl < 5 ||
> +	    !pskb_may_pull(skb, ETH_HLEN + ip_hdr(skb)->ihl * 4))
> +		goto err;
> +

nit: one if would do the job:
if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)) ||
    ip_hdr(skb)->ihl < 5 ||
    !pskb_may_pull(skb, ETH_HLEN + ip_hdr(skb)->ihl * 4))
        goto err;


>  	ip4h = ip_hdr(skb);
>  
>  	memset(&fl4, 0, sizeof(fl4));


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

* Re: [PATCH net v2] vrf: pull the full IPv4 header on xmit
  2026-11-30 20:44 [PATCH net v2] vrf: pull the full IPv4 header on xmit Xiang Mei
  2026-11-30 20:46 ` Xiang Mei
  2026-12-01 17:21 ` Nicolas Dichtel
@ 2026-12-01 20:45 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:45 UTC (permalink / raw)
  To: xmei5
  Cc: dsahern, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, stable, co+bfd69dd4e073f1e9

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete because the new IHL length check assumes
  the IPv4 header always starts ETH_HLEN bytes into the frame.

--

vrf: pull the full IPv4 header on xmit

This patch adds a check to vrf_process_v4_outbound(). The check drops IPv4
frames sent on a VRF device if ihl < 5, or if fewer than ihl * 4 header
bytes are present. The goal is to stop an skb->len underflow in
xfrm4_transport_output() that makes ESP walk off the end of the
scatterlist.

> diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
> index 79d433f49f803..d90b7e8fb158f 100644
> --- a/drivers/net/vrf.c
> +++ b/drivers/net/vrf.c
> @@ -499,6 +499,10 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
>  	if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
>  		goto err;
>  
> +	if (ip_hdr(skb)->ihl < 5 ||
> +	    !pskb_may_pull(skb, ETH_HLEN + ip_hdr(skb)->ihl * 4))
> +		goto err;
> +

[Severity: High]

Is ETH_HLEN the right starting point for this length? ip_hdr() is read at
skb->network_header, but the pull length here is counted from skb->data
with a fixed ETH_HLEN. Later in the same function, the actual network
offset is stripped:

	/* strip the ethernet header added for pass through VRF device */
	__skb_pull(skb, skb_network_offset(skb));

Can vrf_xmit() get frames where skb_network_offset() is larger than
ETH_HLEN? This path looks like it can produce one:

1. An NBMA ipgre device (no remote, so header_ops is &ipgre_header_ops)
   has hard_header_len = tunnel->hlen + sizeof(*iph), which is at least
   24 bytes.

2. packet_snd() on a SOCK_RAW socket bound to that device sets
   reserve = hard_header_len. The network header therefore starts 24 or
   more bytes into the frame.

3. A tc clsact egress "mirred egress redirect dev vrf0" on the GRE device
   goes through tcf_mirred_to_dev(). The VRF device uses ether_setup(), so
   expects_nh is false. at_nh is also false, so the skb is passed on
   unchanged:

	expects_nh = want_ingress || !m_mac_header_xmit;
	at_nh = skb->data == skb_network_header(skb);
	if (at_nh != expects_nh) {

The GRE ingress side looks similar. __ipgre_rcv() calls
skb_pop_mac_header(), and mirred then pushes the outer IP + GRE mac_len
before the skb reaches the VRF device.

Take a network offset of 24, ihl = 15 and a frame length of 74 to 83:

  ETH_HLEN + ihl * 4 = 14 + 60 = 74, so the new check passes
  __skb_pull(skb, 24) leaves skb->len at 50..59, which is less than 60

If the route lookup returns a transport-mode ESP xfrm dst,
xfrm4_transport_output() runs this without checking the length itself:

	__skb_pull(skb, ihl);

Wouldn't skb->len then wrap the same way as in the oops in the commit
message?

If the skb is non-linear, could that __skb_pull() hit the
skb->len < skb->data_len BUG() instead?

The existing 20-byte check just above makes the same ETH_HLEN assumption.
Would checks relative to the network header be more robust, for example:

	if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
		goto err;

	if (ip_hdr(skb)->ihl < 5 ||
	    !pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4))
		goto err;

Every step above (GRE link, tc clsact/mirred, VRF, xfrm SA and policy,
AF_PACKET) can be set up inside an unprivileged user + net namespace. That
is the same privilege the reproducer in the commit message needs.

>  	ip4h = ip_hdr(skb);
>  
>  	memset(&fl4, 0, sizeof(fl4));

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130204412.632027-1-xmei5%40asu.edu

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

end of thread, other threads:[~2026-12-01 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 20:44 [PATCH net v2] vrf: pull the full IPv4 header on xmit Xiang Mei
2026-11-30 20:46 ` Xiang Mei
2026-12-01 17:21 ` Nicolas Dichtel
2026-12-01 20:45 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox