* [PATCH net] tcp: do not BUG on an unreadable urgent byte
@ 2026-11-25 12:42 Junyoung Jang
0 siblings, 0 replies; only message in thread
From: Junyoung Jang @ 2026-11-25 12:42 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell
Cc: Junyoung Jang, Gwanhyun Lee, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Mina Almasry, netdev,
linux-kernel
tcp_urg() checks that the urgent byte offset is within skb->len and
then calls skb_copy_bits(). The byte can still lie in an unreadable
Device Memory fragment. In that case skb_copy_bits() returns -EFAULT
and tcp_urg() calls BUG().
Mark the byte as TCP_URG_READ when the copy fails. Leaving
TCP_URG_NOTYET pending lets a later segment retry the old urgent
pointer: the unsigned offset can wrap into that segment's TCP header
and return a header byte through MSG_OOB. Clearing urg_data instead
would drop the urgent-byte hole and make ordinary recvmsg() hit
-EFAULT on the unreadable byte. TCP_URG_READ prevents the retry and
lets the receive path skip the hole until copied_seq passes urg_seq.
A custom LLM agent developed by the authors found this issue.
The author manually reviewed the root cause and tested the reproducer
and fix. A test-only netfilter module put a loopback MSG_OOB byte
in an unreadable skb fragment. On a 7.4.0-rc2 KASAN kernel, the
original code hit BUG(). The return-only fix avoided the BUG but let
a later MSG_OOB read return a byte from the next TCP header. With
this fix, that read returned -EINVAL, and a normal MSG_OOB control
still returned its byte. A test-only KUnit case seeded TCP_URG_READ
on a synthetic NET_IOV_DMABUF skb and confirmed that a successful
MSG_SOCK_DEVMEM read clears it. Device Memory hardware was not tested.
Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags")
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
net/ipv4/tcp_input.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d9a66a1342ef..50c0da17923e 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6390,8 +6390,10 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t
/* Is the urgent pointer pointing into this packet? */
if (ptr < skb->len) {
u8 tmp;
- if (skb_copy_bits(skb, ptr, &tmp, 1))
- BUG();
+ if (skb_copy_bits(skb, ptr, &tmp, 1)) {
+ WRITE_ONCE(tp->urg_data, TCP_URG_READ);
+ return;
+ }
WRITE_ONCE(tp->urg_data, TCP_URG_VALID | tmp);
if (!sock_flag(sk, SOCK_DEAD))
READ_ONCE(sk->sk_data_ready)(sk);
base-commit: 37fa509e43ba59d7c329025436e8ea64bdf089d7
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 12:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 12:42 [PATCH net] tcp: do not BUG on an unreadable urgent byte Junyoung Jang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®