[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89i+JJ3747u5B89XMzxHQXgHiiXmftGZd2LV-ejJ3-g68CQ@mail.gmail.com>
Date: Mon, 8 May 2023 19:08:58 +0200
From: Eric Dumazet <edumazet@...gle.com>
To: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: "David S. Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org,
syzbot <syzkaller@...glegroups.com>
Subject: Re: [PATCH v2 net] net: Fix sk->sk_stamp race in sock_recv_cmsgs().
On Mon, May 8, 2023 at 6:58 PM Kuniyuki Iwashima <kuniyu@...zon.com> wrote:
>
> KCSAN found a data race in sock_recv_cmsgs() [0] where the read access
> to sk->sk_stamp needs READ_ONCE().
>
> Also, there is another race like below. If the torn load of the high
> 32-bits precedes WRITE_ONCE(sk, skb->tstamp) and later the written
> lower 32-bits happens to match with SK_DEFAULT_STAMP, the final result
> of sk->sk_stamp could be 0.
>
> sock_recv_cmsgs() ioctl(SIOCGSTAMP) sock_recv_cmsgs()
> | | |
> |- if (sock_flag(sk, SOCK_TIMESTAMP)) |
> | | |
> | `- sock_set_flag(sk, SOCK_TIMESTAMP)
> | |
> | `- if (sock_flag(sk, SOCK_TIMESTAMP))
> `- if (sk->sk_stamp == SK_DEFAULT_STAMP) `- sock_write_timestamp(sk, skb->tstamp)
> `- sock_write_timestamp(sk, 0)
>
> Even with READ_ONCE(), we could get the same result if READ_ONCE() precedes
> WRITE_ONCE() because the SK_DEFAULT_STAMP check and WRITE_ONCE(sk_stamp, 0)
> are not atomic.
>
> Let's avoid the race by cmpxchg() on 64-bits architecture or seqlock on
> 32-bits machines.
>
I disagree. Please use WRITE_ONCE(), even if we know it is racy on 32bit.
sock_read_timestamp() and sock_write_timestamp() already are racy, and
we do not care.
Powered by blists - more mailing lists