tcp: do not BUG on an unreadable urgent byte
Subsystems (3)
PATCH 1/1 tcp: do not BUG on an unreadable urgent byte
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.
--- net/ipv4/tcp_input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +4 -2
@@ -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
Signature · 1 line
2.43.0