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 2DD3D2D9787; Thu, 28 May 2026 20:21:01 +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=1779999662; cv=none; b=AtpBjpFerXB/BqqWKCpMs8KUQH98uzvgyYS/LgTa5VxKLKdftDHwjfsokch/fCfyBsyqQNcG2E1bMSCjLidTFULslDA6GLx21JqpUkJe6hIiUuowF9P+IM9x6gkBejKYD4m4GC/BIepRltF8Ru+harGrFtr2eybiWWfoR9sJGCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779999662; c=relaxed/simple; bh=dJODmvuPfePY8VRvvWtYO75L0neDeS0TVXu4Hnrh0sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o8ajN4NvP5QzZ4/ex8So6ky0o7bVvh031cMzUhm8WH283efxA86Ho3hAqUYQBJPNfT+DFRZyUGbWldCRoUgUC3OtXES7YuCQOPDfcsfjoOWeKhE8iWotfcvevyRK2x6Kg6a0T2Kc7/g0hOEuEA6+4WVKSWPUsV4oKmKwWhckpzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZTU8fBtc; 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="ZTU8fBtc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92A921F000E9; Thu, 28 May 2026 20:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779999661; bh=fC5L5umEJrfbb3dCqgzg4NwlP3JjyvYMiVMRRBdHQ04=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZTU8fBtc3F5tpU6whCzkdaV4d6rhwlYspvC7Bv26XAY7ofEoiiiJmUISPGhT6yB6M 3fkldg8tE4ecPvuUZrPTkd7I5YD/hwpBn8rML24WvvffoRvoCNuzCcxpGCsdHpnI+I SdQW8YgpYDmxUHhXR6BWuTFJac/lMHJeDbrAjwkQ= 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 6.18 145/377] batman-adv: fix tp_meter counter underflow during shutdown Date: Thu, 28 May 2026 21:46:23 +0200 Message-ID: <20260528194642.571794562@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528194638.371537336@linuxfoundation.org> References: <20260528194638.371537336@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -451,7 +451,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; @@ -885,7 +885,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; }