From: Junyoung Jang <graypanda.inzag@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>, Neal Cardwell <ncardwell@google.com>
Cc: Junyoung Jang <graypanda.inzag@gmail.com>,
Gwanhyun Lee <gwanhyunlee@gmail.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Mina Almasry <almasrymina@google.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] tcp: do not BUG on an unreadable urgent byte
Date: Wed, 25 Nov 2026 21:42:11 +0900 [thread overview]
Message-ID: <20261125124212.4145820-1-graypanda.inzag@gmail.com> (raw)
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
reply other threads:[~2026-11-25 12:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125124212.4145820-1-graypanda.inzag@gmail.com \
--to=graypanda.inzag@gmail.com \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gwanhyunlee@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox