]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
batman-adv: tp_meter: annotate last_recv_time access with READ/WRITE_ONCE
authorSven Eckelmann <sven@narfation.org>
Thu, 11 Jun 2026 08:28:33 +0000 (10:28 +0200)
committerSven Eckelmann <sven@narfation.org>
Sat, 13 Jun 2026 05:57:52 +0000 (07:57 +0200)
The last_recv_time field for batadv_tp_receiver tracks the jiffies value of
the most recent activity and is used to detect timeouts. These accesses are
not consistently protected by a lock, so READ_ONCE/WRITE_ONCE must be used
to prevent data races caused by compiler optimizations.

Cc: stable@kernel.org
Fixes: 33a3bb4a3345 ("batman-adv: throughput meter implementation")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/tp_meter.c

index 259ac8c307359605c0cbfe2c53b9ac53ec64304d..fb87fa141e32ae0b994bbe97be79c9f6af430555 100644 (file)
@@ -1290,7 +1290,7 @@ static void batadv_tp_receiver_shutdown(struct timer_list *t)
        bat_priv = tp_vars->common.bat_priv;
 
        /* if there is recent activity rearm the timer */
-       if (!batadv_has_timed_out(tp_vars->last_recv_time,
+       if (!batadv_has_timed_out(READ_ONCE(tp_vars->last_recv_time),
                                  BATADV_TP_RECV_TIMEOUT)) {
                /* reset the receiver shutdown timer */
                batadv_tp_reset_receiver_timer(tp_vars);
@@ -1532,7 +1532,7 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv,
        tp_vars = batadv_tp_list_find_receiver_session(bat_priv, icmp->orig,
                                                       icmp->session);
        if (tp_vars) {
-               tp_vars->last_recv_time = jiffies;
+               WRITE_ONCE(tp_vars->last_recv_time, jiffies);
                goto out_unlock;
        }
 
@@ -1562,7 +1562,7 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv,
        kref_get(&tp_vars->common.refcount);
        timer_setup(&tp_vars->common.timer, batadv_tp_receiver_shutdown, 0);
 
-       tp_vars->last_recv_time = jiffies;
+       WRITE_ONCE(tp_vars->last_recv_time, jiffies);
 
        kref_get(&tp_vars->common.refcount);
        hlist_add_head_rcu(&tp_vars->common.list, &bat_priv->tp_receiver_list);
@@ -1613,7 +1613,7 @@ static void batadv_tp_recv_msg(struct batadv_priv *bat_priv,
                        goto out;
                }
 
-               tp_vars->last_recv_time = jiffies;
+               WRITE_ONCE(tp_vars->last_recv_time, jiffies);
        }
 
        /* if the packet is a duplicate, it may be the case that an ACK has been