Dong Chenchen
e2b48f9480
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 15:17:36 +01:00
..
2023-11-28 16:56:19 +00:00
2022-12-31 13:14:42 +01:00
2023-12-08 08:48:02 +01:00
2023-12-20 15:17:35 +01:00
2022-06-22 14:22:01 +02:00
2023-12-20 15:17:35 +01:00
2023-11-28 16:56:16 +00:00
2022-12-31 13:14:11 +01:00
2023-11-28 16:56:24 +00:00
2023-03-17 08:48:54 +01:00
2023-11-08 17:26:49 +01:00
2023-10-19 23:05:36 +02:00
2023-12-13 18:36:46 +01:00
2023-08-11 15:13:53 +02:00
2023-11-28 16:56:22 +00:00
2023-07-23 13:47:30 +02:00
2023-05-17 11:50:18 +02:00
2023-11-20 11:08:28 +01:00
2022-11-03 23:59:14 +09:00
2023-12-20 15:17:36 +01:00
2023-12-20 15:17:34 +01:00
2023-03-22 13:31:28 +01:00
2023-09-19 12:23:04 +02:00
2023-08-26 14:23:32 +02:00
2023-10-10 21:59:07 +02:00
2022-04-27 14:38:53 +02:00
2023-11-20 11:08:28 +01:00
2023-11-28 16:56:15 +00:00
2022-12-14 11:37:25 +01:00
2023-10-25 11:58:59 +02:00
2023-02-22 12:57:09 +01:00
2023-11-28 16:56:22 +00:00
2023-11-28 16:56:33 +00:00
2023-12-20 15:17:33 +01:00
2023-09-19 12:22:29 +02:00
2023-12-13 18:36:38 +01:00
2023-09-19 12:22:35 +02:00
2023-10-25 11:58:55 +02:00
2023-05-24 17:36:51 +01:00
2023-02-22 12:57:09 +01:00
2023-12-13 18:36:43 +01:00
2022-01-11 15:35:16 +01:00
2023-12-13 18:36:37 +01:00
2023-04-20 12:13:53 +02:00
2023-10-19 23:05:33 +02:00
2023-10-25 11:58:57 +02:00
2023-12-20 15:17:36 +01:00
2023-05-17 11:50:17 +02:00
2023-11-08 17:26:45 +01:00
2023-10-10 21:59:08 +02:00
2023-12-03 07:31:22 +01:00
2023-11-28 16:56:29 +00:00
2023-11-28 16:56:23 +00:00
2023-09-19 12:23:04 +02:00
2023-11-28 16:56:24 +00:00
2023-11-08 17:26:37 +01:00
2023-10-25 11:59:00 +02:00
2023-02-09 11:26:40 +01:00
2023-09-19 12:22:58 +02:00
2023-10-25 11:58:56 +02:00
2023-06-21 15:59:15 +02:00
2023-06-21 15:59:15 +02:00
2023-10-19 23:05:33 +02:00