Dong Chenchen
55a43bae08
net: Remove acked SYN flag from packet in the transmit queue correctly
...
[ Upstream commit f99cd56230f56c8b6b33713c5be4da5d6766be1f ]
syzkaller report:
kernel BUG at net/core/skbuff.c:3452!
invalid opcode: 0000 [#1 ] PREEMPT SMP KASAN PTI
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.7.0-rc4-00009-gbee0e7762ad2-dirty #135
RIP: 0010:skb_copy_and_csum_bits (net/core/skbuff.c:3452)
Call Trace:
icmp_glue_bits (net/ipv4/icmp.c:357)
__ip_append_data.isra.0 (net/ipv4/ip_output.c:1165)
ip_append_data (net/ipv4/ip_output.c:1362 net/ipv4/ip_output.c:1341)
icmp_push_reply (net/ipv4/icmp.c:370)
__icmp_send (./include/net/route.h:252 net/ipv4/icmp.c:772)
ip_fragment.constprop.0 (./include/linux/skbuff.h:1234 net/ipv4/ip_output.c:592 net/ipv4/ip_output.c:577)
__ip_finish_output (net/ipv4/ip_output.c:311 net/ipv4/ip_output.c:295)
ip_output (net/ipv4/ip_output.c:427)
__ip_queue_xmit (net/ipv4/ip_output.c:535)
__tcp_transmit_skb (net/ipv4/tcp_output.c:1462)
__tcp_retransmit_skb (net/ipv4/tcp_output.c:3387)
tcp_retransmit_skb (net/ipv4/tcp_output.c:3404)
tcp_retransmit_timer (net/ipv4/tcp_timer.c:604)
tcp_write_timer (./include/linux/spinlock.h:391 net/ipv4/tcp_timer.c:716)
The panic issue was trigered by tcp simultaneous initiation.
The initiation process is as follows:
TCP A TCP B
1. CLOSED CLOSED
2. SYN-SENT --> <SEQ=100><CTL=SYN> ...
3. SYN-RECEIVED <-- <SEQ=300><CTL=SYN> <-- SYN-SENT
4. ... <SEQ=100><CTL=SYN> --> SYN-RECEIVED
5. SYN-RECEIVED --> <SEQ=100><ACK=301><CTL=SYN,ACK> ...
// TCP B: not send challenge ack for ack limit or packet loss
// TCP A: close
tcp_close
tcp_send_fin
if (!tskb && tcp_under_memory_pressure(sk))
tskb = skb_rb_last(&sk->tcp_rtx_queue); //pick SYN_ACK packet
TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN; // set FIN flag
6. FIN_WAIT_1 --> <SEQ=100><ACK=301><END_SEQ=102><CTL=SYN,FIN,ACK> ...
// TCP B: send challenge ack to SYN_FIN_ACK
7. ... <SEQ=301><ACK=101><CTL=ACK> <-- SYN-RECEIVED //challenge ack
// TCP A: <SND.UNA=101>
8. FIN_WAIT_1 --> <SEQ=101><ACK=301><END_SEQ=102><CTL=SYN,FIN,ACK> ... // retransmit panic
__tcp_retransmit_skb //skb->len=0
tcp_trim_head
len = tp->snd_una - TCP_SKB_CB(skb)->seq // len=101-100
__pskb_trim_head
skb->data_len -= len // skb->len=-1, wrap around
... ...
ip_fragment
icmp_glue_bits //BUG_ON
If we use tcp_trim_head() to remove acked SYN from packet that contains data
or other flags, skb->len will be incorrectly decremented. We can remove SYN
flag that has been acked from rtx_queue earlier than tcp_trim_head(), which
can fix the problem mentioned above.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Co-developed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
Link: https://lore.kernel.org/r/20231210020200.1539875-1-dongchenchen2@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-12-20 17:00:18 +01:00
..
2023-11-28 17:07:01 +00:00
2022-12-31 13:33:02 +01:00
2023-05-24 17:32:47 +01:00
2023-12-20 17:00:17 +01:00
2022-08-22 17:55:50 -07:00
2023-12-20 17:00:16 +01:00
2023-11-28 17:06:56 +00:00
2023-03-17 08:50:32 +01:00
2023-11-28 17:07:05 +00:00
2023-03-17 08:50:24 +01:00
2023-10-19 23:08:52 +02:00
2023-10-19 23:08:56 +02:00
2023-12-13 18:39:17 +01:00
2023-08-11 12:08:17 +02:00
2023-11-20 11:52:16 +01:00
2023-09-23 11:11:01 +02:00
2023-07-19 16:22:06 +02:00
2022-08-25 10:33:21 +02:00
2023-09-19 12:28:10 +02:00
2023-11-20 11:52:15 +01:00
2022-10-07 09:29:17 +02:00
2023-12-20 17:00:18 +01:00
2023-12-20 17:00:15 +01:00
2023-03-22 13:33:50 +01:00
2023-09-19 12:28:10 +02:00
2023-08-23 17:52:32 +02:00
2023-10-10 22:00:42 +02:00
2023-11-20 11:52:15 +01:00
2023-11-28 17:06:55 +00:00
2022-12-05 09:53:08 +01:00
2023-10-19 23:08:57 +02:00
2023-02-22 12:59:53 +01:00
2023-11-28 17:07:20 +00:00
2023-11-28 17:07:18 +00:00
2023-12-13 18:39:29 +01:00
2023-09-13 09:42:24 +02:00
2023-12-13 18:39:12 +01:00
2023-09-13 09:42:35 +02:00
2023-10-25 12:03:04 +02:00
2023-05-24 17:32:45 +01:00
2023-08-23 17:52:35 +02:00
2023-12-13 18:39:20 +01:00
2023-12-13 18:39:11 +01:00
2023-04-20 12:35:09 +02:00
2023-10-19 23:08:50 +02:00
2023-10-25 12:03:06 +02:00
2023-12-20 17:00:17 +01:00
2023-05-17 11:53:35 +02:00
2023-11-08 14:10:57 +01:00
2023-10-10 22:00:44 +02:00
2023-12-03 07:32:08 +01:00
2023-11-28 17:07:11 +00:00
2023-11-28 17:07:05 +00:00
2023-11-20 11:51:52 +01:00
2023-11-28 17:07:05 +00:00
2023-11-28 17:06:56 +00:00
2023-12-11 10:41:01 +01:00
2023-02-09 11:28:13 +01:00
2023-12-13 18:39:08 +01:00
2023-10-25 12:03:12 +02:00
2023-02-09 11:28:04 +01:00
2022-08-22 14:26:30 +01:00
2022-09-20 14:23:56 -07:00
2023-08-30 16:11:00 +02:00
2023-10-19 23:08:50 +02:00