| 0/0 |
2026/02/25 01:12 |
flow |
assessment-kcsan |
11m
Results: map[Benign:true Confident:true Explanation:The data race occurs in `batadv_tt_local_add` in `net/batman-adv/translation-table.c` on the `tt_local->last_seen` field. This field is an `unsigned long` used to store the timestamp (in `jiffies`) of when a local client was last seen by the mesh interface.
### Analysis:
1. **Field Purpose**: The `last_seen` field is used by the purging mechanism (`batadv_tt_local_purge_list`) to determine if a local translation table entry has timed out and should be removed. It is a simple timestamp.
2. **Atomicity**: The race involves two concurrent writes of the `jiffies` value to the same memory location. On the x86_64 architecture where this was reported, 64-bit aligned writes are atomic. The memory address in the report (`0xffff8881047891c0`) is 64-byte aligned, ensuring that the 8-byte write is atomic and no partial or corrupted value will be stored.
3. **Impact**: Even if the two CPUs write slightly different `jiffies` values (if they are executing at slightly different times), the result is still a valid timestamp. Given that the timeout for purging entries is typically measured in minutes, a discrepancy of a few jiffies is irrelevant.
4. **Context**: The function `batadv_tt_local_add` is called for every packet transmitted through the mesh interface to register or update the local client's presence. The mesh interface is configured with `NETIF_F_LLTX`, allowing concurrent execution of the transmission path on multiple CPUs. The translation table is designed to handle this concurrency using RCU for lookups and bucket-level spinlocks for adding/removing entries, while updates to existing entries (like `last_seen` or `flags`) are performed without a global lock.
5. **Other Fields**: While other fields like `common.flags` might also be subject to similar races in this function, they are updated in a way that is either idempotent (setting the same flag) or self-correcting (the next packet will set the correct state). No pointers or complex structures are corrupted by this race.
### Conclusion:
The data race is **benign**. It is a common pattern in the network stack to update "last seen" timestamps without explicit synchronization when the consequences of a race are negligible and the performance benefit of avoiding a lock is significant.
Final Verdict: **Benign**]
|
| 1/1 |
2026/02/25 01:12 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/src/5cfff67191bde14790b404e6adb7a8cbc859c618]
|
| 2/1 |
2026/02/25 01:12 |
action |
kernel-builder |
3m
Results: map[KernelObj:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/build/be80aad46ab16320250a01455a6f12b667d10d47]
|
| 3/1 |
2026/02/25 01:16 |
action |
codesearch-prepare |
3m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/02/25 01:19 |
agent |
expert |
3m
Model:
Results: map[Benign:true Confident:true]
Instruction:
You are an experienced Linux kernel developer tasked with determining if the given kernel
data race is benign or not. The data race report is from KCSAN tool.
It contains 2 stack traces of the memory accesses that constitute a data race.
A "benign" data races are on a simple int/bool variable or similar field,
and the accesses are not supposed to be protected by any mutual exclusion primitives.
Common examples of such "benign" data races are accesses to various flags fields,
statistics counters, and similar. A "benign" data race does not lead to memory corruption/crash
with a conservative compiler that compiles memory accesses to primitive types
effectively as atomic.
A non-benign (or "harmful" data race) can lead to corruption/crash even with
a conservative compiler that compiles memory accesses to primitive types
effectively as atomic. A common example of a "harmful" data races is race on
a complex container (list/hashmap/etc), where accesses are supposed to be protected
by a mutual exclusion primitive.
Also consider races that happen at the same time with the given one.
If there is no synchronization in between, other memory accesses in the involved threads
race with each other if they access the same memory. For example, if both threads execute:
some_struct->have_elements = true;
list_add(new_node, &some_struct->list_head);
the race on some_struct->have_elements may appear benign, however it also implies there
is a race on some_struct->list_head which is not benign, since the list is not thread-safe.
Take into account that on 32-bit systems 64-bit memory accesses may be split into two accesses,
and thus even with a conservative compiler may not be fully atomic. However, such races may
still be benign depending on how writes are done, and how read data is used.
In the final reply explain why you think the given data race is benign or is harmful.
Use the provided tools to confirm any assumptions, variables/fields being accessed, etc.
In particular, don't make assumptions about the kernel source code,
use codesearch tools to read the actual source code.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The data race report is:
==================================================================
BUG: KCSAN: data-race in batadv_tt_local_add / batadv_tt_local_add
write to 0xffff8881047891c0 of 8 bytes by interrupt on cpu 1:
batadv_tt_local_add+0x16e/0x1050 net/batman-adv/translation-table.c:619
batadv_interface_tx+0x42b/0xae0 net/batman-adv/mesh-interface.c:236
__netdev_start_xmit include/linux/netdevice.h:5273 [inline]
netdev_start_xmit include/linux/netdevice.h:5282 [inline]
xmit_one net/core/dev.c:3866 [inline]
dev_hard_start_xmit+0x125/0x3e0 net/core/dev.c:3882
__dev_queue_xmit+0xdb1/0x1f20 net/core/dev.c:4832
dev_queue_xmit include/linux/netdevice.h:3381 [inline]
br_dev_queue_push_xmit+0x42d/0x4e0 net/bridge/br_forward.c:53
NF_HOOK include/linux/netfilter.h:318 [inline]
br_forward_finish+0x89/0x190 net/bridge/br_forward.c:66
br_nf_hook_thresh net/bridge/br_netfilter_hooks.c:-1 [inline]
br_nf_forward_finish+0x6ff/0x780 net/bridge/br_netfilter_hooks.c:662
NF_HOOK include/linux/netfilter.h:318 [inline]
br_nf_forward_arp net/bridge/br_netfilter_hooks.c:752 [inline]
br_nf_forward+0xae3/0xec0 net/bridge/br_netfilter_hooks.c:775
nf_hook_entry_hookfn include/linux/netfilter.h:158 [inline]
nf_hook_slow+0x78/0x180 net/netfilter/core.c:623
nf_hook include/linux/netfilter.h:273 [inline]
NF_HOOK include/linux/netfilter.h:316 [inline]
__br_forward+0x282/0x360 net/bridge/br_forward.c:115
deliver_clone net/bridge/br_forward.c:131 [inline]
maybe_deliver+0x1b8/0x280 net/bridge/br_forward.c:191
br_flood+0x21f/0x460 net/bridge/br_forward.c:238
br_handle_frame_finish+0xd96/0xfc0 net/bridge/br_input.c:229
nf_hook_bridge_pre net/bridge/br_input.c:313 [inline]
br_handle_frame+0x5f5/0xa30 net/bridge/br_input.c:442
__netif_receive_skb_core+0x5b1/0x1950 net/core/dev.c:6039
__netif_receive_skb_one_core net/core/dev.c:6150 [inline]
__netif_receive_skb+0x59/0x270 net/core/dev.c:6265
process_backlog+0x228/0x420 net/core/dev.c:6617
__napi_poll+0x5f/0x300 net/core/dev.c:7681
napi_poll net/core/dev.c:7744 [inline]
net_rx_action+0x452/0x930 net/core/dev.c:7896
handle_softirqs+0xb9/0x280 kernel/softirq.c:622
do_softirq+0x45/0x60 kernel/softirq.c:523
__local_bh_enable_ip+0x70/0x80 kernel/softirq.c:450
__raw_spin_unlock_bh include/linux/spinlock_api_smp.h:167 [inline]
_raw_spin_unlock_bh+0x18/0x20 kernel/locking/spinlock.c:210
spin_unlock_bh include/linux/spinlock.h:396 [inline]
__batadv_dat_purge net/batman-adv/distributed-arp-table.c:185 [inline]
batadv_dat_purge+0x1e3/0x270 net/batman-adv/distributed-arp-table.c:204
process_one_work kernel/workqueue.c:3257 [inline]
process_scheduled_works+0x4cd/0x9d0 kernel/workqueue.c:3340
worker_thread+0x581/0x770 kernel/workqueue.c:3421
kthread+0x488/0x510 kernel/kthread.c:463
ret_from_fork+0x148/0x280 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
write to 0xffff8881047891c0 of 8 bytes by interrupt on cpu 0:
batadv_tt_local_add+0x16e/0x1050 net/batman-adv/translation-table.c:619
batadv_interface_tx+0x42b/0xae0 net/batman-adv/mesh-interface.c:236
__netdev_start_xmit include/linux/netdevice.h:5273 [inline]
netdev_start_xmit include/linux/netdevice.h:5282 [inline]
xmit_one net/core/dev.c:3866 [inline]
dev_hard_start_xmit+0x125/0x3e0 net/core/dev.c:3882
__dev_queue_xmit+0xdb1/0x1f20 net/core/dev.c:4832
dev_queue_xmit include/linux/netdevice.h:3381 [inline]
br_dev_queue_push_xmit+0x42d/0x4e0 net/bridge/br_forward.c:53
NF_HOOK include/linux/netfilter.h:318 [inline]
br_forward_finish+0x89/0x190 net/bridge/br_forward.c:66
br_nf_hook_thresh net/bridge/br_netfilter_hooks.c:-1 [inline]
br_nf_forward_finish+0x6ff/0x780 net/bridge/br_netfilter_hooks.c:662
NF_HOOK include/linux/netfilter.h:318 [inline]
br_nf_forward_arp net/bridge/br_netfilter_hooks.c:752 [inline]
br_nf_forward+0xae3/0xec0 net/bridge/br_netfilter_hooks.c:775
nf_hook_entry_hookfn include/linux/netfilter.h:158 [inline]
nf_hook_slow+0x78/0x180 net/netfilter/core.c:623
nf_hook include/linux/netfilter.h:273 [inline]
NF_HOOK include/linux/netfilter.h:316 [inline]
__br_forward+0x282/0x360 net/bridge/br_forward.c:115
deliver_clone net/bridge/br_forward.c:131 [inline]
maybe_deliver+0x1b8/0x280 net/bridge/br_forward.c:191
br_flood+0x21f/0x460 net/bridge/br_forward.c:238
br_handle_frame_finish+0xd96/0xfc0 net/bridge/br_input.c:229
nf_hook_bridge_pre net/bridge/br_input.c:313 [inline]
br_handle_frame+0x5f5/0xa30 net/bridge/br_input.c:442
__netif_receive_skb_core+0x5b1/0x1950 net/core/dev.c:6039
__netif_receive_skb_one_core net/core/dev.c:6150 [inline]
__netif_receive_skb+0x59/0x270 net/core/dev.c:6265
process_backlog+0x228/0x420 net/core/dev.c:6617
__napi_poll+0x5f/0x300 net/core/dev.c:7681
napi_poll net/core/dev.c:7744 [inline]
net_rx_action+0x452/0x930 net/core/dev.c:7896
handle_softirqs+0xb9/0x280 kernel/softirq.c:622
run_ksoftirqd+0x1c/0x30 kernel/softirq.c:1063
smpboot_thread_fn+0x32a/0x510 kernel/smpboot.c:160
kthread+0x488/0x510 kernel/kthread.c:463
ret_from_fork+0x148/0x280 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
value changed: 0x00000000ffffbe11 -> 0x00000000ffffbe12
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 14 Comm: ksoftirqd/0 Not tainted syzkaller #0 PREEMPT(voluntary)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
==================================================================
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
net_ratelimit: 24713 callbacks suppressed
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on veth0_to_bridge with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
bridge0: received packet on bridge_slave_0 with own address as source address (addr:aa:aa:aa:aa:aa:0c, vlan:0)
Reply: The data race occurs in `batadv_tt_local_add` in `net/batman-adv/translation-table.c` on the `tt_local->last_seen` field. This field is an `unsigned long` used to store the timestamp (in `jiffies`) of when a local client was last seen by the mesh interface.
### Analysis:
1. **Field Purpose**: The `last_seen` field is used by the purging mechanism (`batadv_tt_local_purge_list`) to determine if a local translation table entry has timed out and should be removed. It is a simple timestamp.
2. **Atomicity**: The race involves two concurrent writes of the `jiffies` value to the same memory location. On the x86_64 architecture where this was reported, 64-bit aligned writes are atomic. The memory address in the report (`0xffff8881047891c0`) is 64-byte aligned, ensuring that the 8-byte write is atomic and no partial or corrupted value will be stored.
3. **Impact**: Even if the two CPUs write slightly different `jiffies` values (if they are executing at slightly different times), the result is still a valid timestamp. Given that the timeout for purging entries is typically measured in minutes, a discrepancy of a few jiffies is irrelevant.
4. **Context**: The function `batadv_tt_local_add` is called for every packet transmitted through the mesh interface to register or update the local client's presence. The mesh interface is configured with `NETIF_F_LLTX`, allowing concurrent execution of the transmission path on multiple CPUs. The translation table is designed to handle this concurrency using RCU for lookups and bucket-level spinlocks for adding/removing entries, while updates to existing entries (like `last_seen` or `flags`) are performed without a global lock.
5. **Other Fields**: While other fields like `common.flags` might also be subject to similar races in this function, they are updated in a way that is either idempotent (setting the same flag) or self-correcting (the next packet will set the correct state). No pointers or complex structures are corrupted by this race.
### Conclusion:
The data race is **benign**. It is a common pattern in the network stack to update "last seen" timestamps without explicit synchronization when the consequences of a race are negligible and the performance benefit of avoiding a lock is significant.
Final Verdict: **Benign**
|
| 5/2 |
2026/02/25 01:19 |
llm |
expert |
0m
Model:
Tokens:
input: 6536
output: 49
thoughts: 129
Thoughts: **Analyzing a Data Race in `batadv_tt_local_add`**
Okay, so I've got a data race on my hands. The crash report points directly to `batadv_tt_local_add` in `net/batman-adv/translation-table.c:619`. Interesting. Looking at the identical stacks from both CPUs, I'm seeing a concurrent write to the *exact* same memory address. Classic data race scenario. The value shifted from `0x00000000ffffbe11` to `0x00000000ffffbe12`. That smells like a simple increment of a counter or maybe a timestamp being updated, which makes this both easier and harder to debug. The location alone makes me suspect it's some kind of tracking variable related to the translation table.
Time to dive into the code at `net/batman-adv/translation-table.c:619` and see what's *actually* happening at that line. Gotta figure out the critical section and determine if it's protected properly, or where the synchronization failure is. I can already imagine that it's likely incrementing a counter used to track the local translation table entries, so I'll need to figure out what controls access to that.
|
| 6/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_local_add]
Results: map[SourceCode: 576: /**
577: * batadv_tt_local_add() - add a new client to the local table or update an
578: * existing client
579: * @mesh_iface: netdev struct of the mesh interface
580: * @addr: the mac address of the client to add
581: * @vid: VLAN identifier
582: * @ifindex: index of the interface where the client is connected to (useful to
583: * identify wireless clients)
584: * @mark: the value contained in the skb->mark field of the received packet (if
585: * any)
586: *
587: * Return: true if the client was successfully added, false otherwise.
588: */
589: bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
590: unsigned short vid, int ifindex, u32 mark)
591: {
592: struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
593: struct batadv_tt_local_entry *tt_local;
594: struct batadv_tt_global_entry *tt_global = NULL;
595: struct net *net = dev_net(mesh_iface);
596: struct batadv_meshif_vlan *vlan;
597: struct net_device *in_dev = NULL;
598: struct batadv_hard_iface *in_hardif = NULL;
599: struct hlist_head *head;
600: struct batadv_tt_orig_list_entry *orig_entry;
601: int hash_added, table_size, packet_size_max;
602: bool ret = false;
603: bool roamed_back = false;
604: u8 remote_flags;
605: u32 match_mark;
606:
607: if (ifindex != BATADV_NULL_IFINDEX)
608: in_dev = dev_get_by_index(net, ifindex);
609:
610: if (in_dev)
611: in_hardif = batadv_hardif_get_by_netdev(in_dev);
612:
613: tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
614:
615: if (!is_multicast_ether_addr(addr))
616: tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
617:
618: if (tt_local) {
619: tt_local->last_seen = jiffies;
620: if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
621: batadv_dbg(BATADV_DBG_TT, bat_priv,
622: "Re-adding pending client %pM (vid: %d)\n",
623: addr, batadv_print_vid(vid));
624: /* whatever the reason why the PENDING flag was set,
625: * this is a client which was enqueued to be removed in
626: * this orig_interval. Since it popped up again, the
627: * flag can be reset like it was never enqueued
628: */
629: tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
630: goto add_event;
631: }
632:
633: if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
634: batadv_dbg(BATADV_DBG_TT, bat_priv,
635: "Roaming client %pM (vid: %d) came back to its original location\n",
636: addr, batadv_print_vid(vid));
637: /* the ROAM flag is set because this client roamed away
638: * and the node got a roaming_advertisement message. Now
639: * that the client popped up again at its original
640: * location such flag can be unset
641: */
642: tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
643: roamed_back = true;
644: }
645: goto check_roaming;
646: }
647:
648: /* Ignore the client if we cannot send it in a full table response. */
649: table_size = batadv_tt_local_table_transmit_size(bat_priv);
650: table_size += batadv_tt_len(1);
651: packet_size_max = atomic_read(&bat_priv->packet_size_max);
652: if (table_size > packet_size_max) {
653: net_ratelimited_function(batadv_info, mesh_iface,
654: "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
655: table_size, packet_size_max, addr);
656: goto out;
657: }
658:
659: tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC);
660: if (!tt_local)
661: goto out;
662:
663: /* increase the refcounter of the related vlan */
664: vlan = batadv_meshif_vlan_get(bat_priv, vid);
665: if (!vlan) {
666: net_ratelimited_function(batadv_info, mesh_iface,
667: "adding TT local entry %pM to non-existent VLAN %d\n",
668: addr, batadv_print_vid(vid));
669: kmem_cache_free(batadv_tl_cache, tt_local);
670: tt_local = NULL;
671: goto out;
672: }
673:
674: batadv_dbg(BATADV_DBG_TT, bat_priv,
675: "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
676: addr, batadv_print_vid(vid),
677: (u8)atomic_read(&bat_priv->tt.vn));
678:
679: ether_addr_copy(tt_local->common.addr, addr);
680: /* The local entry has to be marked as NEW to avoid to send it in
681: * a full table response going out before the next ttvn increment
682: * (consistency check)
683: */
684: tt_local->common.flags = BATADV_TT_CLIENT_NEW;
685: tt_local->common.vid = vid;
686: if (batadv_is_wifi_hardif(in_hardif))
687: tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
688: kref_init(&tt_local->common.refcount);
689: tt_local->last_seen = jiffies;
690: tt_local->common.added_at = tt_local->last_seen;
691: tt_local->vlan = vlan;
692:
693: /* the batman interface mac and multicast addresses should never be
694: * purged
695: */
696: if (batadv_compare_eth(addr, mesh_iface->dev_addr) ||
697: is_multicast_ether_addr(addr))
698: tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
699:
700: kref_get(&tt_local->common.refcount);
701: hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
702: batadv_choose_tt, &tt_local->common,
703: &tt_local->common.hash_entry);
704:
705: if (unlikely(hash_added != 0)) {
706: /* remove the reference for the hash */
707: batadv_tt_local_entry_put(tt_local);
708: goto out;
709: }
710:
711: add_event:
712: batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
713:
714: check_roaming:
715: /* Check whether it is a roaming, but don't do anything if the roaming
716: * process has already been handled
717: */
718: if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
719: /* These node are probably going to update their tt table */
720: head = &tt_global->orig_list;
721: rcu_read_lock();
722: hlist_for_each_entry_rcu(orig_entry, head, list) {
723: batadv_send_roam_adv(bat_priv, tt_global->common.addr,
724: tt_global->common.vid,
725: orig_entry->orig_node);
726: }
727: rcu_read_unlock();
728: if (roamed_back) {
729: batadv_tt_global_free(bat_priv, tt_global,
730: "Roaming canceled");
731: } else {
732: /* The global entry has to be marked as ROAMING and
733: * has to be kept for consistency purpose
734: */
735: tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
736: tt_global->roam_at = jiffies;
737: }
738: }
739:
740: /* store the current remote flags before altering them. This helps
741: * understanding is flags are changing or not
742: */
743: remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
744:
745: if (batadv_is_wifi_hardif(in_hardif))
746: tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
747: else
748: tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
749:
750: /* check the mark in the skb: if it's equal to the configured
751: * isolation_mark, it means the packet is coming from an isolated
752: * non-mesh client
753: */
754: match_mark = (mark & bat_priv->isolation_mark_mask);
755: if (bat_priv->isolation_mark_mask &&
756: match_mark == bat_priv->isolation_mark)
757: tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA;
758: else
759: tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA;
760:
761: /* if any "dynamic" flag has been modified, resend an ADD event for this
762: * entry so that all the nodes can get the new flags
763: */
764: if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK))
765: batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
766:
767: ret = true;
768: out:
769: batadv_hardif_put(in_hardif);
770: dev_put(in_dev);
771: batadv_tt_local_entry_put(tt_local);
772: batadv_tt_global_entry_put(tt_global);
773: return ret;
774: }
SourceFile:net/batman-adv/translation-table.c]
|
| 7/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 10509
output: 47
thoughts: 216
Thoughts: **Analyzing the Race Condition**
Okay, so the report points to line 619, where we're writing to `tt_local->last_seen`. This is clearly a write operation, and the report mentions that both threads are executing `batadv_tt_local_add`. Hmm, if both threads are hitting the same `tt_local` entry, that means they must have both found the *same* entry in the hash table, accessed via `batadv_tt_local_hash_find` on line 613. That's a key observation. We've got two threads racing to update the same `tt_local` structure.
Now, the natural question is, what locking is in place to protect this? I need to check the `batadv_tt_local_add` function itself. I don't immediately see any obvious mutexes or spinlocks in the code snippet.
The stack traces are showing `batadv_interface_tx` calling `batadv_tt_local_add`, which makes sense in the overall architecture. Now I need to investigate `batadv_interface_tx` and what it's doing around that call to determine whether contention is actually possible.
|
| 8/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/mesh-interface.c IncludeLines:true Name:batadv_interface_tx]
Results: map[SourceCode: 167: static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
168: struct net_device *mesh_iface)
169: {
170: struct ethhdr *ethhdr;
171: struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
172: struct batadv_hard_iface *primary_if = NULL;
173: struct batadv_bcast_packet *bcast_packet;
174: static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
175: 0x00, 0x00};
176: static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
177: 0x00, 0x00};
178: enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;
179: u8 *dst_hint = NULL, chaddr[ETH_ALEN];
180: struct vlan_ethhdr *vhdr;
181: unsigned int header_len = 0;
182: int data_len = skb->len, ret;
183: unsigned long brd_delay = 0;
184: bool do_bcast = false, client_added;
185: unsigned short vid;
186: u32 seqno;
187: int gw_mode;
188: enum batadv_forw_mode forw_mode = BATADV_FORW_BCAST;
189: int mcast_is_routable = 0;
190: int network_offset = ETH_HLEN;
191: __be16 proto;
192:
193: if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
194: goto dropped;
195:
196: /* reset control block to avoid left overs from previous users */
197: memset(skb->cb, 0, sizeof(struct batadv_skb_cb));
198:
199: netif_trans_update(mesh_iface);
200: vid = batadv_get_vid(skb, 0);
201:
202: skb_reset_mac_header(skb);
203: ethhdr = eth_hdr(skb);
204:
205: proto = ethhdr->h_proto;
206:
207: switch (ntohs(proto)) {
208: case ETH_P_8021Q:
209: if (!pskb_may_pull(skb, sizeof(*vhdr)))
210: goto dropped;
211: vhdr = vlan_eth_hdr(skb);
212: proto = vhdr->h_vlan_encapsulated_proto;
213:
214: /* drop batman-in-batman packets to prevent loops */
215: if (proto != htons(ETH_P_BATMAN)) {
216: network_offset += VLAN_HLEN;
217: break;
218: }
219:
220: fallthrough;
221: case ETH_P_BATMAN:
222: goto dropped;
223: }
224:
225: skb_set_network_header(skb, network_offset);
226:
227: if (batadv_bla_tx(bat_priv, skb, vid))
228: goto dropped;
229:
230: /* skb->data might have been reallocated by batadv_bla_tx() */
231: ethhdr = eth_hdr(skb);
232:
233: /* Register the client MAC in the transtable */
234: if (!is_multicast_ether_addr(ethhdr->h_source) &&
235: !batadv_bla_is_loopdetect_mac(ethhdr->h_source)) {
236: client_added = batadv_tt_local_add(mesh_iface, ethhdr->h_source,
237: vid, skb->skb_iif,
238: skb->mark);
239: if (!client_added)
240: goto dropped;
241: }
242:
243: /* Snoop address candidates from DHCPACKs for early DAT filling */
244: batadv_dat_snoop_outgoing_dhcp_ack(bat_priv, skb, proto, vid);
245:
246: /* don't accept stp packets. STP does not help in meshes.
247: * better use the bridge loop avoidance ...
248: *
249: * The same goes for ECTP sent at least by some Cisco Switches,
250: * it might confuse the mesh when used with bridge loop avoidance.
251: */
252: if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
253: goto dropped;
254:
255: if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
256: goto dropped;
257:
258: gw_mode = atomic_read(&bat_priv->gw.mode);
259: if (is_multicast_ether_addr(ethhdr->h_dest)) {
260: /* if gw mode is off, broadcast every packet */
261: if (gw_mode == BATADV_GW_MODE_OFF) {
262: do_bcast = true;
263: goto send;
264: }
265:
266: dhcp_rcp = batadv_gw_dhcp_recipient_get(skb, &header_len,
267: chaddr);
268: /* skb->data may have been modified by
269: * batadv_gw_dhcp_recipient_get()
270: */
271: ethhdr = eth_hdr(skb);
272: /* if gw_mode is on, broadcast any non-DHCP message.
273: * All the DHCP packets are going to be sent as unicast
274: */
275: if (dhcp_rcp == BATADV_DHCP_NO) {
276: do_bcast = true;
277: goto send;
278: }
279:
280: if (dhcp_rcp == BATADV_DHCP_TO_CLIENT)
281: dst_hint = chaddr;
282: else if ((gw_mode == BATADV_GW_MODE_SERVER) &&
283: (dhcp_rcp == BATADV_DHCP_TO_SERVER))
284: /* gateways should not forward any DHCP message if
285: * directed to a DHCP server
286: */
287: goto dropped;
288:
289: send:
290: if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
291: forw_mode = batadv_mcast_forw_mode(bat_priv, skb, vid,
292: &mcast_is_routable);
293: switch (forw_mode) {
294: case BATADV_FORW_BCAST:
295: break;
296: case BATADV_FORW_UCASTS:
297: case BATADV_FORW_MCAST:
298: do_bcast = false;
299: break;
300: case BATADV_FORW_NONE:
301: fallthrough;
302: default:
303: goto dropped;
304: }
305: }
306: }
307:
308: batadv_skb_set_priority(skb, 0);
309:
310: /* ethernet packet should be broadcasted */
311: if (do_bcast) {
312: primary_if = batadv_primary_if_get_selected(bat_priv);
313: if (!primary_if)
314: goto dropped;
315:
316: /* in case of ARP request, we do not immediately broadcasti the
317: * packet, instead we first wait for DAT to try to retrieve the
318: * correct ARP entry
319: */
320: if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
321: brd_delay = msecs_to_jiffies(ARP_REQ_DELAY);
322:
323: if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
324: goto dropped;
325:
326: bcast_packet = (struct batadv_bcast_packet *)skb->data;
327: bcast_packet->version = BATADV_COMPAT_VERSION;
328: bcast_packet->ttl = BATADV_TTL - 1;
329:
330: /* batman packet type: broadcast */
331: bcast_packet->packet_type = BATADV_BCAST;
332: bcast_packet->reserved = 0;
333:
334: /* hw address of first interface is the orig mac because only
335: * this mac is known throughout the mesh
336: */
337: ether_addr_copy(bcast_packet->orig,
338: primary_if->net_dev->dev_addr);
339:
340: /* set broadcast sequence number */
341: seqno = atomic_inc_return(&bat_priv->bcast_seqno);
342: bcast_packet->seqno = htonl(seqno);
343:
344: batadv_send_bcast_packet(bat_priv, skb, brd_delay, true);
345: /* unicast packet */
346: } else {
347: /* DHCP packets going to a server will use the GW feature */
348: if (dhcp_rcp == BATADV_DHCP_TO_SERVER) {
349: ret = batadv_gw_out_of_range(bat_priv, skb);
350: if (ret)
351: goto dropped;
352: ret = batadv_send_skb_via_gw(bat_priv, skb, vid);
353: } else if (forw_mode == BATADV_FORW_UCASTS) {
354: ret = batadv_mcast_forw_send(bat_priv, skb, vid,
355: mcast_is_routable);
356: } else if (forw_mode == BATADV_FORW_MCAST) {
357: ret = batadv_mcast_forw_mcsend(bat_priv, skb);
358: } else {
359: if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
360: skb))
361: goto dropped;
362:
363: batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
364:
365: ret = batadv_send_skb_via_tt(bat_priv, skb, dst_hint,
366: vid);
367: }
368: if (ret != NET_XMIT_SUCCESS)
369: goto dropped_freed;
370: }
371:
372: batadv_inc_counter(bat_priv, BATADV_CNT_TX);
373: batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
374: goto end;
375:
376: dropped:
377: kfree_skb(skb);
378: dropped_freed:
379: batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
380: end:
381: batadv_hardif_put(primary_if);
382: return NETDEV_TX_OK;
383: }
SourceFile:net/batman-adv/mesh-interface.c]
|
| 9/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 14623
output: 51
thoughts: 162
Thoughts: **Analyzing the batadv_interface_tx Function**
Okay, so I'm looking into the `batadv_interface_tx` function, specifically at this line: `client_added = batadv_tt_local_add(mesh_iface, ethhdr->h_source,`. This is where the local client is registered for every outgoing packet. Makes sense. The immediate concern that pops into my head is the race condition on `tt_local->last_seen = jiffies;`. If packets from the same MAC are hitting different CPUs concurrently, `batadv_tt_local_add` will be invoked concurrently, and we need to verify whether the updates to `last_seen` are protected.
Now, `batadv_tt_local_add` then calls `batadv_tt_local_hash_find`, which suggests a hash table lookup. The crucial question is whether *that* function, or the hash table itself, utilizes any locking mechanisms. I need to dig into the implementation of `batadv_tt_local_hash_find` and the hash table's access methods to determine if there's any concurrent access protection. This is where the race condition would be exposed, and where the solution to ensure data consistency would likely lie.
|
| 10/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_local_hash_find]
Results: map[SourceCode: 162: /**
163: * batadv_tt_local_hash_find() - search the local table for a given client
164: * @bat_priv: the bat priv with all the mesh interface information
165: * @addr: the mac address of the client to look for
166: * @vid: VLAN identifier
167: *
168: * Return: a pointer to the corresponding tt_local_entry struct if the client is
169: * found, NULL otherwise.
170: */
171: static struct batadv_tt_local_entry *
172: batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
173: unsigned short vid)
174: {
175: struct batadv_tt_common_entry *tt_common_entry;
176: struct batadv_tt_local_entry *tt_local_entry = NULL;
177:
178: tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
179: vid);
180: if (tt_common_entry)
181: tt_local_entry = container_of(tt_common_entry,
182: struct batadv_tt_local_entry,
183: common);
184: return tt_local_entry;
185: }
SourceFile:net/batman-adv/translation-table.c]
|
| 11/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 15543
output: 49
thoughts: 11
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Delving into the `batadv_tt_hash_find` Function**
Alright, so I'm thinking about the `batadv_tt_hash_find` function within the BATMAN Advanced framework. Specifically, I need to really understand how this function works. It seems pretty critical, as it's the gateway for retrieving information from the TT (Topology Table) hash. Let's break this down further in my mind, considering how the hash works in conjunction with the TT data structures. I need to check how they are related.
First, I need to remind myself of the hashing algorithm used. Is it a simple modulo, or something more sophisticated designed for collision avoidance given the network topology characteristics? What's the impact of the hash size?
Next, how exactly does this function handle collisions? Does it employ chaining, open addressing, or something else entirely? The collision resolution strategy will directly impact lookup time, especially under heavy network load and frequent topology changes. I should see if there are performance considerations given any of this.
Then, there's the question of the lookup key. What data is used as the key to retrieve entries? Is it a simple MAC address, a combination of addresses, or something more complex? I need to understand the implications of the key structure on search efficiency, especially when dealing with multicast or broadcast scenarios.
Finally, I have to consider the locking mechanisms. Given that this function accesses shared data structures, there *must* be concurrency control. Is it a read-write lock, a spinlock, or something else? How fine-grained is the locking? Are we at risk of contention bottlenecks, especially with many concurrent packet flows?
|
| 12/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_hash_find]
Results: map[SourceCode: 117: /**
118: * batadv_tt_hash_find() - look for a client in the given hash table
119: * @hash: the hash table to search
120: * @addr: the mac address of the client to look for
121: * @vid: VLAN identifier
122: *
123: * Return: a pointer to the tt_common struct belonging to the searched client if
124: * found, NULL otherwise.
125: */
126: static struct batadv_tt_common_entry *
127: batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,
128: unsigned short vid)
129: {
130: struct hlist_head *head;
131: struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
132: u32 index;
133:
134: if (!hash)
135: return NULL;
136:
137: ether_addr_copy(to_search.addr, addr);
138: to_search.vid = vid;
139:
140: index = batadv_choose_tt(&to_search, hash->size);
141: head = &hash->table[index];
142:
143: rcu_read_lock();
144: hlist_for_each_entry_rcu(tt, head, hash_entry) {
145: if (!batadv_compare_eth(tt, addr))
146: continue;
147:
148: if (tt->vid != vid)
149: continue;
150:
151: if (!kref_get_unless_zero(&tt->refcount))
152: continue;
153:
154: tt_tmp = tt;
155: break;
156: }
157: rcu_read_unlock();
158:
159: return tt_tmp;
160: }
SourceFile:net/batman-adv/translation-table.c]
|
| 13/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 16617
output: 47
thoughts: 537
Thoughts: **Analyzing Potential Race Conditions in `batadv_tt_local_add`**
Okay, so I'm looking at this `batadv_tt_local_add` function and it's starting to raise some red flags. The code snippet I'm focused on involves how we're handling the `tt_local` entry after it's been retrieved. My understanding is that `batadv_tt_hash_find` uses RCU to get a pointer to the entry, and that pointer comes with an incremented refcount, which is good for safety.
However, I'm noticing modifications to the `tt_local->common.flags` field within this function, specifically at lines 629, 642, 746, and 748, as well as 757 and 759. These flags are not being updated atomically, which is a problem. The original report mentioned `last_seen`, but it didn't call out these other fields.
If two threads call this function concurrently, it's very possible that they could overwrite each other's changes to the `flags` field. That would be a race condition. It looks like `last_seen` is also getting updated, `tt_local->last_seen = jiffies;`, and that's an `unsigned long` so we should consider its size implications with concurrent access as well.
I need to confirm the definition of `struct batadv_tt_local_entry` to see exactly what other data is in there, but my initial impression is that this section of code requires further investigation to ensure thread safety. We need to be using atomic operations or some kind of synchronization to protect these `flags` updates.
|
| 14/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/types.h IncludeLines:true Name:batadv_tt_local_entry]
Results: map[SourceCode:1776: /**
1777: * struct batadv_tt_local_entry - translation table local entry data
1778: */
1779: struct batadv_tt_local_entry {
1780: /** @common: general translation table data */
1781: struct batadv_tt_common_entry common;
1782:
1783: /** @last_seen: timestamp used for purging stale tt local entries */
1784: unsigned long last_seen;
1785:
1786: /** @vlan: mesh-interface vlan of the entry */
1787: struct batadv_meshif_vlan *vlan;
1788: };
SourceFile:net/batman-adv/types.h]
|
| 15/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 17789
output: 47
thoughts: 12
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the Structure of `batadv_tt_common_entry`**
Alright, let's dive into this. I'm looking at `struct batadv_tt_common_entry`. My initial thought is to immediately consider its place within the broader BATMAN-adv topology table and how it interacts with the rest of the mesh network's data structures. Specifically, I need to understand what this "common" implies. Is this a shared component for different types of topology entries? Is it a base structure that others inherit from? It definitely suggests a fundamental building block.
My immediate questions are related to performance. How is this structured for lookups and modifications? What are the synchronization primitives used to manage concurrent access to instances of this structure across different threads and potentially different CPUs? Are there any potential bottlenecks I should anticipate, given its likely widespread use within the TT? The "common" aspect likely means a lot of traffic will be using this so any inherent issues will become magnified.
I also need to see if it makes use of any atomics or lock-free techniques. If it's the core of the TT and involves frequent updates or lookups, the right selection of data structures and concurrent programming techniques will be crucial for scalability.
Finally, I'll be looking for potential memory alignment considerations. Does the structure itself, or any of its embedded members, have any alignment requirements that might impact performance or cause unexpected issues on different architectures? I need to be aware of any potential padding and how that might affect cache line utilization during lookups and updates. Time to dig in and see the details of this structure, especially in the context of the overall topology table.
|
| 16/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/types.h IncludeLines:true Name:batadv_tt_common_entry]
Results: map[SourceCode:1747: /**
1748: * struct batadv_tt_common_entry - tt local & tt global common data
1749: */
1750: struct batadv_tt_common_entry {
1751: /** @addr: mac address of non-mesh client */
1752: u8 addr[ETH_ALEN];
1753:
1754: /** @vid: VLAN identifier */
1755: unsigned short vid;
1756:
1757: /**
1758: * @hash_entry: hlist node for &batadv_priv_tt.local_hash or for
1759: * &batadv_priv_tt.global_hash
1760: */
1761: struct hlist_node hash_entry;
1762:
1763: /** @flags: various state handling flags (see batadv_tt_client_flags) */
1764: u16 flags;
1765:
1766: /** @added_at: timestamp used for purging stale tt common entries */
1767: unsigned long added_at;
1768:
1769: /** @refcount: number of contexts the object is used */
1770: struct kref refcount;
1771:
1772: /** @rcu: struct used for freeing in an RCU-safe manner */
1773: struct rcu_head rcu;
1774: };
SourceFile:net/batman-adv/types.h]
|
| 17/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 18646
output: 21
thoughts: 522
Thoughts: **Analyzing Potential Race Conditions in BATMAN-Adv's TT Local Table Updates**
Okay, so I'm digging into this BATMAN-Adv code, specifically looking at potential concurrency issues. The timestamp update on `last_seen` โ that's likely fine. It's just a timestamp, so even if there's a race, the worst that happens is a slightly skewed timestamp, which is negligible in terms of data integrity.
However, the `flags` field, a `u16`, is where things get interesting. I see several read-modify-write operations on this field within `batadv_tt_local_add`. Lines 629, 642, 746, 748, 757, and 759 are all modifying `tt_local->common.flags`. If two CPU cores hit these operations simultaneously, we could easily have lost updates. That's a classic race condition scenario. The question is, is this code protected? Is there a lock in place?
My next step is to trace the execution path of `batadv_tt_local_add` to figure out if it's called under any kind of mutex or lock. Looking at the stack trace, I see it's called from `batadv_interface_tx`. Alright, `batadv_interface_tx` is essentially the `ndo_start_xmit` handler for the mesh interface. Normally, `ndo_start_xmit` is called with the netdev tx lock held. That's good, that *should* protect us... but with virtual devices, there's always a chance this isn't true.
Ah, I'm digging deeper, and the stack trace reveals that `batadv_interface_tx` is called from `dev_hard_start_xmit`.
Wait, this is a bit more concerning now... the full trace is: `__br_forward` -> `maybe_deliver` -> `br_flood` -> `br_dev_queue_push_xmit` -> `dev_queue_xmit` -> `__dev_queue_xmit` -> `dev_hard_start_xmit` -> `batadv_interface_tx`.
If the Linux bridge is in flooding mode, it means `dev_queue_xmit` might be called on multiple ports concurrently. Now we're talking about *real* potential for concurrent access and data corruption. This isn't just a theoretical concern anymore.
I need to confirm if BATMAN-Adv is using `NETIF_F_LLTX` (low-level transmit) flag, because the implications here are that we're dealing with multiple CPUs accessing the `tt_local` at the same time and we need to verify if the code already has a lock to protect concurrent access. This is going to be my next investigation.
|
| 18/2 |
2026/02/25 01:20 |
tool |
grepper |
0m
Error:
Args: map[Expression:NETIF_F_LLTX]
Results:
|
| 19/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 19813
output: 50
thoughts: 10
Thoughts: Okay, here's my summary, tailored for an expert audience, as if it's my own thought process:
**Mesh Interface Diagnostics - A Quick Sanity Check**
Alright, before I dive too deep into this problem, I'm getting a nagging feeling. *Something* is off. Before I start debugging the code or second-guessing the model parameters, let me just take a quick step back and make sure the foundational stuff is solid. Specifically, I need to confirm the mesh interface setup is behaving as expected. Are the connections correct? Is the data being mapped appropriately? Are the boundary conditions consistent across the interface? Even the most elegant solution crumbles on a bad foundation. Gotta rule out the obvious first, and that means a quick diagnostic pass on the mesh connectivity. It's often the root cause of these head-scratchers.
|
| 20/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:net/batman-adv/mesh-interface.c IncludeLines:true Name:batadv_softif_init_early]
Results: map[SourceCode: SourceFile:]
|
| 21/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 20069
output: 31
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:
**Tracing the Mesh Interface Initialization**
Alright, let's get down to brass tacks. I need to pinpoint the exact location where the mesh interface is initially set up. I'm assuming it's probably not a simple, isolated call somewhere. Given the complexity I expect, I'm thinking I'll need to follow a breadcrumb trail. My first step is to identify the initialization. Itโs a standard approach - understanding where the "start" is the first step in understanding the whole process.
|
| 22/2 |
2026/02/25 01:20 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:net/batman-adv/mesh-interface.c]
Results: map[Entities:[map[Kind:function Name:batadv_get_drvinfo] map[Kind:function Name:batadv_get_ethtool_stats] map[Kind:function Name:batadv_get_sset_count] map[Kind:function Name:batadv_get_strings] map[Kind:function Name:batadv_interface_add_vid] map[Kind:function Name:batadv_interface_change_mtu] map[Kind:function Name:batadv_interface_kill_vid] map[Kind:function Name:batadv_interface_rx] map[Kind:function Name:batadv_interface_set_mac_addr] map[Kind:function Name:batadv_interface_set_rx_mode] map[Kind:function Name:batadv_interface_stats] map[Kind:function Name:batadv_interface_tx] map[Kind:function Name:batadv_meshif_create_vlan] map[Kind:function Name:batadv_meshif_destroy_netlink] map[Kind:function Name:batadv_meshif_destroy_vlan] map[Kind:function Name:batadv_meshif_free] map[Kind:function Name:batadv_meshif_init_early] map[Kind:function Name:batadv_meshif_init_late] map[Kind:function Name:batadv_meshif_is_valid] map[Kind:function Name:batadv_meshif_newlink] map[Kind:function Name:batadv_meshif_slave_add] map[Kind:function Name:batadv_meshif_slave_del] map[Kind:function Name:batadv_meshif_validate] map[Kind:function Name:batadv_meshif_vlan_get] map[Kind:function Name:batadv_meshif_vlan_release] map[Kind:function Name:batadv_set_lockdep_class] map[Kind:function Name:batadv_set_lockdep_class_one] map[Kind:function Name:batadv_skb_head_push] map[Kind:function Name:batadv_sum_counter] map[Kind:global_variable Name:batadv_counters_strings] map[Kind:global_variable Name:batadv_ethtool_ops] map[Kind:global_variable Name:batadv_ifla_policy] map[Kind:global_variable Name:batadv_link_ops] map[Kind:global_variable Name:batadv_netdev_ops]]]
|
| 23/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 20915
output: 50
thoughts: 17
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they were my own immediate processing:
**Initial Assessment: Diving into batadv_meshif_init_early**
Right, so I'm looking at this initialization sequence, and it looks like `batadv_meshif_init_early` is the key function to focus on here. That name gives it away, doesn't it? "Early" suggests this is where a lot of the foundational work for the BATMAN advanced mesh interface (batadv) begins. I'm guessing this function is responsible for setting up the basic data structures, maybe registering some initial handlers, and potentially dealing with early hardware configurations or resource allocation before we get into the more complex parts of the system. I would expect it to be setting up the core batadv_meshif structure. I need to dig in and confirm that, of course, but that's my initial hypothesis based solely on the naming. Let's see if this function is what I think it is and if it makes sense based on what I already know about batadv architecture.
|
| 24/2 |
2026/02/25 01:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/mesh-interface.c IncludeLines:true Name:batadv_meshif_init_early]
Results: map[SourceCode: 998: /**
999: * batadv_meshif_init_early() - early stage initialization of mesh interface
1000: * @dev: registered network device to modify
1001: */
1002: static void batadv_meshif_init_early(struct net_device *dev)
1003: {
1004: ether_setup(dev);
1005:
1006: dev->netdev_ops = &batadv_netdev_ops;
1007: dev->needs_free_netdev = true;
1008: dev->priv_destructor = batadv_meshif_free;
1009: dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
1010: dev->priv_flags |= IFF_NO_QUEUE;
1011: dev->lltx = true;
1012: dev->netns_immutable = true;
1013:
1014: /* can't call min_mtu, because the needed variables
1015: * have not been initialized yet
1016: */
1017: dev->mtu = ETH_DATA_LEN;
1018: dev->max_mtu = BATADV_MAX_MTU;
1019:
1020: /* generate random address */
1021: eth_hw_addr_random(dev);
1022:
1023: dev->ethtool_ops = &batadv_ethtool_ops;
1024: }
SourceFile:net/batman-adv/mesh-interface.c]
|
| 25/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 21667
output: 44
thoughts: 394
Thoughts: **Analyzing a Potential Data Race in the batadv Driver**
Okay, so I'm looking at this `lltx = true` flag on line 1011. Right, so this means the driver is handling its own locking within `ndo_start_xmit`. The problem is, `batadv_interface_tx`, which is the actual handler for `ndo_start_xmit`, doesn't *appear* to have any explicit locking mechanisms in place.
```c
167: static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
168: struct net_device *mesh_iface)
```
If the `lltx` flag is set and there's no locking in the transmit function, that implies that `batadv_tt_local_add` could indeed be called concurrently from different CPUs operating on the same mesh interface. And, glancing at `batadv_tt_local_add`, I'm not seeing any mutexes or spinlocks in there either.
Okay, let me double-check `batadv_tt_local_add`... yep, it modifies `tt_local->last_seen` and `tt_local->common.flags`. That's a red flag. If those fields are being modified concurrently without any protection, we're almost certainly looking at a data race. Losing updates to `tt_local->common.flags` could be very problematic.
I should check the impact of losing flags, especially those flags that have implications for routing or client advertisement. Let me look at the definitions of `BATADV_TT_CLIENT_PENDING`, `BATADV_TT_CLIENT_ROAM`, `BATADV_TT_CLIENT_WIFI`, and `BATADV_TT_CLIENT_ISOLA`.
I suspect losing `BATADV_TT_CLIENT_WIFI` in particular could have serious consequences. If the driver is not correctly tracking Wi-Fi clients, this could lead to routing issues and connectivity problems.
The report also specifically mentions `last_seen` at offset 0x1c0, which is interesting. Time to pull up the definition of `batadv_tt_local_entry` and see what exactly is located at that offset. I need to understand what data could be corrupted.
|
| 26/2 |
2026/02/25 01:20 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c Name:batadv_tt_local_entry]
Results: map[Fields:[map[Name:common OffsetBits:0 SizeBits:512] map[Name:last_seen OffsetBits:512 SizeBits:64] map[Name:vlan OffsetBits:576 SizeBits:64]]]
|
| 27/2 |
2026/02/25 01:20 |
llm |
expert |
0m
Model:
Tokens:
input: 22675
output: 44
thoughts: 406
Thoughts: **Analyzing the Memory Layout and Offset Calculations**
Okay, so I'm looking at this memory dump and trying to piece together where this write operation is targeting. First, `common` is 512 bits, or 64 bytes. That's a key starting point. This `last_seen` field is obviously starting at byte 64. The target address is reported as `0xffff8881047891c0`, which is 448 bytes (0x1c0).
Now I'm diving deeper into the `common` struct's size to make sure my initial assumption is correct, it helps determine the offset. Let's see... `addr` is 6, `vid` is 2, `hash_entry` is 16 on 64-bit systems, `flags` is 2, `added_at` is 8, `refcount` is 4, and `rcu` is 16 bytes. Summing these up, it's 54 bytes. Padding might bring this to 64 bytes for alignment. If so, `last_seen` is indeed at offset 64 (0x40).
The write is going to `0xffff8881047891c0`. However, the object address itself isn't directly given, just an offset within the structure. The function name `batadv_tt_local_add+0x16e/0x1050` is a good clue. Line 619, where `tt_local->last_seen = jiffies;` is called, is the likely culprit.
If `tt_local` points to the base of the structure, then `tt_local->last_seen` is at `tt_local + offsetof(struct batadv_tt_local_entry, last_seen)`. Knowing `last_seen` is at offset 64 (0x40), the base object address is `0xffff8881047891c0 - 0x40 = 0xffff888104789180`. I need to double-check `batadv_tt_common_entry` to fully confirm this layout.
|
| 28/2 |
2026/02/25 01:21 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c Name:batadv_tt_common_entry]
Results: map[Fields:[map[Name:addr OffsetBits:0 SizeBits:48] map[Name:vid OffsetBits:48 SizeBits:16] map[Name:hash_entry OffsetBits:64 SizeBits:128] map[Name:flags OffsetBits:192 SizeBits:16] map[Name:added_at OffsetBits:256 SizeBits:64] map[Name:refcount OffsetBits:320 SizeBits:32] map[Name:rcu OffsetBits:384 SizeBits:128]]]
|
| 29/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 23770
output: 26
thoughts: 1109
Thoughts: **Analyzing the Potential Race Conditions in `batadv_tt_local_add`**
Okay, so I'm digging into this reported race condition and need to break down exactly what's happening. First, let me confirm the offsets and sizes: `common` is 512 bits, which is 64 bytes. `last_seen` is also 512 bits or 64 bytes.
The reported address for `last_seen` is `0xffff8881047891c0`. Now, I need to check the alignment. `0xffff8881047891c0 & 0x3f` equals 0, so it *is* 64-byte aligned. This means that if `last_seen` is at offset 64 within the object, the object's start is 64 bytes before that. If `last_seen` is at `0xffff8881047891c0`, then the object starts at `0xffff888104789180`. And `0x1c0 - 0x180` is indeed 0x40 or 64, which is correct. So, the race on `last_seen` is as reported, itโs a 64-byte write.
Now, let's consider `flags`. It's at offset 192 bits, or 24 bytes. If `last_seen` is racing, and this code path is hit concurrently, there's a good chance we'll also see contention on the `flags` updates.
Looking at the code:
```c
618: if (tt_local) {
619: tt_local->last_seen = jiffies;
620: if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
```
The `flags` are checked right after `last_seen` is updated. That's a classic setup for a race. If `batadv_tt_local_add` is called concurrently, CPU 0 might update `last_seen` while CPU 1 is doing the same. That's the first race.
Then, both CPUs could be in the conditional:
CPU 0: `if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING)`
CPU 1: `if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING)`
And if `BATADV_TT_CLIENT_PENDING` is set:
CPU 0: `tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;`
CPU 1: `tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;`
This is another race. Both CPUs could be clearing the same flag.
Furthermore, consider:
```c
746: tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
747: else
748: tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
```
If one CPU is setting `WIFI` and another is clearing `ISOLA` (at line 759, which I'll have to look at later), we could lose updates. Let's remember the `flags` is a `u16`. The `|=` operation is typically compiled as:
1. Load `flags` into a register.
2. OR with the new flag value.
3. Store the register back to `flags`.
If CPU 1 does:
1. Load `flags` into a register.
2. AND with `~ISOLA`.
3. Store register back to `flags`.
If there's interleaving:
* CPU 0 loads `flags` (say, 0).
* CPU 1 loads `flags` (also 0).
* CPU 0 ORs with `WIFI` (register = `WIFI`).
* CPU 1 ANDs with `~ISOLA` (register = 0).
* CPU 0 stores `WIFI`.
* CPU 1 stores 0.
The result is that the `WIFI` flag is lost. This is a very real, and potentially harmful, race condition. The `last_seen` race is more of a symptom, a visible sign that something is missing. The race on `flags` is a potential data corruption bug.
So, is `batadv_tt_local
|
| 30/2 |
2026/02/25 01:21 |
tool |
codesearch-find-references |
0m
Args: map[Name:batadv_tt_local_add]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:batadv_interface_add_vid SourceFile:net/batman-adv/mesh-interface.c SourceLine:651] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:batadv_interface_set_mac_addr SourceFile:net/batman-adv/mesh-interface.c SourceLine:133] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:batadv_interface_tx SourceFile:net/batman-adv/mesh-interface.c SourceLine:236] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:batadv_mcast_mla_tt_add SourceFile:net/batman-adv/multicast.c SourceLine:725] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:batadv_meshif_create_vlan SourceFile:net/batman-adv/mesh-interface.c SourceLine:577]] TruncatedOutput:false]
|
| 31/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 26239
output: 49
thoughts: 146
Thoughts: **Analyzing the Batadv Transmission Path**
Okay, so the report indicates a problem originates from `batadv_interface_tx`. Right, let's trace this. My initial thought is to examine `batadv_tt_local_event`. It's called from `batadv_tt_local_add`, which looks like a key point to investigate the control flow of this process. Specifically, I'm noting the calls to `batadv_tt_local_event` on lines 712 and 765 within `batadv_tt_local_add`. Both calls are made with `BATADV_NO_FLAGS`, which suggests a standard execution path. My next step, naturally, is to delve into the implementation of `batadv_tt_local_event` itself. Let's see what we can find there.
|
| 32/2 |
2026/02/25 01:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_local_event]
Results: map[SourceCode: 413: /**
414: * batadv_tt_local_event() - store a local TT event (ADD/DEL)
415: * @bat_priv: the bat priv with all the mesh interface information
416: * @tt_local_entry: the TT entry involved in the event
417: * @event_flags: flags to store in the event structure
418: */
419: static void batadv_tt_local_event(struct batadv_priv *bat_priv,
420: struct batadv_tt_local_entry *tt_local_entry,
421: u8 event_flags)
422: {
423: struct batadv_tt_change_node *tt_change_node, *entry, *safe;
424: struct batadv_tt_common_entry *common = &tt_local_entry->common;
425: u8 flags = common->flags | event_flags;
426: bool del_op_requested, del_op_entry;
427: size_t changes;
428:
429: tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
430: if (!tt_change_node)
431: return;
432:
433: tt_change_node->change.flags = flags;
434: memset(tt_change_node->change.reserved, 0,
435: sizeof(tt_change_node->change.reserved));
436: ether_addr_copy(tt_change_node->change.addr, common->addr);
437: tt_change_node->change.vid = htons(common->vid);
438:
439: del_op_requested = flags & BATADV_TT_CLIENT_DEL;
440:
441: /* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */
442: spin_lock_bh(&bat_priv->tt.changes_list_lock);
443: changes = READ_ONCE(bat_priv->tt.local_changes);
444: list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
445: list) {
446: if (!batadv_compare_eth(entry->change.addr, common->addr))
447: continue;
448:
449: del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
450: if (del_op_requested != del_op_entry) {
451: /* DEL+ADD in the same orig interval have no effect and
452: * can be removed to avoid silly behaviour on the
453: * receiver side. The other way around (ADD+DEL) can
454: * happen in case of roaming of a client still in the
455: * NEW state. Roaming of NEW clients is now possible due
456: * to automatically recognition of "temporary" clients
457: */
458: list_del(&entry->list);
459: kmem_cache_free(batadv_tt_change_cache, entry);
460: changes--;
461: } else {
462: /* this is a second add or del in the same originator
463: * interval. It could mean that flags have been changed
464: * (e.g. double add): update them
465: */
466: entry->change.flags = flags;
467: }
468:
469: kmem_cache_free(batadv_tt_change_cache, tt_change_node);
470: goto update_changes;
471: }
472:
473: /* track the change in the OGMinterval list */
474: list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
475: changes++;
476:
477: update_changes:
478: WRITE_ONCE(bat_priv->tt.local_changes, changes);
479: spin_unlock_bh(&bat_priv->tt.changes_list_lock);
480: }
SourceFile:net/batman-adv/translation-table.c]
|
| 33/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 27833
output: 42
thoughts: 375
Thoughts: **Analyzing a Potential Race Condition in batman-adv's Translation Table**
Okay, so I'm looking at this `batadv_tt_local_event` function, and it seems like it has its own lock, `bat_priv->tt.changes_list_lock`, which is good. But wait, it doesn't seem to protect the `tt_local_entry` itself. That's immediately raising a red flag. Specifically, the `flags` are read at line 425: `u8 flags = common->flags | event_flags;` โ and that's *outside* the protection of the lock.
My intuition is screaming, "potential bug!". If `batadv_tt_local_add` lacks proper synchronization, it's definitely a problem. Hold on, let me quickly double-check if there might be another lock held higher up the call stack, something I'm missing.
Okay, I see that `batadv_interface_tx` calls `batadv_tt_local_add`, and that function is called from `dev_hard_start_xmit`. Now, if `dev->lltx` is true, then `dev_hard_start_xmit` *doesn't* take the `tx_lock`. So, that means `batadv_interface_tx` can, and probably *is*, called concurrently across multiple CPUs. And, since `batadv_tt_local_add` is called within that, we have our race condition.
If we have concurrent calls to `batadv_tt_local_add` for the same `addr` and `vid`, they'll both hit the same `tt_local` entry and potentially try to update it simultaneously. The `last_seen` update is just a simple write of `jiffies`, so thatโs probably okay. But the update to `flags`? That's a read-modify-write on a `u16`. *That's* where we'll have problems.
I wonder if the `batman-adv` devs consider this benign, or have some other form of protection that I'm overlooking. I have to admit, that module has some seriously complex logic in `translation-table.c`. If those `flags` get corrupted, it could easily lead to inconsistent state across the mesh network, and thatโs a nightmare. Iโd better thoroughly check the surrounding context for any relevant locks.
|
| 34/2 |
2026/02/25 01:21 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c Name:batadv_priv_tt]
Results: map[Fields:[map[Name:vn OffsetBits:0 SizeBits:32] map[Name:ogm_append_cnt OffsetBits:32 SizeBits:32] map[Name:local_changes OffsetBits:64 SizeBits:64] map[Name:changes_list OffsetBits:128 SizeBits:128] map[Name:local_hash OffsetBits:256 SizeBits:64] map[Name:global_hash OffsetBits:320 SizeBits:64] map[Name:req_list OffsetBits:384 SizeBits:64] map[Name:roam_list OffsetBits:448 SizeBits:128] map[Name:changes_list_lock OffsetBits:576 SizeBits:32] map[Name:req_list_lock OffsetBits:608 SizeBits:32] map[Name:roam_list_lock OffsetBits:640 SizeBits:32] map[Name:last_changeset OffsetBits:704 SizeBits:64] map[Name:last_changeset_len OffsetBits:768 SizeBits:16] map[Name:last_changeset_lock OffsetBits:800 SizeBits:32] map[Name:commit_lock OffsetBits:832 SizeBits:32] map[Name:work OffsetBits:896 SizeBits:704]]]
|
| 35/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 29134
output: 28
thoughts: 18
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating the `commit_lock`**
Alright, a `commit_lock`. That's a critical piece of the puzzle, and I need to understand its scope and impact. Let's trace its usage. I'll need to see precisely where this lock is acquired, released, and most importantly, what resources or critical sections it protects. This is a common pattern for handling concurrency, but the specific implementation is what truly matters. I'll be looking for potential bottlenecks, deadlocks, and other concurrency hazards that might be hiding within that code. A deeper dive is required to identify any areas for optimization, or risks that need to be mitigated.
|
| 36/2 |
2026/02/25 01:21 |
tool |
codesearch-find-references |
0m
Args: map[Name:batadv_priv_tt::commit_lock]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_mesh_init SourceFile:net/batman-adv/main.c SourceLine:156] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_mesh_init SourceFile:net/batman-adv/main.c SourceLine:156] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_send_my_tt_response SourceFile:net/batman-adv/translation-table.c SourceLine:3095] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_send_my_tt_response SourceFile:net/batman-adv/translation-table.c SourceLine:3178] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_tt_local_commit_changes SourceFile:net/batman-adv/translation-table.c SourceLine:3666] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_tt_local_commit_changes SourceFile:net/batman-adv/translation-table.c SourceLine:3668] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_tt_local_commit_changes_nolock SourceFile:net/batman-adv/translation-table.c SourceLine:3635] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_tt_local_resize_to_mtu SourceFile:net/batman-adv/translation-table.c SourceLine:3898] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:batadv_tt_local_resize_to_mtu SourceFile:net/batman-adv/translation-table.c SourceLine:3921]] TruncatedOutput:false]
|
| 37/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 29928
output: 45
thoughts: 151
Thoughts: **Analyzing Potential Concurrency Issues in `batadv_tt_local_add`**
Okay, so I was looking at the `batadv_tt_local_add` function and noticed that `commit_lock` isn't being used within it. That immediately got me thinking. If `commit_lock` isn't there, is `batadv_tt_local_add` itself thread-safe? Could concurrent calls to this function lead to problems, specifically with duplicate entries in the hash table?
My attention zeroes in on this block of code:
```c
701: hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
702: batadv_choose_tt, &tt_local->common,
703: &tt_local->common.hash_entry);
```
That `batadv_hash_add` call is where the actual insertion into the hash table happens. Clearly, it is the most critical point of concern. So, I need to understand `batadv_hash_add` more thoroughly. It's the key to figuring out if this whole `batadv_tt_local_add` function is susceptible to race conditions. The lack of a lock around the addition raises a red flag; I need to dig into `batadv_hash_add`'s implementation and how it handles concurrency.
|
| 38/2 |
2026/02/25 01:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/hash.c IncludeLines:true Name:batadv_hash_add]
Results: map[SourceCode: 64: /**
65: * batadv_hash_add() - adds data to the hashtable
66: * @hash: storage hash table
67: * @compare: callback to determine if 2 hash elements are identical
68: * @choose: callback calculating the hash index
69: * @data: data passed to the aforementioned callbacks as argument
70: * @data_node: to be added element
71: *
72: * Return: 0 on success, 1 if the element already is in the hash
73: * and -1 on error.
74: */
75: static inline int batadv_hash_add(struct batadv_hashtable *hash,
76: batadv_hashdata_compare_cb compare,
77: batadv_hashdata_choose_cb choose,
78: const void *data,
79: struct hlist_node *data_node)
80: {
81: u32 index;
82: int ret = -1;
83: struct hlist_head *head;
84: struct hlist_node *node;
85: spinlock_t *list_lock; /* spinlock to protect write access */
86:
87: if (!hash)
88: goto out;
89:
90: index = choose(data, hash->size);
91: head = &hash->table[index];
92: list_lock = &hash->list_locks[index];
93:
94: spin_lock_bh(list_lock);
95:
96: hlist_for_each(node, head) {
97: if (!compare(node, data))
98: continue;
99:
100: ret = 1;
101: goto unlock;
102: }
103:
104: /* no duplicate found in list, add new element */
105: hlist_add_head_rcu(data_node, head);
106: atomic_inc(&hash->generation);
107:
108: ret = 0;
109:
110: unlock:
111: spin_unlock_bh(list_lock);
112: out:
113: return ret;
114: }
SourceFile:net/batman-adv/hash.h]
|
| 39/2 |
2026/02/25 01:21 |
llm |
expert |
0m
Model:
Tokens:
input: 31135
output: 27
thoughts: 2567
Thoughts: **Analysis of Concurrent Access to batadv_tt_local_add and Potential Data Races**
Okay, so I've been digging into this `batadv_tt_local_add` function in `batman-adv`, and there's a definite race condition here that needs some serious consideration. It appears the core of the issue lies in the concurrent access to the `tt_local` structure within the hash table. The hash table itself is protected by a per-bucket spinlock, which is good. But the critical section inside `batadv_tt_local_add` which updates existing entries is vulnerable.
The vulnerability stems from the sequence where the code first *finds* an existing `tt_local` entry using RCU, and then proceeds to update its `last_seen` and `flags` fields without holding a lock. This introduces a potential race.
Initially, I thought updating `last_seen` was benign. It's just a timestamp; if two writes happen concurrently, the "winner" is arbitrary, and the timing details aren't critical. However, the `flags` field is far more concerning. The analysis shows that several flags are manipulated based on the current context (`in_hardif` and `skb->mark`, for instance), and if these flag changes are interleaved by concurrent threads, there's a risk of losing updates.
Specifically, the interleaving scenario where one thread tries to *set* a flag (e.g., `WIFI`) while another tries to *clear* a different flag (e.g., `ISOLA`) results in an unrecoverable loss. The problem is that the state is not atomic. The read/modify/write operations can be interleaved.
The code's logic derives `WIFI` and `ISOLA` flags from interface and packet mark, respectively, which *should* be constant for a client's stream of packets (at least in a short period). However, the bridge setup comes into play, creating a situation where packets from the same client are processed with different hard interfaces and bridge ports. Therefore, flag changes *can* occur.
While the code *might* eventually converge to the correct state because `batadv_tt_local_add` is called for every packet, the core problem is that we're relying on subsequent packets to eventually fix a *lost* flag change. This seems fragile, especially for a protocol like `batman-adv`, which is known for its sensitivity to TT consistency.
The analysis shows `batadv_tt_local_event` uses `common->flags` and this is where it gets really dicey. This function is called based on a bitwise XOR comparison of the old flag values to the new ones. If these are changed concurrently, the events generated are also incorrect and can lose the correct flag values. This can lead to incorrect advertisements of local TT entries.
The good news is that the events are handled in a way that handles duplicate events by updating the existing change node. So, repeated events don't corrupt the data structure.
The `PENDING` and `ROAM` flags seem less problematic because they are meant to be cleared during updates. If multiple packets arrive for a pending client, clearing these flags multiple times is not harmful. However, these flags are subject to the same race conditions.
The root cause of this vulnerability comes from the potential for packets from the same client to be received on different interfaces or with different marks. That can happen in bridge setups.
In essence, the data race in `batadv_tt_local_add` is a *real* bug because lost flags can result in incorrect state for local TT entries and consequently, incorrect advertisement of client state within the mesh. We need to implement a proper locking mechanism to prevent this concurrent access. RCU alone is insufficient for this scenario. The lock has to protect the entire critical section for an existing `tt_local` entry: read, update of `last_seen` and `flags`.
|
| 40/2 |
2026/02/25 01:22 |
tool |
codesearch-find-references |
0m
Error:
Args: map[Name:BATADV_TT_CLIENT_PENDING]
Results: map[References:<nil> TruncatedOutput:false]
|
| 41/2 |
2026/02/25 01:22 |
llm |
expert |
0m
Model:
Tokens:
input: 34586
output: 23
thoughts: 16
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Identifying a Tooling Mismatch**
Okay, so I've realized this isn't a complex, intricate problem; it's a simple, repetitive task, likely handled by some sort of macro. My initial instinct was probably too complicated; I was probably reaching for something with too much overhead. This is a common pitfall. The real issue is that I didn't immediately recognize the appropriate tool for the job. Now that I understand that this is macro related, I need to get back to the basics and use grep or grepper. This will be the most efficient solution.
|
| 42/2 |
2026/02/25 01:22 |
tool |
grepper |
0m
Args: map[Expression:BATADV_TT_CLIENT_PENDING]
Results: map[Output:include/uapi/linux/batman_adv.h=26=enum batadv_tt_client_flags {
--
include/uapi/linux/batman_adv.h-63- /**
include/uapi/linux/batman_adv.h:64: * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it
include/uapi/linux/batman_adv.h-65- * is kept in the table for one more originator interval for consistency
--
include/uapi/linux/batman_adv.h-67- */
include/uapi/linux/batman_adv.h:68: BATADV_TT_CLIENT_PENDING = (1 << 10),
include/uapi/linux/batman_adv.h-69-
--
net/batman-adv/translation-table.c=589=bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
--
net/batman-adv/translation-table.c-619- tt_local->last_seen = jiffies;
net/batman-adv/translation-table.c:620: if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
net/batman-adv/translation-table.c-621- batadv_dbg(BATADV_DBG_TT, bat_priv,
--
net/batman-adv/translation-table.c-628- */
net/batman-adv/translation-table.c:629: tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
net/batman-adv/translation-table.c-630- goto add_event;
--
net/batman-adv/translation-table.c=1177=batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
--
net/batman-adv/translation-table.c-1186- */
net/batman-adv/translation-table.c:1187: tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
net/batman-adv/translation-table.c-1188-
--
net/batman-adv/translation-table.c=1267=static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
--
net/batman-adv/translation-table.c-1283- /* entry already marked for deletion */
net/batman-adv/translation-table.c:1284: if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
net/batman-adv/translation-table.c-1285- continue;
--
net/batman-adv/translation-table.c=2320=struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
--
net/batman-adv/translation-table.c-2332- if (!tt_local_entry ||
net/batman-adv/translation-table.c:2333: (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
net/batman-adv/translation-table.c-2334- goto out;
--
net/batman-adv/translation-table.c=3289=bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,
--
net/batman-adv/translation-table.c-3300- */
net/batman-adv/translation-table.c:3301: if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
net/batman-adv/translation-table.c-3302- (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
--
net/batman-adv/translation-table.c=3548=static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
--
net/batman-adv/translation-table.c-3584-
net/batman-adv/translation-table.c:3585:/* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
net/batman-adv/translation-table.c-3586-static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
--
net/batman-adv/translation-table.c-3605- hash_entry) {
net/batman-adv/translation-table.c:3606: if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
net/batman-adv/translation-table.c-3607- continue;
]
|
| 43/2 |
2026/02/25 01:22 |
llm |
expert |
0m
Model:
Tokens:
input: 36011
output: 51
thoughts: 49
Thoughts: Okay, here's my interpretation of these thoughts, summarized in the first person, assuming an expert-level understanding:
**Analyzing the Batadv Tunneling Table Operations**
Alright, so the core idea here is about managing the Tunneling Table (TT) within BATMAN-adv. The initial thought is that `batadv_tt_local_set_pending` is responsible for setting a specific flag, which I assume indicates some kind of pending state or action related to a particular TT entry. Now, the key is knowing *what* triggers the use of that flag.
That's where `batadv_tt_local_purge_list` comes in. It appears this function is the one that calls `batadv_tt_local_set_pending`. This strongly suggests that `batadv_tt_local_purge_list` is either initiating, or part of, a process to deal with the entries that need some further processing. I'll need to dig into `batadv_tt_local_purge_list` itself to fully understand what's happening and why this flag is being set. It's likely involved in cleaning up or removing potentially stale or invalid entries from the local TT. I need to figure out the context. Let's see how `batadv_tt_local_purge_list` is implemented to get a better idea.
|
| 44/2 |
2026/02/25 01:22 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_local_purge_list]
Results: map[SourceCode:1260: /**
1261: * batadv_tt_local_purge_list() - purge inactive tt local entries
1262: * @bat_priv: the bat priv with all the mesh interface information
1263: * @head: pointer to the list containing the local tt entries
1264: * @timeout: parameter deciding whether a given tt local entry is considered
1265: * inactive or not
1266: */
1267: static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
1268: struct hlist_head *head,
1269: int timeout)
1270: {
1271: struct batadv_tt_local_entry *tt_local_entry;
1272: struct batadv_tt_common_entry *tt_common_entry;
1273: struct hlist_node *node_tmp;
1274:
1275: hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
1276: hash_entry) {
1277: tt_local_entry = container_of(tt_common_entry,
1278: struct batadv_tt_local_entry,
1279: common);
1280: if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
1281: continue;
1282:
1283: /* entry already marked for deletion */
1284: if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
1285: continue;
1286:
1287: if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout))
1288: continue;
1289:
1290: batadv_tt_local_set_pending(bat_priv, tt_local_entry,
1291: BATADV_TT_CLIENT_DEL, "timed out");
1292: }
1293: }
SourceFile:net/batman-adv/translation-table.c]
|
| 45/2 |
2026/02/25 01:22 |
llm |
expert |
0m
Model:
Tokens:
input: 36992
output: 25
thoughts: 2445
Thoughts: **Analysis of Potential Data Race in `batadv_tt_local_add`**
Okay, so I'm digging into this report of a data race within `batadv_tt_local_add` in batman-adv. The core of the issue seems to be the concurrent access to `tt_local_entry->last_seen` and `tt_local_entry->flags`. The fact that `last_seen` is timestamped with `jiffies` makes me think this is probably going to be a classic "benign" race from a pure correctness standpoint, in that we're talking about a slightly inaccurate timestamp. Still, data races in the kernel are rarely *truly* benign, so let's dig deeper.
The report highlights that `batadv_tt_local_purge_list` (which is likely running on a timer or workqueue) might be racing with `batadv_tt_local_add`. While `last_seen` might be slightly off in the face of this race, this is not a huge deal. `batadv_tt_local_set_pending` also modifies the flags field. This is where things get interesting, since flags are used to drive logic. The immediate concern is whether this race could lead to any memory corruption, but it seems unlikely, since `flags` are used for control flow rather than for holding pointers or sizes.
I immediately looked for any explicit locking on the `batadv_tt_local_entry` structure itself, but I'm not seeing any. Then I wondered if the race had already been addressed upstream. The report points to `batadv_tt_local_add+0x16e/0x1050`. After a quick review, it seems clear this function is *not* inherently thread-safe when dealing with existing entries, but the table itself seems safe, thanks to its use of RCU and bucket locks.
Now, if a race *is* occurring on the `flags` field, it's not simply an inaccuracy. It could have the potential to prematurely purge an entry, or mis-advertise a client. This is where things become "harmful" from a functional standpoint, even if no crash occurs. KCSAN's flagging this as a data race tells us that someone should investigate it, regardless of any perceived "benign-ness."
Iโm particularly concerned that a lost update to `BATADV_TT_CLIENT_WIFI` could affect how other nodes handle traffic for a client. The potential for inconsistent table states across the mesh is another issue.
Looking at the code again, the key issue seems to be that `last_seen` is updated without synchronization. Also, the read of `flags` that happens just after `last_seen` is read is also potentially racing. The use of `WRITE_ONCE` for `last_seen` would have been a very clean solution from the start.
So, let's look at similar drivers to see how they handle FDB updates. In the bridge driver, I believe there's a spinlock involved. Batman-adv uses `kref` for entry lifecycle, which is good.
I need to confirm that `batadv_tt_local_add` is *actually* called concurrently in a way that matters. The function is definitely called from `ndo_start_xmit` when `lltx` is true.
I have to look for other problematic fields on `batadv_tt_local_entry`. The `vlan` field is set during creation and shouldn't change.
I'm starting to think this is potentially an issue because of the potential for inconsistent updates to `flags`. The `PENDING` flag is a transient issue, but losing `WIFI` could lead to longer-term problems. The use of the TT version number (`ttvn`) is interesting. A lost flag change could impact the `ttvn` and lead to TT inconsistencies, which are then handled with a full TT re-send. The race on `last_seen` itself is definitely benign.
The KCSAN report *means* this is a data race. Now I have to look into the philosophy of batman-adv development. They may be intentionally relying on idempotent or transient nature of updates to avoid heavy locking.
I need to check for a past fix. A commit *similar* to the problem is `734666657890 ("batman-adv: fix data race in batadv_tt_local_add")`. Let's see if this commit exists and how it addressed this.
I'll also re-scan the current code for any `ONCE` macros that might have been added to fix this.
It turns out that the `flags` race is definitely an issue, if `WIFI` is lost it has real implications for the mesh'
|
| 46/2 |
2026/02/25 01:22 |
tool |
grepper |
0m
Error:
Args: map[Expression:_ONCE.*tt_local->last_seen]
Results:
|
| 47/2 |
2026/02/25 01:22 |
llm |
expert |
0m
Model:
Tokens:
input: 40501
output: 21
thoughts: 8
Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:
**Considering a Namespace for Configuration Flags**
Alright, so I'm thinking about how to manage these configuration flags. We need something organized and easily accessible. `common.flags` is popping into my head. It's a pretty straightforward approach, isn't it? It suggests a centralized namespace, a designated area within the `common` module, perhaps, to house all our relevant flags. This approach offers immediate benefits: it's readable, it clearly demarcates the flags from other components, and it implies good organization at the outset. I need to consider if `common` is the most appropriate scope, or if there is a more fitting one, but the structure is the important element here. Iโm leaning towards it because it feels intuitive, doesn't require importing from many disparate places, and should be relatively easy to implement and maintain long-term. Let's weigh the benefits and drawbacks of this simple namespace solution more closely.
|
| 48/2 |
2026/02/25 01:22 |
tool |
grepper |
0m
Error:
Args: map[Expression:_ONCE.*common.flags]
Results:
|
| 49/2 |
2026/02/25 01:22 |
llm |
expert |
0m
Model:
Tokens:
input: 40758
output: 49
thoughts: 2915
Thoughts: **Benign Data Race in `batadv_tt_local_add`**
Alright, let's break this down. It seems the kernel's KCSAN is flagging a potential data race within the `batadv_tt_local_add` function, specifically on the `last_seen` timestamp and the `flags` field of a `tt_local` entry. First, I confirmed that `batadv_tt_local_add` isn't using `READ_ONCE` or `WRITE_ONCE`. I verified that the function can be called concurrently, particularly in a bridge setup where packets are flooded to the batman-adv interface, leading to multiple CPUs processing the same client's traffic simultaneously. This is a common and expected scenario in a busy network.
My analysis suggests that this race is likely benign. The `last_seen` timestamp is simply a value indicating when the client was last active, and while a concurrent update could lead to a slightly incorrect value, this would be transient and self-correcting. The `flags` field warrants closer inspection, as concurrent updates *could* lead to inconsistent flag states. However, the flags are derived from the packet and are likely identical for packets from the same client, so that scenario is less likely.
There's the `PENDING` flag, which is cleared in `batadv_tt_local_add`, and might be set in `batadv_tt_local_purge_list`. But even if a race occurs, the effect would be cleared, or at the very worst, would be transient and harmless. There is a `batadv_tt_local_event` call which could potentially be affected. This function is called if the `PENDING` flag is cleared, and handles duplicates.
I also considered whether the hash bucket locks or other synchronization primitives protect this, but they are only for adds and deletes, not lookups or updates. In essence, it appears the `batman-adv` design *expects* some level of lockless updates using RCU for lookups. I confirmed the `last_seen` and `flags` fields are the only ones potentially raced.
The fact that `last_seen` is a simple 64-bit value on an x86_64 system, and the write is 64-bit aligned, makes the write atomic anyway. This means that, at worst, an incremented `jiffies` value might get overwritten by the other thread's update, which is a benign effect. Other fields like `vlan`, `addr`, and `refcount` are handled during creation or using atomic operations.
The `flags` field is a 16-bit update on x86, also atomic if aligned, and it is 2-byte aligned, so the read-modify-write cycle is not a factor. Even if the update is not atomic (which it is), the consequences would still be transient. The code calls `batadv_tt_local_event`, which has its own lock, so that call is safe. The other side effects, sending packets and calling free are also not harmful even if called twice. The overall design of batman-adv is robust against packet loss and reordering, making this race even less significant.
Overall, considering the transient nature of the race, the atomic nature of the operations, the simple fields involved, and the design principles of `batman-adv`, I'm confident that this is a benign data race.
|
| 50/2 |
2026/02/25 01:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/batman-adv/translation-table.c IncludeLines:true Name:batadv_tt_global_free]
Results: map[SourceCode: 550: static void batadv_tt_global_free(struct batadv_priv *bat_priv,
551: struct batadv_tt_global_entry *tt_global,
552: const char *message)
553: {
554: struct batadv_tt_global_entry *tt_removed_entry;
555: struct hlist_node *tt_removed_node;
556:
557: batadv_dbg(BATADV_DBG_TT, bat_priv,
558: "Deleting global tt entry %pM (vid: %d): %s\n",
559: tt_global->common.addr,
560: batadv_print_vid(tt_global->common.vid), message);
561:
562: tt_removed_node = batadv_hash_remove(bat_priv->tt.global_hash,
563: batadv_compare_tt,
564: batadv_choose_tt,
565: &tt_global->common);
566: if (!tt_removed_node)
567: return;
568:
569: /* drop reference of remove hash entry */
570: tt_removed_entry = hlist_entry(tt_removed_node,
571: struct batadv_tt_global_entry,
572: common.hash_entry);
573: batadv_tt_global_entry_put(tt_removed_entry);
574: }
SourceFile:net/batman-adv/translation-table.c]
|
| 51/2 |
2026/02/25 01:23 |
llm |
expert |
0m
Model:
Tokens:
input: 44914
output: 19
thoughts: 449
Thoughts: **My Concluding Thoughts on the Concurrency Issue**
Okay, after thoroughly examining the code related to `batadv_tt_global_free`, I'm confident in my assessment. The use of bucket locks in `batadv_hash_remove` and the NULL return if the entry was already removed clearly indicates that calling `batadv_tt_global_free` twice is safe. This reinforces my initial impression that the design is robust against concurrent access, or at the very least, handles it gracefully.
I noted the `tt_global->roam_at = jiffies;` timestamp update; it's just another instance of timestamping, much like `last_seen`, so no worries there. With this, I was already leaning towards a "benign" verdict.
But, I should perform one last check on `batadv_tt_local_add`. Specifically, what about the potential race condition on `tt_local->common.flags`? Ah, I see: it's a bit-setting and bit-clearing operation for `BATADV_TT_CLIENT_ROAM` in `tt_local`, and again on `tt_global`. However, the lookups for both `tt_local` and `tt_global` utilize a hash, so it's possible that two threads may find the same `tt_global`. Even so, the operations are the same in that they are both bitwise operations.
Ultimately, the `last_seen` timestamp race, as reported, is the only one to consider. And now I see the full picture: The interrupt context is softirq (which makes sense, given the stack trace and the call to `batadv_interface_tx`), I've confirmed that the write to memory is happening in `batadv_tt_local_add`, at the line where `tt_local->last_seen = jiffies;`. The "interrupt" part of the report gives the final clue.
So, I'm ready to move forward and provide the result.
|
| 52/2 |
2026/02/25 01:23 |
tool |
set-results |
0m
Args: map[Benign:true Confident:true]
Results: map[Benign:true Confident:true]
|
| 53/2 |
2026/02/25 01:23 |
llm |
expert |
0m
Model:
Tokens:
input: 45829
output: 545
thoughts: 398
Thoughts: **My Assessment of the Data Race in `batadv_tt_local_add`**
Alright, the user is asking me to evaluate this data race, specifically regarding the `tt_local->last_seen` field within `batadv_tt_local_add`. My initial thought process is to break this down.
First, I need to understand the *nature* of the field. `last_seen` is essentially just a timestamp, an `unsigned long`, recording the last time a local client was "seen." It's used to purge stale entries, which, in and of itself, makes this less critical than say, a pointer update or a flag that controls resource allocation.
Second, I need to consider *atomicity*. On an x86_64 system, and I'm assuming that's what we're dealing with, a 64-bit write, aligned to 64 bytes is going to be atomic. The report indicates an 8-byte write to an aligned address, so we can rule out partial writes or reading garbage data.
Third, what are the *consequences*? Even if two threads clobber the `jiffies` value with slightly different values, it's not the end of the world. The purging logic probably has a timeout window on the order of minutes. A tiny difference in the timestamp won't matter, it's not critical precision.
Fourth, it's essential to consider the *protocol's robustness*. `batman-adv` is designed to deal with transient inconsistencies in its translation tables. The protocol's likely designed to handle this, as other flags, and shared information are also updated in an idempotent or self-correcting manner.
Finally, lack of explicit synchronization hints towards lockless design. Since `batman-adv` uses `NETIF_F_LLTX`, it seems to handle its own concurrency. The function `batadv_tt_local_add` looks lockless for updating existing entries, possibly relying on RCU for lookups, or atomic operations like `kref`, or bucket locks for structure manipulation.
In summary, given the nature of the field (a simple timestamp), the atomicity of the operation on x86_64, the tolerance of the purging logic to slightly different timestamps, and the inherent robustness of the `batman-adv` protocol, I conclude this data race on `tt_local->last_seen` is benign. It's unlikely to cause any significant issues or failures.
|