net: prevent load/store tearing on sk->sk_stamp
authorEric Dumazet <edumazet@google.com>
Tue, 5 Nov 2019 05:38:43 +0000 (21:38 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 6 Nov 2019 02:22:30 +0000 (18:22 -0800)
Add a couple of READ_ONCE() and WRITE_ONCE() to prevent
load-tearing and store-tearing in sock_read_timestamp()
and sock_write_timestamp()

This might prevent another KCSAN report.

Fixes: 3a0ed3e96197 ("sock: Make sock->sk_stamp thread-safe")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h

index 8f9adcf..718e62f 100644 (file)
@@ -2342,7 +2342,7 @@ static inline ktime_t sock_read_timestamp(struct sock *sk)
 
        return kt;
 #else
 
        return kt;
 #else
-       return sk->sk_stamp;
+       return READ_ONCE(sk->sk_stamp);
 #endif
 }
 
 #endif
 }
 
@@ -2353,7 +2353,7 @@ static inline void sock_write_timestamp(struct sock *sk, ktime_t kt)
        sk->sk_stamp = kt;
        write_sequnlock(&sk->sk_stamp_seq);
 #else
        sk->sk_stamp = kt;
        write_sequnlock(&sk->sk_stamp_seq);
 #else
-       sk->sk_stamp = kt;
+       WRITE_ONCE(sk->sk_stamp, kt);
 #endif
 }
 
 #endif
 }