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 29CC23E639C for ; Thu, 28 May 2026 11:57:13 +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=1779969435; cv=none; b=pJI4tFU+VLQyu0QL1pUN/BuLk1ija2u9Bj3OQpv/D/MQuPw0y1vgxx7KIvLfIpDydtzrlvJeFKS4RXtGEEDPIAYqwbLEkI4XFstukWpGuHqfvdGuoxgQqi/g0qN8WmtnyIZAKu25UEZINBe1i+SIbvYDyTRAmdyXCMDLGKINwko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779969435; c=relaxed/simple; bh=KsK/UtcTSG4CTA/o4uZZzqlKis2NYoLYOS7R6kHYql8=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=pLiB5pb//EIPs02Yzby44gg3mQewt6bGPiRvImuiTrjrbzSdfva/9FpT9YzS5J1lusoOiAUNIAn2/LmfQa+zQf8pG0LzO9t0RCKy8jCGunqIv80nxfUgMkDxinOANbOHpmfuHrtEfEcIYc9dyAn2hwPzX2BA0vjPNeCmzpzsy+Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uuENRZmk; 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="uuENRZmk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F2441F00A3A; Thu, 28 May 2026 11:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779969432; bh=rU4IvFaOGEjwnNwevk+UbGSgweC8LRdnY2D/fVK4Q3U=; h=Subject:To:Cc:From:Date; b=uuENRZmkbRRNMay55bkc1XbtniasOPSqws5csVwUf7/SpYUEZmItJ8P3pGPo7vIk6 M+J7sKOtUQ5CfIpvok10pROoX9nwXMJftYtKUwwt2xcEgyG2tpwSeuHiOXWQ9excYi YlvqdWznNexXHI9n+WZpmHzl9Q6RzumeyQLgJ374= Subject: FAILED: patch "[PATCH] batman-adv: tt: fix TOCTOU race for reported vlans" failed to apply to 5.15-stable tree To: sven@narfation.org Cc: From: Date: Thu, 28 May 2026 13:56:10 +0200 Message-ID: <2026052810-narrow-feast-bb41@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y git checkout FETCH_HEAD git cherry-pick -x 94d27005016be15ffc638b2ecbc4d58805ad7b48 # git commit -s git send-email --to '' --in-reply-to '2026052810-narrow-feast-bb41@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 94d27005016be15ffc638b2ecbc4d58805ad7b48 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sat, 2 May 2026 19:47:11 +0200 Subject: [PATCH] batman-adv: tt: fix TOCTOU race for reported vlans The local TT based TVLV is generated by first checking the number of VLANs which have at least one TT entry. A new buffer with the correct size for the VLANs is then allocated. Only then, the list of VLANs s used to fill the VLAN entries in the buffer. During this time, the meshif_vlan_list_lock is held. But the actual number of TT entries of each VLAN can still increase during this time - just not the number of VLANs in the list. But the prefilter used in the buffer size calculation might still cause an increase of the number of VLANs which need to be stored. Simply because a VLAN might now suddenly have at least one entry when it had none in the pre-alloc check - and then needs to occupy space which was not allocated. It is better to overestimate the buffer size at the beginning and then fill the buffer only with the VLANs which are not empty. Cc: stable@kernel.org Fixes: 16116dac2339 ("batman-adv: prevent TT request storms by not sending inconsistent TT TLVLs") Signed-off-by: Sven Eckelmann diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 06548dae1039..f009cbf8a276 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -887,11 +887,8 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, spin_lock_bh(&bat_priv->meshif_vlan_list_lock); hlist_for_each_entry(vlan, &bat_priv->meshif_vlan_list, list) { vlan_entries = atomic_read(&vlan->tt.num_entries); - if (vlan_entries < 1) - continue; - - num_vlan++; total_entries += vlan_entries; + num_vlan++; } change_offset = struct_size(*tt_data, vlan_data, num_vlan); @@ -916,6 +913,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, (*tt_data)->num_vlan = htons(num_vlan); tt_vlan = (*tt_data)->vlan_data; + num_vlan = 0; hlist_for_each_entry(vlan, &bat_priv->meshif_vlan_list, list) { vlan_entries = atomic_read(&vlan->tt.num_entries); if (vlan_entries < 1) @@ -926,8 +924,15 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, tt_vlan->reserved = 0; tt_vlan++; + num_vlan++; } + /* recalculate in case number of VLANs reduced */ + change_offset = struct_size(*tt_data, vlan_data, num_vlan); + tvlv_len = *tt_len + change_offset; + + (*tt_data)->num_vlan = htons(num_vlan); + tt_change_ptr = (u8 *)*tt_data + change_offset; *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;