Re: [PATCH net] tcp: do not BUG on an unreadable urgent byte

From: Kuniyuki Iwashima

Date: Sun Nov 29 2026 - 19:34:17 EST


On Wed, 25 Nov 2026 21:42:11 +0900, Junyoung Jang wrote:
> 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@xxxxxxxxx>
> Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>

Reviewed-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>