Skip to contentSkip to conversation

fou/gue: Fix skb memleak with inner protocol 0.

PATCH Superseded Kuniyuki Iwashima 3 participants 9 messages Jan 12 – Jan 15

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fou/gue: Fix skb memleak with inner protocol 0.

syzbot reported memleak for a GUE packet with its inner protocol number 0.

Patch 1 fixes the issue, and patch 2 fixes the same issue in FOU.

Kuniyuki Iwashima (2):
gue: Fix skb memleak with inner IP protocol 0.
fou: Don't allow 0 for FOU_ATTR_IPPROTO.

 net/ipv4/fou_core.c | 3 +++
 net/ipv4/fou_nl.c   | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#1 lore raw

PATCH 1/2 gue: Fix skb memleak with inner IP protocol 0.

syzbot reported skb memleak below. [0]

The repro generated a GUE packet with its inner protocol 0.

gue_udp_recv() returns -guehdr->proto_ctype for "resubmit" in ip_protocol_deliver_rcu(), but this only works with non-zero protocol number.

Let's drop such packets.

Note that 0 is a valid number (IPv6 Hop-by-Hop Option).

I think it is not practical to encap HOPOPT in GUE, so once someone starts to complain, we could pass down a resubmit flag pointer to distinguish two zeros from the upper layer:

* no error
* resubmit HOPOPT

[0]

BUG: memory leak
unreferenced object 0xffff888109695a00 (size 240):
  comm "syz.0.17", pid 6088, jiffies 4294943096
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 40 c2 10 81 88 ff ff 00 00 00 00 00 00 00 00  .@..............
  backtrace (crc a84b336f):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4958 [inline]
    slab_alloc_node mm/slub.c:5263 [inline]
    kmem_cache_alloc_noprof+0x3b4/0x590 mm/slub.c:5270
    __build_skb+0x23/0x60 net/core/skbuff.c:474
    build_skb+0x20/0x190 net/core/skbuff.c:490
    __tun_build_skb drivers/net/tun.c:1541 [inline]
    tun_build_skb+0x4a1/0xa40 drivers/net/tun.c:1636
    tun_get_user+0xc12/0x2030 drivers/net/tun.c:1770
    tun_chr_write_iter+0x71/0x120 drivers/net/tun.c:1999
    new_sync_write fs/read_write.c:593 [inline]
    vfs_write+0x45d/0x710 fs/read_write.c:686
    ksys_write+0xa7/0x170 fs/read_write.c:738
    do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
    do_syscall_64+0xa4/0xf80 arch/x86/entry/syscall_64.c:94
    entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fixes 37dd0247797b1 ("gue: Receive side for Generic UDP Encapsulation")
Reported-by [email protected]
---
 net/ipv4/fou_core.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv4/fou_core.c +3 -0
index 3970b6b7ace53..ab8f309f8925d 100644
@@ -215,6 +215,9 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
 		return gue_control_message(skb, guehdr);
 
 	proto_ctype = guehdr->proto_ctype;
+	if (unlikely(!proto_ctype))
+		goto drop;
+
 	__skb_pull(skb, sizeof(struct udphdr) + hdrlen);
 	skb_reset_transport_header(skb);
 
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#3 lore raw

PATCH 2/2 fou: Don't allow 0 for FOU_ATTR_IPPROTO.

In reply to Kuniyuki Iwashima

fou_udp_recv() has the same problem mentioned in the previous patch.

If FOU_ATTR_IPPROTO is set to 0, skb is not freed by fou_udp_recv() nor "resubmit"-ted in ip_protocol_deliver_rcu().

Let's forbid 0 for FOU_ATTR_IPPROTO.

Fixes 23461551c0062 ("fou: Support for foo-over-udp RX path")
---
 net/ipv4/fou_nl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fou_nl.c +1 -1
index 7a99639204b16..0dec9da1bff46 100644
@@ -15,7 +15,7 @@
 const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
 	[FOU_ATTR_PORT] = { .type = NLA_BE16, },
 	[FOU_ATTR_AF] = { .type = NLA_U8, },
-	[FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
+	[FOU_ATTR_IPPROTO] = { .type = NLA_U8, .min = 1 },
 	[FOU_ATTR_TYPE] = { .type = NLA_U8, },
 	[FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
 	[FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH v1 net 2/2] fou: Don't allow 0 for FOU_ATTR_IPPROTO.

Quoted 11 lines · Kuniyuki Iwashima

fou_udp_recv() has the same problem mentioned in the previous patch.

If FOU_ATTR_IPPROTO is set to 0, skb is not freed by fou_udp_recv() nor "resubmit"-ted in ip_protocol_deliver_rcu().

Let's forbid 0 for FOU_ATTR_IPPROTO.

Fixes 23461551c0062 ("fou: Support for foo-over-udp RX path")
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 net 1/2] gue: Fix skb memleak with inner IP protocol 0.

In reply to Kuniyuki Iwashima
Quoted 11 lines · Kuniyuki Iwashima

syzbot reported skb memleak below. [0]

The repro generated a GUE packet with its inner protocol 0.

gue_udp_recv() returns -guehdr->proto_ctype for "resubmit" in ip_protocol_deliver_rcu(), but this only works with non-zero protocol number.

Let's drop such packets.

Quoted 8 lines

Note that 0 is a valid number (IPv6 Hop-by-Hop Option).

I think it is not practical to encap HOPOPT in GUE, so once someone starts to complain, we could pass down a resubmit flag pointer to distinguish two zeros from the upper layer:

* no error
* resubmit HOPOPT

maintainer
#5 lore raw

Re: [PATCH v1 net 2/2] fou: Don't allow 0 for FOU_ATTR_IPPROTO.

In reply to Kuniyuki Iwashima
Quoted 19 lines · On Mon, 12 Jan 2026 20:06:36 +0000 Kuniyuki Iwashima wrote:

fou_udp_recv() has the same problem mentioned in the previous patch.

If FOU_ATTR_IPPROTO is set to 0, skb is not freed by fou_udp_recv() nor "resubmit"-ted in ip_protocol_deliver_rcu().

Let's forbid 0 for FOU_ATTR_IPPROTO.

Fixes 23461551c0062 ("fou: Support for foo-over-udp RX path")
---
 net/ipv4/fou_nl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fou_nl.c +0 -0
index 7a99639204b16..0dec9da1bff46 100644

net/ipv4/fou_nl.c line 21

Quoted 8 lines
net/ipv4/fou_nl.c +1 -1
@@ -15,7 +15,7 @@
 const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
 	[FOU_ATTR_PORT] = { .type = NLA_BE16, },
 	[FOU_ATTR_AF] = { .type = NLA_U8, },
-	[FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
+	[FOU_ATTR_IPPROTO] = { .type = NLA_U8, .min = 1 },
 	[FOU_ATTR_TYPE] = { .type = NLA_U8, },
 	[FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
 	[FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },

This code is generated, please use :

Documentation/netlink/specs/fou.yaml +2 -0
index 8e7974ec453f..331f1b342b3a 100644
@@ -39,6 +39,8 @@ kernel-policy: global
       -
         name: ipproto
         type: u8
+        checks:
+          min: 1
       -
         name: type
         type: u8
net/ipv4/fou_nl.c +1 -1
index 7a99639204b1..309d5ba983d0 100644
@@ -15,7 +15,7 @@
 const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
 	[FOU_ATTR_PORT] = { .type = NLA_BE16, },
 	[FOU_ATTR_AF] = { .type = NLA_U8, },
-	[FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
+	[FOU_ATTR_IPPROTO] = NLA_POLICY_MIN(NLA_U8, 1),
 	[FOU_ATTR_TYPE] = { .type = NLA_U8, },
 	[FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
 	[FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },
#6 lore raw

Re: [PATCH v1 net 2/2] fou: Don't allow 0 for FOU_ATTR_IPPROTO.

Quoted 50 lines · Jakub Kicinski
Quoted 19 lines · On Mon, 12 Jan 2026 20:06:36 +0000 Kuniyuki Iwashima wrote:

fou_udp_recv() has the same problem mentioned in the previous patch.

If FOU_ATTR_IPPROTO is set to 0, skb is not freed by fou_udp_recv() nor "resubmit"-ted in ip_protocol_deliver_rcu().

Let's forbid 0 for FOU_ATTR_IPPROTO.

Fixes 23461551c0062 ("fou: Support for foo-over-udp RX path")
---
 net/ipv4/fou_nl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fou_nl.c +0 -0
index 7a99639204b16..0dec9da1bff46 100644

net/ipv4/fou_nl.c line 21

Quoted 8 lines
net/ipv4/fou_nl.c +1 -1
@@ -15,7 +15,7 @@
 const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
      [FOU_ATTR_PORT] = { .type = NLA_BE16, },
      [FOU_ATTR_AF] = { .type = NLA_U8, },
-     [FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
+     [FOU_ATTR_IPPROTO] = { .type = NLA_U8, .min = 1 },
      [FOU_ATTR_TYPE] = { .type = NLA_U8, },
      [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
      [FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },

This code is generated, please use :

Documentation/netlink/specs/fou.yaml +2 -0
index 8e7974ec453f..331f1b342b3a 100644
@@ -39,6 +39,8 @@ kernel-policy: global
       -
         name: ipproto
         type: u8
+        checks:
+          min: 1
       -
         name: type
         type: u8
net/ipv4/fou_nl.c +0 -0
index 7a99639204b1..309d5ba983d0 100644

net/ipv4/fou_nl.c line 21

Quoted 8 lines
net/ipv4/fou_nl.c +1 -1
@@ -15,7 +15,7 @@
 const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
        [FOU_ATTR_PORT] = { .type = NLA_BE16, },
        [FOU_ATTR_AF] = { .type = NLA_U8, },
-       [FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
+       [FOU_ATTR_IPPROTO] = NLA_POLICY_MIN(NLA_U8, 1),
        [FOU_ATTR_TYPE] = { .type = NLA_U8, },
        [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
        [FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },

Oh thanks, I missed it's auto-generated.

Btw I needed the change below to generate the diff above by "./tools/net/ynl/ynl-regen.sh -f". Maybe depending on

tools/net/ynl/ynl-regen.sh +3 -3
index 81b4ecd891006..fda5fe24cfd47 100755
@@ -29,9 +29,9 @@ for f in $files; do
  continue
     fi
 
-    echo -e "\tGEN ${params[2]}\t$f"
-    $TOOL --cmp-out --mode ${params[2]} --${params[3]} \
-   --spec $KDIR/${params[0]} $args -o $f
+    echo -e "\tGEN ${params[5]}\t$f"
+    $TOOL --cmp-out --mode ${params[4]} --${params[5]} \
+   --spec $KDIR/${params[1]} $args -o $f
 done
 
 popd >>/dev/null

fwiw, $params were like

3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel source
--
3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel header

maintainer
#7 lore raw

Re: [PATCH v1 net 2/2] fou: Don't allow 0 for FOU_ATTR_IPPROTO.

Quoted 23 lines · On Tue, 13 Jan 2026 23:15:42 -0800 Kuniyuki Iwashima wrote:

Btw I needed the change below to generate the diff above by "./tools/net/ynl/ynl-regen.sh -f". Maybe depending on

tools/net/ynl/ynl-regen.sh +3 -3
index 81b4ecd891006..fda5fe24cfd47 100755
@@ -29,9 +29,9 @@ for f in $files; do
  continue
     fi
 
-    echo -e "\tGEN ${params[2]}\t$f"
-    $TOOL --cmp-out --mode ${params[2]} --${params[3]} \
-   --spec $KDIR/${params[0]} $args -o $f
+    echo -e "\tGEN ${params[5]}\t$f"
+    $TOOL --cmp-out --mode ${params[4]} --${params[5]} \
+   --spec $KDIR/${params[1]} $args -o $f
 done
 
 popd >>/dev/null
Quoted 7 lines

fwiw, $params were like

3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel source
--
3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel header

Hm, I guess you have grep.lineNumber enabled in your git config? Could you see if tossing --no-line-number into the git grep in this script fixes it for you and if yes send a patch?

#8 lore raw

Re: [PATCH v1 net 2/2] fou: Don't allow 0 for FOU_ATTR_IPPROTO.

Quoted 27 lines · Jakub Kicinski
Quoted 25 lines · On Tue, 13 Jan 2026 23:15:42 -0800 Kuniyuki Iwashima wrote:

Btw I needed the change below to generate the diff above by "./tools/net/ynl/ynl-regen.sh -f". Maybe depending on

tools/net/ynl/ynl-regen.sh +3 -3
index 81b4ecd891006..fda5fe24cfd47 100755
@@ -29,9 +29,9 @@ for f in $files; do
  continue
     fi
 
-    echo -e "\tGEN ${params[2]}\t$f"
-    $TOOL --cmp-out --mode ${params[2]} --${params[3]} \
-   --spec $KDIR/${params[0]} $args -o $f
+    echo -e "\tGEN ${params[5]}\t$f"
+    $TOOL --cmp-out --mode ${params[4]} --${params[5]} \
+   --spec $KDIR/${params[1]} $args -o $f
 done
 
 popd >>/dev/null

fwiw, $params were like

Quoted 7 lines
Quoted 5 lines

3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel source
--
3- Documentation/netlink/specs/fou.yaml
4: YNL-GEN kernel header

Hm, I guess you have grep.lineNumber enabled in your git config?

Ah exactly, I didn't know that my corp machine enabled it globally by default :)

Quoted 2 lines

Could you see if tossing --no-line-number into the git grep in this script fixes it for you and if yes send a patch?

It worked, I'll include it in the series.

Thank you!