From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) (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 A2BEB39D6EC for ; Fri, 26 Jun 2026 16:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.160.73.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782490269; cv=none; b=dBt4dgeyuDLWZRgKYpzeaJKZZSHgn3LI9x3+R6gNacJjLAdoYxeldtMgH+Os4tT4E2TUcjCR5uZBEzN73SyXMsTb5n/hSkkBYN6ee96JqNtfYCPmdjsNu7M081TsNw2kX+sCNUkjx+nm/hSqlcCTWw9UiHtDLrRYT4OASuo+hxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782490269; c=relaxed/simple; bh=y5Ykj6SJSL1V82jrgCQzlpyJjApHNLHr8R1kIbKBDeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rwpm5ZxtjPMLJ/fu3ybYDdQyejegYys03v3dM0BTShIKt0GyAk+hz8HVe6eADTnlwd7ZErClLPOlwChYpmVBjRVBKvlzPCGqTceNDqaDmeIrrP8fGD50LrtNOvgEd9+TXDpOz+Oul4xEGAqhcDu42yiUrpPuETJH2khTN6doyU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=narfation.org; spf=pass smtp.mailfrom=narfation.org; dkim=pass (1024-bit key) header.d=narfation.org header.i=@narfation.org header.b=OneoV+zG; arc=none smtp.client-ip=213.160.73.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=narfation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=narfation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=narfation.org header.i=@narfation.org header.b="OneoV+zG" Received: by dvalin.narfation.org (Postfix) id 59BB4203F3; Fri, 26 Jun 2026 16:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1782490267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JpymKH7NQ2pJ0bVOD7UNuNWHR1oCPkondUHmKp6fAWQ=; b=OneoV+zGYawlXON8ukMPvfFVF3BrAwob9YcoWmNStiZaO3HZmx+fW0szBX7CmpA2G6y+k9 s0k90vEYbkrYS2tC0PDQk4F6piSsTsKZ9qseYVddAyGsQVZr112wLsUoL2e4uLxRkIS/oi 0ZGKQuCrPq6n7ZNq8u/jvoriqlTuFbY= From: Sven Eckelmann To: stable@vger.kernel.org Cc: Sven Eckelmann Subject: [PATCH 5.15 04/25] batman-adv: tp_meter: avoid window underflow Date: Fri, 26 Jun 2026 18:10:43 +0200 Message-ID: <20260626161105.124113-5-sven@narfation.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260626161105.124113-1-sven@narfation.org> References: <20260626161105.124113-1-sven@narfation.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit commit 765947b81fb54b6ebb0bc1cfe55c0fa399e002b8 upstream. In batadv_tp_avail(), win_left is calculated with 32-bit unsigned arithmetic: win_left = win_limit - tp_vars->last_sent; During Fast Recovery, cwnd is inflated and last_sent advances rapidly. When Fast Recovery ends, cwnd drops abruptly back to ss_threshold. If the newly shrunk win_limit is less than last_sent, the unsigned subtraction will underflow, wrapping to a massive positive value. Instead of returning that the window is full (unavailable), it returns that the sender can continue sending. To handle this situation, it must be checked whether the windows end sequence number (win_limit) has to be compared with the last sent sequence number. If it would be before the last sent sequence number, then more acks are needed before the transmission can be started again. Cc: stable@kernel.org Fixes: 33a3bb4a3345 ("batman-adv: throughput meter implementation") Signed-off-by: Sven Eckelmann --- net/batman-adv/tp_meter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c index f7b0ce3f8e2ae..3fd46999f3674 100644 --- a/net/batman-adv/tp_meter.c +++ b/net/batman-adv/tp_meter.c @@ -817,10 +817,15 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv, static bool batadv_tp_avail(struct batadv_tp_vars *tp_vars, size_t payload_len) { + u32 last_sent = READ_ONCE(tp_vars->last_sent); u32 win_left, win_limit; win_limit = atomic_read(&tp_vars->last_acked) + tp_vars->cwnd; - win_left = win_limit - tp_vars->last_sent; + + if (batadv_seq_before(last_sent, win_limit)) + win_left = win_limit - last_sent; + else + win_left = 0; return win_left >= payload_len; } -- 2.47.3