Jiayuan Chen a32aee8f0d bpf: fix filed access without lock
The tcp_bpf_recvmsg_parser() function, running in user context,
retrieves seq_copied from tcp_sk without holding the socket lock, and
stores it in a local variable seq. However, the softirq context can
modify tcp_sk->seq_copied concurrently, for example, n tcp_read_sock().

As a result, the seq value is stale when it is assigned back to
tcp_sk->copied_seq at the end of tcp_bpf_recvmsg_parser(), leading to
incorrect behavior.

Due to concurrency, the copied_seq field in tcp_bpf_recvmsg_parser()
might be set to an incorrect value (less than the actual copied_seq) at
the end of function: 'WRITE_ONCE(tcp->copied_seq, seq)'. This causes the
'offset' to be negative in tcp_read_sock()->tcp_recv_skb() when
processing new incoming packets (sk->copied_seq - skb->seq becomes less
than 0), and all subsequent packets will be dropped.

Signed-off-by: Jiayuan Chen <mrpre@163.com>
Link: https://lore.kernel.org/r/20241028065226.35568-1-mrpre@163.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2024-10-29 10:54:05 -07:00
..
2024-05-01 18:37:07 -07:00
2024-09-11 20:44:31 -07:00
2024-08-20 14:57:08 +02:00
2024-09-09 17:21:47 -07:00
2024-07-30 18:35:12 -07:00
2024-01-04 10:23:10 -08:00
2021-05-17 15:29:35 -07:00
2024-10-29 10:54:05 -07:00
2024-06-06 11:52:52 +02:00
2024-09-11 20:44:32 -07:00
2024-09-11 20:44:32 -07:00
2022-12-20 03:13:45 +01:00
2024-09-11 20:44:32 -07:00
2023-09-14 16:16:36 +02:00