]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: annotate data-races around sk->sk_bind_phc
authorEric Dumazet <edumazet@google.com>
Thu, 31 Aug 2023 13:52:12 +0000 (13:52 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Jan 2024 16:10:23 +0000 (17:10 +0100)
[ Upstream commit 251cd405a9e6e70b92fe5afbdd17fd5caf9d3266 ]

sk->sk_bind_phc is read locklessly. Add corresponding annotations.

Fixes: d463126e23f1 ("net: sock: extend SO_TIMESTAMPING for PHC binding")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: 7f6ca95d16b9 ("net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)")
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/sock.c
net/socket.c

index 929055bc0cc7be79477be774960cad2d803fc2fd..49b7f252ddae4063f56fac3833bbc5f4da3ad68f 100644 (file)
@@ -890,7 +890,7 @@ static int sock_timestamping_bind_phc(struct sock *sk, int phc_index)
        if (!match)
                return -EINVAL;
 
-       sk->sk_bind_phc = phc_index;
+       WRITE_ONCE(sk->sk_bind_phc, phc_index);
 
        return 0;
 }
@@ -1706,7 +1706,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
        case SO_TIMESTAMPING_OLD:
                lv = sizeof(v.timestamping);
                v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
-               v.timestamping.bind_phc = sk->sk_bind_phc;
+               v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
                break;
 
        case SO_RCVTIMEO_OLD:
index 9c1fb94b1285125729e978fc569bad3f03eeea60..07470724e735863758778a6fc1f1564971469e56 100644 (file)
@@ -940,7 +940,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
 
                if (tsflags & SOF_TIMESTAMPING_BIND_PHC)
                        hwtstamp = ptp_convert_timestamp(&hwtstamp,
-                                                        sk->sk_bind_phc);
+                                                        READ_ONCE(sk->sk_bind_phc));
 
                if (ktime_to_timespec64_cond(hwtstamp, tss.ts + 2)) {
                        empty = 0;