Netdev List
 help / color / mirror / Atom feed
* [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
@ 2026-08-30 18:09 Kuniyuki Iwashima
  2026-08-30 18:25 ` Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2026-08-30 18:09 UTC (permalink / raw)
  To: Willem de Bruijn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Simon Horman, Johann Baudy, Kuniyuki Iwashima, Kuniyuki Iwashima,
	netdev, syzbot+73df3f89e1e13089e466

syzbot reported BUG() in sock_sendmsg_nosec(). [0]

The problem is that tpacket_parse_header() casts user-provided
tpacket_hdr.tp_len, which is u32, to int.

If the length is larger than INT_MAX, the following condition
in tpacket_parse_header() passes,

  if (unlikely(tp_len > size_max))

and any negative value can be returned to the caller, up to
sock_sendmsg_nosec().

The repro set tpacket_hdr.tp_len to 0xfffffdef, which is cast
to -EIOCBQUEUED (-529), triggering BUG() in sock_sendmsg_nosec().

  *(uint64_t*)0x200000000008 = 0xfffffdef;
  ...
  syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000000ul, /*count=*/1ul);

Let's define the local tp_len as u32 in tpacket_parse_header().

[0]:
kernel BUG at net/socket.c:803!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 0 UID: 0 PID: 5628 Comm: syz-executor176 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
RIP: 0010:sock_sendmsg_nosec+0x145/0x180 net/socket.c:803
Code: 06 67 48 0f b9 3a eb 95 e8 e8 3a 22 f8 48 89 df 4c 89 f6 4c 89 e2 4d 89 fb 2e e8 32 a5 5c 16 e9 51 ff ff ff e8 cc 3a 22 f8 90 <0f> 0b e8 c4 3a 22 f8 48 83 c3 18 48 89 d8 48 c1 e8 03 42 80 3c 28
RSP: 0018:ffffc90003aefb48 EFLAGS: 00010293
RAX: ffffffff89a578d4 RBX: ffff8880764c67c0 RCX: ffff88807fb23e80
RDX: 0000000000000000 RSI: 00000000fffffdef RDI: 00000000fffffdef
RBP: 00000000fffffdef R08: ffffc90003aef747 R09: 1ffff9200075dee8
R10: dffffc0000000000 R11: fffff5200075dee9 R12: 0000000000000001
R13: dffffc0000000000 R14: ffffc90003aefbc0 R15: ffffffff8aac4310
FS:  000055559101b400(0000) GS:ffff888124ce0000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000200000000210 CR3: 0000000073dca000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 __sock_sendmsg net/socket.c:815 [inline]
 sock_write_iter+0x2de/0x3e0 net/socket.c:1266
 new_sync_write fs/read_write.c:595 [inline]
 vfs_write+0x612/0xba0 fs/read_write.c:687
 ksys_write+0x150/0x270 fs/read_write.c:739
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f173130ecb9
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd67e44248 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000200000000000 RCX: 00007f173130ecb9
RDX: 0000000000000001 RSI: 0000200000000000 RDI: 0000000000000003
RBP: 0000000000000001 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd67e44388
R13: 0000000000000002 R14: 00002000000000c0 R15: 0000000000000002
 </TASK>

Fixes: 69e3c75f4d54 ("net: TX_RING and packet mmap")
Reported-by: syzbot+73df3f89e1e13089e466@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a946ffa.1d9ded08.62e62.0123.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 net/packet/af_packet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index b22cda322136..76bde7906d49 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2675,7 +2675,8 @@ static int tpacket_parse_header(struct packet_sock *po, void *frame,
 				int size_max, void **data)
 {
 	union tpacket_uhdr ph;
-	int tp_len, off;
+	u32 tp_len;
+	int off;
 
 	ph.raw = frame;
 
@@ -2695,7 +2696,7 @@ static int tpacket_parse_header(struct packet_sock *po, void *frame,
 		break;
 	}
 	if (unlikely(tp_len > size_max)) {
-		pr_err("packet size is too long (%d > %d)\n", tp_len, size_max);
+		pr_err("packet size is too long (%u > %d)\n", tp_len, size_max);
 		return -EMSGSIZE;
 	}
 
-- 
2.55.0.897.gb25b4bd76c-goog


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

* Re: [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
  2026-08-30 18:09 [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header() Kuniyuki Iwashima
@ 2026-08-30 18:25 ` Eric Dumazet
  2026-08-30 18:36   ` Kuniyuki Iwashima
  2026-08-31 15:32 ` Willem de Bruijn
  2026-09-01  8:50 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2026-08-30 18:25 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: Willem de Bruijn, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Johann Baudy, Kuniyuki Iwashima, netdev,
	syzbot+73df3f89e1e13089e466

On Sun, Aug 30, 2026 at 8:09 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
>
> syzbot reported BUG() in sock_sendmsg_nosec(). [0]
>
> The problem is that tpacket_parse_header() casts user-provided
> tpacket_hdr.tp_len, which is u32, to int.
>
> If the length is larger than INT_MAX, the following condition
> in tpacket_parse_header() passes,
>
>   if (unlikely(tp_len > size_max))
>
> and any negative value can be returned to the caller, up to
> sock_sendmsg_nosec().
>
> The repro set tpacket_hdr.tp_len to 0xfffffdef, which is cast
> to -EIOCBQUEUED (-529), triggering BUG() in sock_sendmsg_nosec().

Patch looks good, I wonder why we still have this awful BUG_ON(ret ==
-EIOCBQUEUED) though.

Work done in 2014–2015 by Al Viro and Christoph Hellwig was completed
more than a decade ago.

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
  2026-08-30 18:25 ` Eric Dumazet
@ 2026-08-30 18:36   ` Kuniyuki Iwashima
  0 siblings, 0 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2026-08-30 18:36 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Willem de Bruijn, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Johann Baudy, Kuniyuki Iwashima, netdev,
	syzbot+73df3f89e1e13089e466

On Sun, Aug 30, 2026 at 11:25 AM Eric Dumazet <edumazet@google.com> wrote:
>
> On Sun, Aug 30, 2026 at 8:09 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
> >
> > syzbot reported BUG() in sock_sendmsg_nosec(). [0]
> >
> > The problem is that tpacket_parse_header() casts user-provided
> > tpacket_hdr.tp_len, which is u32, to int.
> >
> > If the length is larger than INT_MAX, the following condition
> > in tpacket_parse_header() passes,
> >
> >   if (unlikely(tp_len > size_max))
> >
> > and any negative value can be returned to the caller, up to
> > sock_sendmsg_nosec().
> >
> > The repro set tpacket_hdr.tp_len to 0xfffffdef, which is cast
> > to -EIOCBQUEUED (-529), triggering BUG() in sock_sendmsg_nosec().
>
> Patch looks good, I wonder why we still have this awful BUG_ON(ret ==
> -EIOCBQUEUED) though.

I think we can remove one in sendmsg() at least, syzbot will
catch the same issue by the same BUG_ON() in the write() path
in fs/read_write.c.


>
> Work done in 2014–2015 by Al Viro and Christoph Hellwig was completed
> more than a decade ago.
>
> Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !

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

* Re: [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
  2026-08-30 18:09 [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header() Kuniyuki Iwashima
  2026-08-30 18:25 ` Eric Dumazet
@ 2026-08-31 15:32 ` Willem de Bruijn
  2026-09-01  8:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2026-08-31 15:32 UTC (permalink / raw)
  To: Kuniyuki Iwashima, Willem de Bruijn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Johann Baudy, Kuniyuki Iwashima, Kuniyuki Iwashima,
	netdev, syzbot+73df3f89e1e13089e466

Kuniyuki Iwashima wrote:
> syzbot reported BUG() in sock_sendmsg_nosec(). [0]
> 
> The problem is that tpacket_parse_header() casts user-provided
> tpacket_hdr.tp_len, which is u32, to int.
> 
> If the length is larger than INT_MAX, the following condition
> in tpacket_parse_header() passes,
> 
>   if (unlikely(tp_len > size_max))
> 
> and any negative value can be returned to the caller, up to
> sock_sendmsg_nosec().
> 
> The repro set tpacket_hdr.tp_len to 0xfffffdef, which is cast
> to -EIOCBQUEUED (-529), triggering BUG() in sock_sendmsg_nosec().
> 
>   *(uint64_t*)0x200000000008 = 0xfffffdef;
>   ...
>   syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000000ul, /*count=*/1ul);
> 
> Let's define the local tp_len as u32 in tpacket_parse_header().
> 
> [0]:
> kernel BUG at net/socket.c:803!
> Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
> CPU: 0 UID: 0 PID: 5628 Comm: syz-executor176 Not tainted syzkaller #0 PREEMPT(full)
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
> RIP: 0010:sock_sendmsg_nosec+0x145/0x180 net/socket.c:803
> Code: 06 67 48 0f b9 3a eb 95 e8 e8 3a 22 f8 48 89 df 4c 89 f6 4c 89 e2 4d 89 fb 2e e8 32 a5 5c 16 e9 51 ff ff ff e8 cc 3a 22 f8 90 <0f> 0b e8 c4 3a 22 f8 48 83 c3 18 48 89 d8 48 c1 e8 03 42 80 3c 28
> RSP: 0018:ffffc90003aefb48 EFLAGS: 00010293
> RAX: ffffffff89a578d4 RBX: ffff8880764c67c0 RCX: ffff88807fb23e80
> RDX: 0000000000000000 RSI: 00000000fffffdef RDI: 00000000fffffdef
> RBP: 00000000fffffdef R08: ffffc90003aef747 R09: 1ffff9200075dee8
> R10: dffffc0000000000 R11: fffff5200075dee9 R12: 0000000000000001
> R13: dffffc0000000000 R14: ffffc90003aefbc0 R15: ffffffff8aac4310
> FS:  000055559101b400(0000) GS:ffff888124ce0000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000200000000210 CR3: 0000000073dca000 CR4: 00000000003526f0
> Call Trace:
>  <TASK>
>  __sock_sendmsg net/socket.c:815 [inline]
>  sock_write_iter+0x2de/0x3e0 net/socket.c:1266
>  new_sync_write fs/read_write.c:595 [inline]
>  vfs_write+0x612/0xba0 fs/read_write.c:687
>  ksys_write+0x150/0x270 fs/read_write.c:739
>  do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
>  do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f173130ecb9
> Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007ffd67e44248 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
> RAX: ffffffffffffffda RBX: 0000200000000000 RCX: 00007f173130ecb9
> RDX: 0000000000000001 RSI: 0000200000000000 RDI: 0000000000000003
> RBP: 0000000000000001 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd67e44388
> R13: 0000000000000002 R14: 00002000000000c0 R15: 0000000000000002
>  </TASK>
> 
> Fixes: 69e3c75f4d54 ("net: TX_RING and packet mmap")
> Reported-by: syzbot+73df3f89e1e13089e466@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a946ffa.1d9ded08.62e62.0123.GAE@google.com/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>

Reviewed-by: Willem de Bruijn <willemb@google.com>

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

* Re: [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
  2026-08-30 18:09 [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header() Kuniyuki Iwashima
  2026-08-30 18:25 ` Eric Dumazet
  2026-08-31 15:32 ` Willem de Bruijn
@ 2026-09-01  8:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-01  8:50 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: willemdebruijn.kernel, davem, edumazet, kuba, pabeni, horms,
	johann.baudy, kuni1840, netdev, syzbot+73df3f89e1e13089e466

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sun, 30 Aug 2026 18:09:12 +0000 you wrote:
> syzbot reported BUG() in sock_sendmsg_nosec(). [0]
> 
> The problem is that tpacket_parse_header() casts user-provided
> tpacket_hdr.tp_len, which is u32, to int.
> 
> If the length is larger than INT_MAX, the following condition
> in tpacket_parse_header() passes,
> 
> [...]

Here is the summary with links:
  - [v1,net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().
    https://git.kernel.org/netdev/net/c/73e594c19b4f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-09-01  8:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-30 18:09 [PATCH v1 net] af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header() Kuniyuki Iwashima
2026-08-30 18:25 ` Eric Dumazet
2026-08-30 18:36   ` Kuniyuki Iwashima
2026-08-31 15:32 ` Willem de Bruijn
2026-09-01  8:50 ` patchwork-bot+netdevbpf

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