FAILED: patch "[PATCH] batman-adv: Close OGM aggregation before transmission" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe 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 <[email protected]>.
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 f91f64a91682c07e6c5f059804e709656364e8a6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From f91f64a91682c07e6c5f059804e709656364e8a6 Mon Sep 17 00:00:00 2001
From: Chengfeng Ye <[email protected]>
Date: Sun, 27 Sep 2026 18:16:24 +0800
Subject: [PATCH] batman-adv: Close OGM aggregation before transmission
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1909,6 +1909,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BATADV_MAX_AGGREGATION_PACKETS ; +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -2047,7 +2047,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ DECLARE_BITMAP (direct_link_flags,BATADV_MAX_AGGREGATION_PACKETS ); -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BATADV_MAX_AGGREGATION_PACKETS (independent of the real number of +* aggregated packets) by the send worker to prevent further +* aggregation while the packet is emitted. It must therefore not be +* used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.53.0
Sven Eckelmann
maintainerPATCH 1/1 batman-adv: Close OGM aggregation before transmission
From: Chengfeng Ye <[email protected]>
commit f91f64a91682c07e6c5f059804e709656364e8a6 upstream.
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1794,6 +1794,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BITS_PER_TYPE (forw_packet->direct_link_flags); +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -2177,7 +2177,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ u32 direct_link_flags; -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BITS_PER_TYPE(forw_packet->direct_link_flags) (independent of the +* real number of aggregated packets) by the send worker to prevent +* further aggregation while the packet is emitted. It must therefore +* not be used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v2 1/2 batman-adv: Limit number of aggregated packets directly
In reply to Sasha Levincommit 434becf57bdc89f939db635ed3337b9d1da5967e upstream.
The currently selected size in BATADV_MAX_AGGREGATION_BYTES (512) is chosen such that the number of possible aggregated packets is lower than 32. This number must be limited so that the type of batadv_forw_packet->direct_link_flags has enough bits to represent each packet (with the size of at least 24 bytes).
This requirement is better implemented in code instead of having it inside a comment.
--- net/batman-adv/bat_iv_ogm.c | 4 ++++ net/batman-adv/main.h | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
net/batman-adv/bat_iv_ogm.c +4 -0
@@ -450,6 +450,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,struct batadv_ogm_packet *batadv_ogm_packet;int aggregated_bytes = forw_packet->packet_len + packet_len;struct batadv_hard_iface *primary_if =NULL ; +u8 packet_num = forw_packet->num_packets +1 ;bool res = false;unsigned long aggregation_end_time;
@@ -475,6 +476,9 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,if (aggregated_bytes >BATADV_MAX_AGGREGATION_BYTES )return false; +if (packet_num >=BITS_PER_TYPE (forw_packet->direct_link_flags)) +return false; +/* packet is not leaving on the same interface. */ if (forw_packet->if_outgoing != if_outgoing)return false;
net/batman-adv/main.h +0 -3
@@ -102,9 +102,6 @@*/ #define BATADV_TQ_SIMILARITY_THRESHOLD 50 -/* should not be bigger than 512 bytes or change the size of -* forw_packet->direct_link_flags -*/ #define BATADV_MAX_AGGREGATION_BYTES 512#define BATADV_MAX_AGGREGATION_MS 100
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v2 2/2 batman-adv: Close OGM aggregation before transmission
From: Chengfeng Ye <[email protected]>
commit f91f64a91682c07e6c5f059804e709656364e8a6 upstream.
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
---
v2:
- Submit together with the marked dependency commit 434becf57bdc ("batman-adv: Limit number of aggregated packets directly")
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1794,6 +1794,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BITS_PER_TYPE (forw_packet->direct_link_flags); +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -2177,7 +2177,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ u32 direct_link_flags; -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BITS_PER_TYPE(forw_packet->direct_link_flags) (independent of the +* real number of aggregated packets) by the send worker to prevent +* further aggregation while the packet is emitted. It must therefore +* not be used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.47.3