Skip to content

Commit

Permalink
net: mark racy access on sk->sk_rcvbuf
Browse files Browse the repository at this point in the history
[ Upstream commit c2deb2e971f5d9aca941ef13ee05566979e337a4 ]

sk->sk_rcvbuf in __sock_queue_rcv_skb() and __sk_receive_skb() can be
changed by other threads. Mark this as benign using READ_ONCE().

This patch is aimed at reducing the number of benign races reported by
KCSAN in order to focus future debugging effort on harmful races.

Signed-off-by: linke li <lilinke99@qq.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 9e7538cb8131946817218f793ceb334c63cfcdb8)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
  • Loading branch information
linke li authored and Anush02198 committed Dec 4, 2024
1 parent f46cc8d commit 1ee372e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
unsigned long flags;
struct sk_buff_head *list = &sk->sk_receive_queue;

if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
if (atomic_read(&sk->sk_rmem_alloc) >= READ_ONCE(sk->sk_rcvbuf)) {
atomic_inc(&sk->sk_drops);
trace_sock_rcvqueue_full(sk, skb);
return -ENOMEM;
Expand Down Expand Up @@ -494,7 +494,7 @@ int __sk_receive_skb(struct sock *sk, struct sk_buff *skb,

skb->dev = NULL;

if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
if (sk_rcvqueues_full(sk, READ_ONCE(sk->sk_rcvbuf))) {
atomic_inc(&sk->sk_drops);
goto discard_and_relse;
}
Expand Down

0 comments on commit 1ee372e

Please sign in to comment.