]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
batman-adv: fix tp_meter counter underflow during shutdown
authorLuxiao Xu <rakukuip@gmail.com>
Mon, 11 May 2026 16:52:09 +0000 (18:52 +0200)
committerSven Eckelmann <sven@narfation.org>
Mon, 11 May 2026 17:52:40 +0000 (19:52 +0200)
commit94f3b133168d1c49895e7cc6afbcf1cc0b354602
tree64ded3482ebe5ebb8e8da42c979e87aa0d1c9f98
parentba9d20ee9076dac32c371116bacbe72480eb356c
batman-adv: fix tp_meter counter underflow during shutdown

batadv_tp_sender_shutdown() unconditionally decrements the "sending"
atomic counter. If multiple paths (e.g. timeout, user cancel, and
normal finish) call this function, the counter can underflow to -1.

Since the sender logic treats any non-zero value as "still sending",
a negative value causes the sender kthread to loop indefinitely.
This leads to a use-after-free when the interface is removed while
the zombie thread is still active.

Fix this by using atomic_xchg() to ensure the counter only transitions
from 1 to 0 once.

Fixes: 33a3bb4a3345 ("batman-adv: throughput meter implementation")
Cc: stable@kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Luxiao Xu <rakukuip@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
[sven: added missing change in batadv_tp_send]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/tp_meter.c