Re: [PATCH net] raw: annotate data-races in raw_v6_match()
From: Eric Dumazet
Date: Mon Jun 01 2026 - 04:13:51 EST
On Mon, Jun 1, 2026 at 12:42 AM Runyu Xiao <runyu.xiao@xxxxxxxxxx> wrote:
>
> raw_v6_match() is a lockless match helper under sk_for_each_rcu()
> and still reads inet_sk(sk)->inet_num, sk->sk_bound_dev_if,
> sk->sk_v6_daddr and sk->sk_v6_rcv_saddr with plain loads.
>
> Add READ_ONCE() annotations for these fields.
>
> Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
> ---
> net/ipv6/raw.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
> index 3cc58698cbbd..7160d5513742 100644
> --- a/net/ipv6/raw.c
> +++ b/net/ipv6/raw.c
> @@ -64,20 +64,37 @@
> struct raw_hashinfo raw_v6_hashinfo;
> EXPORT_SYMBOL_GPL(raw_v6_hashinfo);
>
> +static void raw_v6_addr_snapshot(struct in6_addr *dst,
> + const struct in6_addr *src)
> +{
> + dst->s6_addr32[0] = READ_ONCE(src->s6_addr32[0]);
> + dst->s6_addr32[1] = READ_ONCE(src->s6_addr32[1]);
> + dst->s6_addr32[2] = READ_ONCE(src->s6_addr32[2]);
> + dst->s6_addr32[3] = READ_ONCE(src->s6_addr32[3]);
> +}
I do not think we want to incur an extra cost for such a minor race.
Note that your patch does not solve the race, since writers do not
update these fields atomically anyway.