From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EBDA4315F; Sat, 30 May 2026 18:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780167065; cv=none; b=IZwt0DPeKVLwggn4BYEIWE8Ju7Q4uJfZo+Guq4gm+TF91e7OBREotM9ZF7htP2qyU56mUwGl6dp3wx/0ynRNV0q39eDjHZas7kn60UURxn+qN5Sd9cr+JzMTbHwtyBIlHcTnh35trN2ApBFljP8elXV0XxnZ1Bs7a1bzf9RzNGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780167065; c=relaxed/simple; bh=tvYTNcJsvc1FJJ22zI3GdC3HRFQW2PJ7szWO6KvI4tI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fsfu2zf3Ei+B+VtNMo9+ChcACRrhcUrxls0aRlhVOwT+fW5k6alaXp3h/NvIqjn0TeXB+xRV4roA3OuGkx3wBR0XjeknH/AmXJKJRkJFS2mkjcwuCvHR4NZJ/Nr71owUQZMAEzwZ9gmX7Imf28O4NgMtQ7jpgEEEf2ck/7Y1exU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hzJ/nWx3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hzJ/nWx3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF9C51F00893; Sat, 30 May 2026 18:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780167064; bh=VTqJ8grYJnqePDxPihIytqTPyDSHqV7N70PLYVHgaeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hzJ/nWx3m2RE9YN9g6i/odnxdZElGgxIbDNGRQHQoaNpPNq3yILW2VOtrzxYMsr/t gsvDrWQtivYA6teXzq5+jbZ87FOrOQn/6q2XtQVvNNMqsS3sRO4qonZBR7gHfG1Jr5 BnN7xAIYq41t5sER+PLMkiAE2ksdAP/xIgNbK2fM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Yuan Tan , Yifan Wu , Juefei Pu , Xin Liu , Luxiao Xu , Ren Wei , Sven Eckelmann Subject: [PATCH 5.10 554/589] batman-adv: fix tp_meter counter underflow during shutdown Date: Sat, 30 May 2026 18:07:15 +0200 Message-ID: <20260530160239.218226839@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160224.570625122@linuxfoundation.org> References: <20260530160224.570625122@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Luxiao Xu commit 94f3b133168d1c49895e7cc6afbcf1cc0b354602 upstream. 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 Reported-by: Yifan Wu Reported-by: Juefei Pu Reported-by: Xin Liu Signed-off-by: Luxiao Xu Signed-off-by: Ren Wei [sven: added missing change in batadv_tp_send] Signed-off-by: Sven Eckelmann Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/tp_meter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/batman-adv/tp_meter.c +++ b/net/batman-adv/tp_meter.c @@ -435,7 +435,7 @@ static void batadv_tp_sender_end(struct static void batadv_tp_sender_shutdown(struct batadv_tp_vars *tp_vars, enum batadv_tp_meter_reason reason) { - if (!atomic_dec_and_test(&tp_vars->sending)) + if (atomic_xchg(&tp_vars->sending, 0) != 1) return; tp_vars->reason = reason; @@ -872,7 +872,7 @@ static int batadv_tp_send(void *arg) "Meter: %s() cannot send packets (%d)\n", __func__, err); /* ensure nobody else tries to stop the thread now */ - if (atomic_dec_and_test(&tp_vars->sending)) + if (atomic_xchg(&tp_vars->sending, 0) == 1) tp_vars->reason = err; break; }