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 067CC2F8EA1; Thu, 28 May 2026 19:59:32 +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=1779998373; cv=none; b=WC4wwPETfq+rklzDfCyaKYDzt9c9xL0tfsdSgje7kgDMCfyXPCW9X7T/wBu5siHYqKlgUkOgLp9LJLfGjBwjXPOwGbSQuUjWexx/IdbgT/9byucsrVKeFGPuz4KISdVThE3QDnw+Y1dq6Xw8Win17cklc65q1c5XYxEmjRNlfEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779998373; c=relaxed/simple; bh=D4G8zQAeWmOPGuckCvbPxrcNsEGfNvm722HTykIhXdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ii20S+AMJbeoDCD1AFzfRp3eco5IS8WnvOiALvj7yuqGHGnMPOz22SuukO5jAWl2+yZLAyAqnfhp4brKQrzdNTAeAWujOa9+J8oG/56qVt1x5w1XvqNe2NXFvXRxL64vE+mxsGVQS6C0jEg9juMz76IdGgJD2Na2MgMIyeHMAHk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MeB+qCVt; 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="MeB+qCVt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B68B1F000E9; Thu, 28 May 2026 19:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779998371; bh=84sakPUglbjqslujxPWjh26zMijj8XmZZBW/iekqZqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MeB+qCVtnxAWFXuaS0DBfHk1OoAiTjhNnvkGjdffG28wO0xTsfzLfrY9isTMB/z/L m5/n27ZymIm3F/Hk2l0O9Nc0Cid5RGTguHlOsEk6QlXdYGvdS265+NZef/swnoezvm 6i1v0jEPkvs7Zxa5txRRjmFS7ebKnjV3UbwwFdhY= 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 7.0 149/461] batman-adv: fix tp_meter counter underflow during shutdown Date: Thu, 28 May 2026 21:44:38 +0200 Message-ID: <20260528194651.342225968@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528194646.819809818@linuxfoundation.org> References: <20260528194646.819809818@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 7.0-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; }