Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: mark racy access on sk->sk_rcvbuf
@ 2024-03-09 13:34 linke li
  2024-03-09 13:50 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: linke li @ 2024-03-09 13:34 UTC (permalink / raw)
  Cc: lilinke99, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kuniyuki Iwashima, Willem de Bruijn, Abel Wu,
	Breno Leitao, Alexander Mikhalitsyn, David Howells, netdev,
	linux-kernel

sk->sk_rcvbuf 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>
---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 5e78798456fd..4c5524e70534 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -551,7 +551,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;
 	}
-- 
2.39.3 (Apple Git-146)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: mark racy access on sk->sk_rcvbuf
  2024-03-09 13:34 [PATCH] net: mark racy access on sk->sk_rcvbuf linke li
@ 2024-03-09 13:50 ` Eric Dumazet
  2024-03-09 13:59   ` linke li
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2024-03-09 13:50 UTC (permalink / raw)
  To: linke li
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Kuniyuki Iwashima,
	Willem de Bruijn, Abel Wu, Breno Leitao, Alexander Mikhalitsyn,
	David Howells, netdev, linux-kernel

On Sat, Mar 9, 2024 at 2:35 PM linke li <lilinke99@qq.com> wrote:
>
> sk->sk_rcvbuf 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>
> ---
>  net/core/sock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 5e78798456fd..4c5524e70534 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -551,7 +551,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;

OK, but what about __sock_queue_rcv_skb() in the same file ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: mark racy access on sk->sk_rcvbuf
  2024-03-09 13:50 ` Eric Dumazet
@ 2024-03-09 13:59   ` linke li
  2024-03-09 14:49     ` Jason Xing
  0 siblings, 1 reply; 4+ messages in thread
From: linke li @ 2024-03-09 13:59 UTC (permalink / raw)
  To: edumazet
  Cc: alexander, davem, dhowells, kuba, kuniyu, leitao, lilinke99,
	linux-kernel, netdev, pabeni, willemb, wuyun.abel

> OK, but what about __sock_queue_rcv_skb() in the same file ?

I notice that, but I am not very sure whether there is a data race. If it
is a similar situation, then the same patch should be applied too.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: mark racy access on sk->sk_rcvbuf
  2024-03-09 13:59   ` linke li
@ 2024-03-09 14:49     ` Jason Xing
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Xing @ 2024-03-09 14:49 UTC (permalink / raw)
  To: linke li
  Cc: edumazet, alexander, davem, dhowells, kuba, kuniyu, leitao,
	linux-kernel, netdev, pabeni, willemb, wuyun.abel

On Sat, Mar 9, 2024 at 10:10 PM linke li <lilinke99@qq.com> wrote:
>
> > OK, but what about __sock_queue_rcv_skb() in the same file ?
>
> I notice that, but I am not very sure whether there is a data race. If it
> is a similar situation, then the same patch should be applied too.

During that process, I see no lock owning the socket, so sk->sk_rcvbuf
should also be read locklessly.

Thanks,
Jason

>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-09 14:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-09 13:34 [PATCH] net: mark racy access on sk->sk_rcvbuf linke li
2024-03-09 13:50 ` Eric Dumazet
2024-03-09 13:59   ` linke li
2024-03-09 14:49     ` Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox