Skip to contentSkip to conversation

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

PATCH Applied Kuniyuki Iwashima 3 participants 7 messages Jan 15 – Jan 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 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 3 fixes the same issue in FOU.

Changes:
v2:
* Add patch 2 for ynl-regen.sh (Jakub)
* Patch 3
* Updated ynl spec and regenerated fou_nl.c (Jakub)

v1: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (3):
gue: Fix skb memleak with inner IP protocol 0.
tools: ynl: Specify --no-line-number in ynl-regen.sh.
fou: Don't allow 0 for FOU_ATTR_IPPROTO.

 Documentation/netlink/specs/fou.yaml | 2 ++
 net/ipv4/fou_core.c                  | 3 +++
 net/ipv4/fou_nl.c                    | 2 +-
 tools/net/ynl/ynl-regen.sh           | 2 +-
 4 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#1 lore raw

PATCH v2 1/3 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 3970b6b7ace5..ab8f309f8925 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
#2 lore raw

PATCH v2 2/3 tools: ynl: Specify --no-line-number in ynl-regen.sh.

In reply to Kuniyuki Iwashima

If grep.lineNumber is enabled in .gitconfig,

[grep]
lineNumber = true

ynl-regen.sh fails with the following error:

  $ ./tools/net/ynl/ynl-regen.sh -f
  ...
  ynl_gen_c.py: error: argument --mode: invalid choice: '4:' (choose from user, kernel, uapi)
  	GEN 4:	net/ipv4/fou_nl.c

Let's specify --no-line-number explicitly.

Fixes be5bea1cc0bf ("net: add basic C code generators for Netlink")
---
 tools/net/ynl/ynl-regen.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/ynl-regen.sh +1 -1
index 81b4ecd89100..d9809276db98 100755
@@ -21,7 +21,7 @@ files=$(git grep --files-with-matches '^/\* YNL-GEN \(kernel\|uapi\|user\)')
 for f in $files; do
     # params:     0       1      2     3
     #         $YAML YNL-GEN kernel $mode
-    params=( $(git grep -B1 -h '/\* YNL-GEN' $f | sed 's@/\*\(.*\)\*/@\1@') )
+    params=( $(git grep --no-line-number -B1 -h '/\* YNL-GEN' $f | sed 's@/\*\(.*\)\*/@\1@') )
     args=$(sed -n 's@/\* YNL-ARG \(.*\) \*/@\1@p' $f)
 
     if [ $f -nt ${params[0]} -a -z "$force" ]; then
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Reviewed-by on v2 2/3
#3 lore raw

Re: [PATCH v2 net 2/3] tools: ynl: Specify --no-line-number in ynl-regen.sh.

Quoted 6 lines · Kuniyuki Iwashima

If grep.lineNumber is enabled in .gitconfig,

[grep]
lineNumber = true

Quoted 8 lines

ynl-regen.sh fails with the following error:

  $ ./tools/net/ynl/ynl-regen.sh -f
  ...
  ynl_gen_c.py: error: argument --mode: invalid choice: '4:' (choose from user, kernel, uapi)
        GEN 4:  net/ipv4/fou_nl.c

Let's specify --no-line-number explicitly.

#4 lore raw

PATCH v2 3/3 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")

---
v2:
* Updated ynl spec and generated fou_nl.c (Jakub)

---
 Documentation/netlink/specs/fou.yaml | 2 ++
 net/ipv4/fou_nl.c                    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
Documentation/netlink/specs/fou.yaml +2 -0
index 8e7974ec453f..331f1b342b3a 100644
@@ -39,6 +39,8 @@ attribute-sets:
       -
         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, },
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Reviewed-by on v2 3/3
#5 lore raw

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

Quoted 4 lines · Kuniyuki Iwashima

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

Quoted 8 lines

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")

---

#6 lore raw
In reply to Kuniyuki Iwashima
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 15 Jan 2026 17:24:45 +0000 you wrote:

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

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

[...]

Here is the summary with links:
- [v2,net,1/3] gue: Fix skb memleak with inner IP protocol 0.

    https://git.kernel.org/netdev/net/c/9a56796ad258
  - [v2,net,2/3] tools: ynl: Specify --no-line-number in ynl-regen.sh.
    https://git.kernel.org/netdev/net/c/68578370f9b3
  - [v2,net,3/3] fou: Don't allow 0 for FOU_ATTR_IPPROTO.
    https://git.kernel.org/netdev/net/c/7a9bc9e3f423

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html