| 0/0 |
2026/08/09 12:19 |
flow |
assessment-security |
10m
Results: map[DenialOfService:true Explanation:Based on the analysis of the provided kernel bug report and source code, here is
the assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock involving `rtnl_lock` and `device_lock`.
1. **Path 1 (`wiphy_unregister`)**: When a `mac80211_hwsim` radio is deleted
(e.g., via netlink or when its network namespace is destroyed),
`wiphy_unregister()` is called. This function first acquires the global
`rtnl_lock()`, and later calls `device_del(&rdev->wiphy.dev)`, which attempts to
acquire `device_lock(&rdev->wiphy.dev)`.
2. **Path 2 (`wiphy_suspend` / `wiphy_resume`)**: During a system-wide suspend
or resume, the Power Management (PM) core iterates over devices and calls their
suspend/resume callbacks. The PM core inherently holds `device_lock(dev)` while
doing this. The suspend callback for the wiphy device (`wiphy_suspend()`) then
attempts to acquire `rtnl_lock()`.
If a radio is being unregistered at the exact same time the system is suspending
or resuming, the two threads will deadlock, each holding one lock and waiting
for the other.
**Security Impact:**
* **Exploitable:** No. This is a pure logic bug (deadlock) that results in a
thread hang. It does not cause memory corruption, out-of-bounds accesses, or
information leaks, so it cannot be exploited for privilege escalation or
arbitrary code execution.
* **Denial of Service (DoS):** Yes. The deadlock will permanently hang the
`rtnl_lock`, which is a critical global lock used by the entire network
subsystem. Any subsequent attempts to modify network configurations
(adding/removing interfaces, changing IP addresses, routing, etc.) will hang
indefinitely. It also prevents the system from completing its suspend/resume
cycle.
* **Accessible from Unprivileged Processes / User Namespaces:** Yes. The
`mac80211_hwsim` netlink commands (`HWSIM_CMD_NEW_RADIO` and
`HWSIM_CMD_DEL_RADIO`) are registered with the `GENL_UNS_ADMIN_PERM` flag. This
means they can be invoked by a user who has `CAP_NET_ADMIN` in their current
user namespace. An unprivileged user can create a new user/network namespace,
acquire the necessary capabilities, and continuously create and delete virtual
radios. If the system attempts to suspend while this is happening, the user will
successfully trigger the deadlock. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/08/09 12:19 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/08/09 12:19 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/26766716579cdcff13b5e3416aa2d1ff891e8337]
|
| 3/1 |
2026/08/09 12:19 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/f8a628c752ebc7bff60482a8688df256d2cc50bc]
|
| 4/1 |
2026/08/09 12:19 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/08/09 12:19 |
agent |
expert |
10m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
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 kernel bug report is:
------------[ cut here ]------------
rtmutex deadlock detected
WARNING: kernel/locking/rtmutex.c:1698 at rt_mutex_handle_deadlock+0x21/0xb0 kernel/locking/rtmutex.c:1698, CPU#1: kworker/u8:141/6021
Modules linked in:
CPU: 1 UID: 0 PID: 6021 Comm: kworker/u8:141 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
Workqueue: netns cleanup_net
RIP: 0010:rt_mutex_handle_deadlock+0x21/0xb0 kernel/locking/rtmutex.c:1698
Code: 90 90 90 90 90 90 90 90 90 41 57 41 56 41 55 41 54 53 83 ff dd 0f 85 81 00 00 00 48 89 f7 e8 16 40 01 00 48 8d 3d af 6d 81 04 <67> 48 0f b9 3a 4c 8d 3d 00 00 00 00 65 48 8b 1d 73 6b 70 07 4c 8d
RSP: 0018:ffffc900067373b0 EFLAGS: 00010286
RAX: 0000000080000000 RBX: 00000000ffffffdd RCX: 0000000000000000
RDX: 0000000000000006 RSI: ffffffff8d98ba58 RDI: ffffffff8fd3e230
RBP: ffffc90006737560 R08: ffffffff8fd0c47f R09: 1ffffffff1fa188f
R10: dffffc0000000000 R11: fffffbfff1fa1890 R12: 1ffff92000ce6e84
R13: ffffffff8b526ec2 R14: ffff888037d60b68 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125af2000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000560e6c0cc950 CR3: 000000000e1b0000 CR4: 00000000003526f0
Call Trace:
<TASK>
__rt_mutex_slowlock kernel/locking/rtmutex.c:1760 [inline]
__rt_mutex_slowlock_locked kernel/locking/rtmutex.c:1787 [inline]
rt_mutex_slowlock+0x73c/0x780 kernel/locking/rtmutex.c:1827
__rt_mutex_lock kernel/locking/rtmutex.c:1842 [inline]
__mutex_lock_common kernel/locking/rtmutex_api.c:560 [inline]
mutex_lock_nested+0x168/0x1d0 kernel/locking/rtmutex_api.c:578
device_lock include/linux/device.h:1104 [inline]
device_del+0xa9/0x8f0 drivers/base/core.c:3923
wiphy_unregister+0x406/0xb10 net/wireless/core.c:1323
ieee80211_unregister_hw+0x1e2/0x2c0 net/mac80211/main.c:1741
mac80211_hwsim_del_radio+0x28a/0x4a0 drivers/net/wireless/virtual/mac80211_hwsim_main.c:6227
hwsim_exit_net+0xea6/0xf70 drivers/net/wireless/virtual/mac80211_hwsim_main.c:7210
ops_exit_list net/core/net_namespace.c:200 [inline]
ops_undo_list+0x43d/0x8d0 net/core/net_namespace.c:253
cleanup_net+0x575/0x810 net/core/net_namespace.c:706
process_one_work+0xaaf/0x1480 kernel/workqueue.c:3379
process_scheduled_works kernel/workqueue.c:3462 [inline]
worker_thread+0xb05/0x10d0 kernel/workqueue.c:3543
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
----------------
Code disassembly (best guess):
0: 90 nop
1: 90 nop
2: 90 nop
3: 90 nop
4: 90 nop
5: 90 nop
6: 90 nop
7: 90 nop
8: 90 nop
9: 41 57 push %r15
b: 41 56 push %r14
d: 41 55 push %r13
f: 41 54 push %r12
11: 53 push %rbx
12: 83 ff dd cmp $0xffffffdd,%edi
15: 0f 85 81 00 00 00 jne 0x9c
1b: 48 89 f7 mov %rsi,%rdi
1e: e8 16 40 01 00 call 0x14039
23: 48 8d 3d af 6d 81 04 lea 0x4816daf(%rip),%rdi # 0x4816dd9
* 2a: 67 48 0f b9 3a ud1 (%edx),%rdi <-- trapping instruction
2f: 4c 8d 3d 00 00 00 00 lea 0x0(%rip),%r15 # 0x36
36: 65 48 8b 1d 73 6b 70 mov %gs:0x7706b73(%rip),%rbx # 0x7706bb1
3d: 07
3e: 4c rex.WR
3f: 8d .byte 0x8d
Reply: Based on the analysis of the provided kernel bug report and source code, here is the assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock involving `rtnl_lock` and `device_lock`.
1. **Path 1 (`wiphy_unregister`)**: When a `mac80211_hwsim` radio is deleted (e.g., via netlink or when its network namespace is destroyed), `wiphy_unregister()` is called. This function first acquires the global `rtnl_lock()`, and later calls `device_del(&rdev->wiphy.dev)`, which attempts to acquire `device_lock(&rdev->wiphy.dev)`.
2. **Path 2 (`wiphy_suspend` / `wiphy_resume`)**: During a system-wide suspend or resume, the Power Management (PM) core iterates over devices and calls their suspend/resume callbacks. The PM core inherently holds `device_lock(dev)` while doing this. The suspend callback for the wiphy device (`wiphy_suspend()`) then attempts to acquire `rtnl_lock()`.
If a radio is being unregistered at the exact same time the system is suspending or resuming, the two threads will deadlock, each holding one lock and waiting for the other.
**Security Impact:**
* **Exploitable:** No. This is a pure logic bug (deadlock) that results in a thread hang. It does not cause memory corruption, out-of-bounds accesses, or information leaks, so it cannot be exploited for privilege escalation or arbitrary code execution.
* **Denial of Service (DoS):** Yes. The deadlock will permanently hang the `rtnl_lock`, which is a critical global lock used by the entire network subsystem. Any subsequent attempts to modify network configurations (adding/removing interfaces, changing IP addresses, routing, etc.) will hang indefinitely. It also prevents the system from completing its suspend/resume cycle.
* **Accessible from Unprivileged Processes / User Namespaces:** Yes. The `mac80211_hwsim` netlink commands (`HWSIM_CMD_NEW_RADIO` and `HWSIM_CMD_DEL_RADIO`) are registered with the `GENL_UNS_ADMIN_PERM` flag. This means they can be invoked by a user who has `CAP_NET_ADMIN` in their current user namespace. An unprivileged user can create a new user/network namespace, acquire the necessary capabilities, and continuously create and delete virtual radios. If the system attempts to suspend while this is happening, the user will successfully trigger the deadlock.
|
| 6/2 |
2026/08/09 12:19 |
llm |
expert |
0m
Model:
Tokens:
input: 7717
output: 24
thoughts: 681
Thoughts: **Analyzing a Kernel RTmutex Deadlock**
Okay, so I've got an interesting kernel bug report on my hands: an `rtmutex` deadlock, specifically triggered at `kernel/locking/rtmutex.c:1698`. The report points to CPU #1 and a `kworker` thread. The call trace is key here, laying out the sequence of events.
From the trace, it looks like the deadlock is happening within the `cleanup_net` function, which is called when a network namespace is being destroyed. The process starts with `cleanup_net` calling `ops_undo_list`, which, in turn, calls `hwsim_exit_net`. That function seems to be where things get interesting. `hwsim_exit_net` calls `mac80211_hwsim_del_radio`. This is where the virtual wireless hardware simulation ties in, I'm guessing. This function then calls `ieee80211_unregister_hw`, which then calls `wiphy_unregister`, and eventually we hit `device_del`. And *that* function attempts to acquire `device_lock`.
So, it's clear the deadlock is rooted in the cleanup process of a network namespace, but specifically involving the virtual wireless hardware simulation (`mac80211_hwsim`). Now, I need to dig into `hwsim_exit_net` and `mac80211_hwsim_del_radio` to understand the locking order and see where the conflict arises. It's likely that `device_lock` is being held somewhere else or in the wrong order. This will likely involve a deep dive into the virtual wireless driver's code and potentially the network namespace teardown process. Let's see if we can identify the lock acquisition order in those functions and spot the issue.
|
| 7/2 |
2026/08/09 12:19 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode:7187: static void __net_exit hwsim_exit_net(struct net *net)
7188: {
7189: struct mac80211_hwsim_data *data, *tmp;
7190: LIST_HEAD(list);
7191:
7192: spin_lock_bh(&hwsim_radio_lock);
7193: list_for_each_entry_safe(data, tmp, &hwsim_radios, list) {
7194: if (!net_eq(wiphy_net(data->hw->wiphy), net))
7195: continue;
7196:
7197: /* Radios created in init_net are returned to init_net. */
7198: if (data->netgroup == hwsim_net_get_netgroup(&init_net))
7199: continue;
7200:
7201: list_move(&data->list, &list);
7202: rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
7203: hwsim_rht_params);
7204: hwsim_radios_generation++;
7205: }
7206: spin_unlock_bh(&hwsim_radio_lock);
7207:
7208: list_for_each_entry_safe(data, tmp, &list, list) {
7209: list_del(&data->list);
7210: mac80211_hwsim_del_radio(data,
7211: wiphy_name(data->hw->wiphy),
7212: NULL);
7213: }
7214:
7215: ida_free(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
7216: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 8/2 |
2026/08/09 12:19 |
llm |
expert |
0m
Model:
Tokens:
input: 9355
output: 31
thoughts: 19
Thoughts: Okay, let's dive into this. Here's my take on `mac80211_hwsim_del_radio`:
**Deconstructing `mac80211_hwsim_del_radio`**
Alright, so the task at hand is `mac80211_hwsim_del_radio`. Right off the bat, I know this is going to be about cleaning up a simulated radio instance within the mac80211 hardware simulation environment. `del_radio` almost screams "destruction" or "removal" β it's the counterpart to whatever function set the radio up in the first place, presumably `mac80211_hwsim_add_radio` or similar.
My mind immediately starts running through the implications. Iβm thinking about the data structures involved: What data structures hold information about this simulated radio? Is it a linked list, an array, a hash table? I'll need to identify the relevant ones. I'll need to consider how this function interacts with those data structures to ensure the simulated radio is cleanly removed.
I'm picturing the common pitfalls. Are we talking about memory leaks? If so, where are the allocated memory regions associated with this particular radio? I'm anticipating the need to `kfree` any dynamically allocated memory, likely including control blocks, and potentially even freeing any associated queues or lists.
What about locking? Is there a mutex or spinlock protecting access to the simulated radio's data? It's crucial we release any locks we hold to prevent deadlocks or race conditions. I need to make sure the code releases the simulated radio from the appropriate data structures safely and doesnβt corrupt any shared state.
I'll be looking for potential side effects, too. Is this radio used in a larger context, perhaps as part of a virtual interface or network device? I'll need to figure out if we have to clean up any references to it elsewhere, and I'll need to make sure that whatever is "using" that radio knows that it's gone. What are the dependencies? I'm anticipating a cascade of clean-up operations that'll likely be required.
Finally, I'll be looking for error handling. What happens if something goes wrong during the clean-up process? Does the function return an error code? Does it log a warning? It needs to be robust and designed to handle unexpected situations gracefully, so that it doesn't leave the kernel in an inconsistent state. Now, let's get into the details...
|
| 9/2 |
2026/08/09 12:19 |
tool |
codesearch-definition-source |
0m
Args: map[Name:mac80211_hwsim_del_radio]
Results: map[SourceCode:6221: static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
6222: const char *hwname,
6223: struct genl_info *info)
6224: {
6225: hwsim_mcast_del_radio(data->idx, hwname, info);
6226: debugfs_remove_recursive(data->debugfs);
6227: ieee80211_unregister_hw(data->hw);
6228: device_release_driver(data->dev);
6229: device_unregister(data->dev);
6230: ieee80211_free_hw(data->hw);
6231: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 10/2 |
2026/08/09 12:19 |
llm |
expert |
0m
Model:
Tokens:
input: 10192
output: 21
thoughts: 982
Thoughts: **Analyzing a Real-Time Mutex Deadlock**
Okay, so `device_lock` is acquired within `device_del`, which is called from `wiphy_unregister`. I need to figure out who else might be holding that lock. The deadlock detection is happening through the real-time mutex mechanism, specifically triggered by `rtmutex`. Is this a legitimate deadlock, or just a lockdep warning? The output is explicitly a `rtmutex deadlock detected`, which means `rt_mutex_handle_deadlock` is the culprit.
Looking at `kernel/locking/rtmutex.c`, it seems that if the return value of `rt_mutex_slowlock` is `-EDEADLK` *and* deadlock detection wasn't specifically requested, the code either triggers a BUG (if debugging is enabled) or issues a `WARN` message. This confirms it's a *real* deadlock, not just a false positive. Now, the question is *why*?
Let's examine `cleanup_net`, because that is in the callstack. It's called from a workqueue. If `rt_mutex_handle_deadlock` has been called, it means `rt_mutex_slowlock` returned `-EDEADLK`. When does that happen? Because `task_blocks_on_rt_mutex` returns `-EDEADLK` in the case of recursion or a cycle of waiters.
So, `device_del` takes `device_lock`. Could `cleanup_net` *already* be holding that lock? I'll review the call trace again: `wiphy_unregister` appears to be taking `device_lock` on the wiphy device, but it is already held. Or maybe it's `device_del` trying to grab `device_lock` on the parent device? I need to dig into `device_del` further.
|
| 11/2 |
2026/08/09 12:19 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode:3902: /**
3903: * device_del - delete device from system.
3904: * @dev: device.
3905: *
3906: * This is the first part of the device unregistration
3907: * sequence. This removes the device from the lists we control
3908: * from here, has it removed from the other driver model
3909: * subsystems it was added to in device_add(), and removes it
3910: * from the kobject hierarchy.
3911: *
3912: * NOTE: this should be called manually _iff_ device_add() was
3913: * also called manually.
3914: */
3915: void device_del(struct device *dev)
3916: {
3917: struct subsys_private *sp;
3918: struct device *parent = dev->parent;
3919: struct kobject *glue_dir = NULL;
3920: struct class_interface *class_intf;
3921: unsigned int noio_flag;
3922:
3923: device_lock(dev);
3924: kill_device(dev);
3925: device_unlock(dev);
3926:
3927: if (dev->fwnode && dev->fwnode->dev == dev)
3928: dev->fwnode->dev = NULL;
3929:
3930: /* Notify clients of device removal. This call must come
3931: * before dpm_sysfs_remove().
3932: */
3933: noio_flag = memalloc_noio_save();
3934: bus_notify(dev, BUS_NOTIFY_DEL_DEVICE);
3935:
3936: dpm_sysfs_remove(dev);
3937: if (parent)
3938: klist_del(&dev->p->knode_parent);
3939: if (MAJOR(dev->devt)) {
3940: devtmpfs_delete_node(dev);
3941: device_remove_sys_dev_entry(dev);
3942: device_remove_file(dev, &dev_attr_dev);
3943: }
3944:
3945: sp = class_to_subsys(dev->class);
3946: if (sp) {
3947: device_remove_class_symlinks(dev);
3948:
3949: mutex_lock(&sp->mutex);
3950: /* notify any interfaces that the device is now gone */
3951: list_for_each_entry(class_intf, &sp->interfaces, node)
3952: if (class_intf->remove_dev)
3953: class_intf->remove_dev(dev);
3954: /* remove the device from the class list */
3955: klist_del(&dev->p->knode_class);
3956: mutex_unlock(&sp->mutex);
3957: subsys_put(sp);
3958: }
3959: device_remove_file(dev, &dev_attr_uevent);
3960: device_remove_attrs(dev);
3961: bus_remove_device(dev);
3962: device_pm_remove(dev);
3963: driver_deferred_probe_del(dev);
3964: device_platform_notify_remove(dev);
3965: device_links_purge(dev);
3966:
3967: /*
3968: * If a device does not have a driver attached, we need to clean
3969: * up any managed resources. We do this in device_release(), but
3970: * it's never called (and we leak the device) if a managed
3971: * resource holds a reference to the device. So release all
3972: * managed resources here, like we do in driver_detach(). We
3973: * still need to do so again in device_release() in case someone
3974: * adds a new resource after this point, though.
3975: */
3976: devres_release_all(dev);
3977:
3978: bus_notify(dev, BUS_NOTIFY_REMOVED_DEVICE);
3979: kobject_uevent(&dev->kobj, KOBJ_REMOVE);
3980: glue_dir = get_glue_dir(dev);
3981: kobject_del(&dev->kobj);
3982: cleanup_glue_dir(dev, glue_dir);
3983: memalloc_noio_restore(noio_flag);
3984: put_device(parent);
3985: }
SourceFile:drivers/base/core.c]
|
| 12/2 |
2026/08/09 12:19 |
llm |
expert |
0m
Model:
Tokens:
input: 12926
output: 22
thoughts: 288
Thoughts: **Analyzing a Potential Deadlock in mac80211_hwsim_del_radio**
Okay, let's break this down. I see that `device_del` takes `device_lock(dev)`. Now, I'm looking at `mac80211_hwsim_del_radio`. It seems like we have a potential conflict here.
First, the code sequence: `ieee80211_unregister_hw`, then `device_release_driver`, and finally `device_unregister` and `ieee80211_free_hw`. The key line is in `ieee80211_unregister_hw` which calls `wiphy_unregister`, and this in turn, calls `device_del(&rdev->wiphy.dev)`. Right, so `wiphy_unregister` appears to be the one calling `device_lock` on the `wiphy` device.
Hold on, `device_release_driver(data->dev)` also takes `device_lock(data->dev)`. The critical question: are `data->dev` and `rdev->wiphy.dev` the same device? No, I'm pretty sure `data->dev` is the parent of `wiphy.dev`. So, it's not the same device.
Hmm, this is strange, but if they are different devices, why would there be a deadlock in the first place? Let's rule some things out. Could `device_lock` already be held by something like `cleanup_net`? No, `cleanup_net` is just a workqueue function.
Okay, let's think about this: `wiphy_unregister` is taking `device_lock` on `rdev->wiphy.dev`. Is it possible that lock is already being held? I think I need to dive deeper and verify that `wiphy_unregister` is the culprit. Let me look at that function carefully. I need to be sure about the locking order and see if there is potential for a lock ordering violation.
|
| 13/2 |
2026/08/09 12:19 |
tool |
codesearch-definition-source |
0m
Args: map[Name:wiphy_unregister]
Results: map[SourceCode:1287: void wiphy_unregister(struct wiphy *wiphy)
1288: {
1289: struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1290:
1291: wait_event(rdev->dev_wait, ({
1292: int __count;
1293: wiphy_lock(&rdev->wiphy);
1294: __count = rdev->opencount;
1295: wiphy_unlock(&rdev->wiphy);
1296: __count == 0; }));
1297:
1298: if (rdev->wiphy.rfkill)
1299: rfkill_unregister(rdev->wiphy.rfkill);
1300:
1301: rtnl_lock();
1302: wiphy_lock(&rdev->wiphy);
1303: nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
1304: rdev->wiphy.registered = false;
1305:
1306: WARN_ON(!list_empty(&rdev->wiphy.wdev_list));
1307:
1308: /*
1309: * First remove the hardware from everywhere, this makes
1310: * it impossible to find from userspace.
1311: */
1312: debugfs_remove_recursive(rdev->wiphy.debugfsdir);
1313: list_del_rcu(&rdev->list);
1314: synchronize_rcu();
1315:
1316: /*
1317: * If this device got a regulatory hint tell core its
1318: * free to listen now to a new shiny device regulatory hint
1319: */
1320: wiphy_regulatory_deregister(wiphy);
1321:
1322: cfg80211_rdev_list_generation++;
1323: device_del(&rdev->wiphy.dev);
1324:
1325: #ifdef CONFIG_PM
1326: if (rdev->wiphy.wowlan_config && rdev->ops->set_wakeup)
1327: rdev_set_wakeup(rdev, false);
1328: #endif
1329:
1330: /* surely nothing is reachable now, clean up work */
1331: cfg80211_process_wiphy_works(rdev, NULL);
1332: wiphy_unlock(&rdev->wiphy);
1333: rtnl_unlock();
1334:
1335: /* this has nothing to do now but make sure it's gone */
1336: cancel_work_sync(&rdev->wiphy_work);
1337:
1338: cancel_work_sync(&rdev->sched_scan_res_wk);
1339: cancel_work_sync(&rdev->rfkill_block);
1340: cancel_work_sync(&rdev->conn_work);
1341: flush_work(&rdev->event_work);
1342: cancel_delayed_work_sync(&rdev->dfs_update_channels_wk);
1343: cancel_delayed_work_sync(&rdev->background_cac_done_wk);
1344: flush_work(&rdev->destroy_work);
1345: flush_work(&rdev->propagate_radar_detect_wk);
1346: flush_work(&rdev->propagate_cac_done_wk);
1347: flush_work(&rdev->mgmt_registrations_update_wk);
1348: flush_work(&rdev->background_cac_abort_wk);
1349:
1350: cfg80211_rdev_free_wowlan(rdev);
1351: cfg80211_free_coalesce(rdev->coalesce);
1352: rdev->coalesce = NULL;
1353: }
SourceFile:net/wireless/core.c]
|
| 14/2 |
2026/08/09 12:19 |
llm |
expert |
0m
Model:
Tokens:
input: 14822
output: 22
thoughts: 185
Thoughts: **Deadlock Potential in Wireless Device Unregistration**
Okay, so I'm looking at `wiphy_unregister`, and it's calling `rtnl_lock()` and then `wiphy_lock(&rdev->wiphy)`. After that, we've got `device_del(&rdev->wiphy.dev)` being called. And *that* function, `device_del`, takes `device_lock(&rdev->wiphy.dev)`. My immediate thought is, "Are we staring down the barrel of a deadlock here?" We have three locks involved: `rtnl_lock`, `wiphy_lock`, and `device_lock`. The sequence seems concerning.
Wait, right, `device_lock` is a mutex, that's crucial. Let's dig deeper to see if there's any cycle present, as this is a common source of deadlock. If `device_lock` is taken, does any subsequent function call then attempt to acquire either `rtnl_lock` or `wiphy_lock`? Or is there another thread out there, sitting on `device_lock`, trying to get `rtnl_lock`? I need to understand the potential locking order. Time to go search for instances where `device_lock` and `rtnl_lock` are used together in the codebase.
|
| 15/2 |
2026/08/09 12:20 |
tool |
grepper |
0m
Error:
Args: map[Expression:device_lock.*rtnl_lock]
Results:
|
| 16/2 |
2026/08/09 12:20 |
llm |
expert |
0m
Model:
Tokens:
input: 15326
output: 23
thoughts: 299
Thoughts: **Debugging a Potential Deadlock**
Okay, so I've hit an `rtmutex deadlock detected` error, which means I've got a circular dependency of tasks waiting on locks. I need to figure out the specific cycle here. My task currently holds `rtnl_lock` and `wiphy_lock`, and I'm waiting for `device_lock`. The obvious approach is to search for `rtnl_lock` inside `device_lock` or the converse, but I have a hunch about what is happening here.
I need to understand who might be holding `device_lock`. Could it be `device_release_driver`? But that's called *after* `ieee80211_unregister_hw` in `mac80211_hwsim_del_radio`, so that can't be it. It's not running yet.
Hmm, but what *else* could be interacting with the device? Maybe another thread is touching the device in some other way. For example, a `sysfs` write to the `unbind` file? That seems likely. If a user tries to unbind the device by writing to `/sys/bus/mac80211_hwsim/devices/hwsim0/driver/unbind`, that will call `device_release_driver`, which definitely takes the `device_lock(dev)`.
The crucial detail here is that `wiphy.dev` is a child device of `hwsim0`. The key question is this: when unbinding, does the `unbind` operation take `device_lock` on the child device? This is the core of the problem. Time to verify how `device_release_driver` works in this scenario. I need to check the code.
|
| 17/2 |
2026/08/09 12:20 |
tool |
codesearch-definition-source |
0m
Args: map[Name:device_release_driver]
Results: map[SourceCode:1377: /**
1378: * device_release_driver - manually detach device from driver.
1379: * @dev: device.
1380: *
1381: * Manually detach device from driver.
1382: * When called for a USB interface, @dev->parent lock must be held.
1383: *
1384: * If this function is to be called with @dev->parent lock held, ensure that
1385: * the device's consumers are unbound in advance or that their locks can be
1386: * acquired under the @dev->parent lock.
1387: */
1388: void device_release_driver(struct device *dev)
1389: {
1390: /*
1391: * If anyone calls device_release_driver() recursively from
1392: * within their ->remove callback for the same device, they
1393: * will deadlock right here.
1394: */
1395: device_release_driver_internal(dev, NULL, NULL);
1396: }
SourceFile:drivers/base/dd.c]
|
| 18/2 |
2026/08/09 12:20 |
llm |
expert |
0m
Model:
Tokens:
input: 16346
output: 25
thoughts: 13
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Internal Driver Release Verification**
Alright, time to dive in. My mind immediately jumps to `device_release_driver_internal`. This function. I'm assuming we're dealing with a driver release process, likely for a specific device, and I need to ensure everything's kosher. I'm focusing on the *internal* aspects because that likely indicates the core mechanics of resource cleanup, state resets, and potentially, error handling within the driver itself. Iβm thinking about potential race conditions during the release, memory leaks if things aren't handled correctly, and the order of operations. Am I looking at a specific issue, or just performing a general audit? Is the function well-documented? Are there any potential areas where it might be vulnerable to misuse or unanticipated scenarios, especially if this driver is complex? Time to dig in and verify its integrity.
|
| 19/2 |
2026/08/09 12:20 |
tool |
codesearch-definition-source |
0m
Args: map[Name:device_release_driver_internal]
Results: map[SourceCode:1365: void device_release_driver_internal(struct device *dev,
1366: const struct device_driver *drv,
1367: struct device *parent)
1368: {
1369: __device_driver_lock(dev, parent);
1370:
1371: if (!drv || drv == dev->driver)
1372: __device_release_driver(dev, parent);
1373:
1374: __device_driver_unlock(dev, parent);
1375: }
SourceFile:drivers/base/dd.c]
|
| 20/2 |
2026/08/09 12:20 |
llm |
expert |
0m
Model:
Tokens:
input: 16770
output: 21
thoughts: 752
Thoughts: **Deadlock Analysis in Device Driver Unregistration**
Okay, so I'm looking at this deadlock report, and my initial thought is that it's probably related to locking order. Specifically, I'm tracing the likely path of the problem. `__device_driver_lock` calls `device_lock(dev)`. That's the starting point. I see `device_release_driver` also taking `device_lock(data->dev)`. And then there's `wiphy_unregister`, which uses `device_lock(&rdev->wiphy.dev)`. Right away, the alarm bells are ringing because these are *different* devices, though `wiphy.dev` is a child of `data->dev`. Could we have a classic parent-child lock ordering issue? Is `device_del` taking `device_lock(parent)`? No, it looks like it's taking the `device_lock(dev)`.
Let's see... what about the context? `cleanup_net` is in the mix, destroying the net namespace. This smells like a possible multi-threaded race but the report says it's a single thread, and if a thread tries to acquire the same lock, `rt_mutex_slowlock` will trigger an error. I need to check whether `device_lock(&rdev->wiphy.dev)` is already held by *this* thread.
Who could have taken it? The trace goes from `cleanup_net` through a series of calls: `ops_undo_list` -> `hwsim_exit_net` -> `mac80211_hwsim_del_radio` -> `ieee80211_unregister_hw` -> `wiphy_unregister` -> `device_del`. I'm going to look carefully at these functions to identify if they hold any locks: `mac80211_hwsim_del_radio` doesn't use `device_lock`. `hwsim_exit_net` only takes `spin_lock_bh(&hwsim_radio_lock)`. `ops_undo_list`? Nope.
Could `device_del` itself be the problem, calling something internally that takes the lock again? Let me check `device_del`: it acquires `device_lock(dev)`, does its thing, and then *unlocks* it. Hmm. Maybe `device_del` is called twice on the same device? If it's called a second time it won't be held.
Now why is it deadlocking? That leads me to think about `rtnl_lock`. `wiphy_unregister` *does* take `rtnl_lock()`. Does `cleanup_net` hold this lock? I need to check it.
|
| 21/2 |
2026/08/09 12:20 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 666: static void cleanup_net(struct work_struct *work)
667: {
668: struct llist_node *net_kill_list;
669: struct net *net, *tmp, *last;
670: LIST_HEAD(net_exit_list);
671:
672: WRITE_ONCE(cleanup_net_task, current);
673:
674: /* Atomically snapshot the list of namespaces to cleanup */
675: net_kill_list = llist_del_all(&cleanup_list);
676:
677: down_read(&pernet_ops_rwsem);
678:
679: /* Don't let anyone else find us. */
680: down_write(&net_rwsem);
681: llist_for_each_entry(net, net_kill_list, cleanup_list) {
682: ns_tree_remove(net);
683: list_del_rcu(&net->list);
684: net->is_dying = true;
685: }
686: /* Cache last net. After we unlock rtnl, no one new net
687: * added to net_namespace_list can assign nsid pointer
688: * to a net from net_kill_list (see peernet2id_alloc()).
689: * So, we skip them in unhash_nsid().
690: *
691: * Note, that unhash_nsid() does not delete nsid links
692: * between net_kill_list's nets, as they've already
693: * deleted from net_namespace_list. But, this would be
694: * useless anyway, as netns_ids are destroyed there.
695: */
696: last = list_last_entry(&net_namespace_list, struct net, list);
697: up_write(&net_rwsem);
698:
699: unhash_nsid(last);
700:
701: llist_for_each_entry(net, net_kill_list, cleanup_list) {
702: idr_destroy(&net->netns_ids);
703: list_add_tail(&net->exit_list, &net_exit_list);
704: }
705:
706: ops_undo_list(&pernet_list, NULL, &net_exit_list, true);
707:
708: up_read(&pernet_ops_rwsem);
709:
710: /* Ensure there are no outstanding rcu callbacks using this
711: * network namespace.
712: */
713: rcu_barrier();
714:
715: net_complete_free();
716:
717: /* Finally it is safe to free my network namespace structure */
718: list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) {
719: list_del_init(&net->exit_list);
720: ns_common_free(net);
721: dec_net_namespaces(net->ucounts);
722: #ifdef CONFIG_KEYS
723: key_remove_domain(net->key_domain);
724: #endif
725: put_user_ns(net->user_ns);
726: net_passive_dec(net);
727: }
728: WRITE_ONCE(cleanup_net_task, NULL);
729: }
SourceFile:net/core/net_namespace.c]
|
| 22/2 |
2026/08/09 12:20 |
llm |
expert |
0m
Model:
Tokens:
input: 19182
output: 25
thoughts: 347
Thoughts: **Analyzing Potential Deadlock in Network Device Removal**
Okay, so I'm looking at `cleanup_net`, and I see it *doesn't* hold `rtnl_lock`. Right, `rtnl_lock` is a mutex, which immediately raises a flag. I need to be careful with locking order. If `wiphy_unregister` grabs `rtnl_lock` and then calls `device_del`, which in turn calls `device_lock`, I need to identify *any* potential reverse order scenario. My expert intuition is telling me this could be a tricky one.
The first thing I'm doing is checking for any functions where `device_lock` is held *before* `rtnl_lock` is acquired. I'm going to look at the locking patterns. I'm thinking, for example, of `mac80211_hwsim_del_radio`. It calls `ieee80211_unregister_hw`, and that leads to `wiphy_unregister` which does take `rtnl_lock` *and* then `device_lock`.
But⦠what if `mac80211_hwsim_del_radio` is called from a sysfs attribute? Aha! Sysfs attributes are a potential vector. I need to quickly recall the locking context for sysfs calls. Wait⦠no, sysfs attributes are *not* called with `device_lock` held. *But*, `device_release_driver` does indeed take `device_lock(dev)`. That's the key.
Let me break this down further: if a user unbinds the driver via sysfs, the call chain is `unbind_store` -> `device_release_driver` -> `device_lock(dev)` -> `device_release_driver_internal` -> `drv->remove(dev)`. And for `mac80211_hwsim`, the `remove` callback is `mac80211_hwsim_remove`. Okay, so now I just need to verify how `mac80211_hwsim_remove`, or any related function, interacts with `rtnl_lock`. That's the critical path to examine.
|
| 23/2 |
2026/08/09 12:21 |
tool |
grepper |
0m
Args: map[Expression:mac80211_hwsim_remove]
Results: map[Output:drivers/net/wireless/virtual/mac80211_hwsim_main.c=2366=static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw,
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-2386-
drivers/net/wireless/virtual/mac80211_hwsim_main.c:2387:static void mac80211_hwsim_remove_interface(
drivers/net/wireless/virtual/mac80211_hwsim_main.c-2388- struct ieee80211_hw *hw, struct ieee80211_vif *vif)
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=3352=static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw,
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-3362-
drivers/net/wireless/virtual/mac80211_hwsim_main.c:3363:static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw,
drivers/net/wireless/virtual/mac80211_hwsim_main.c-3364- struct ieee80211_chanctx_conf *ctx)
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=4251=static int mac80211_hwsim_set_radar_background(struct ieee80211_hw *hw,
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-4282- .change_interface = mac80211_hwsim_change_interface, \
drivers/net/wireless/virtual/mac80211_hwsim_main.c:4283: .remove_interface = mac80211_hwsim_remove_interface, \
drivers/net/wireless/virtual/mac80211_hwsim_main.c-4284- .config = mac80211_hwsim_config, \
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=4317=static const struct ieee80211_ops mac80211_hwsim_ops = {
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-4333- .add_chanctx = mac80211_hwsim_add_chanctx, \
drivers/net/wireless/virtual/mac80211_hwsim_main.c:4334: .remove_chanctx = mac80211_hwsim_remove_chanctx, \
drivers/net/wireless/virtual/mac80211_hwsim_main.c-4335- .change_chanctx = mac80211_hwsim_change_chanctx, \
]
|
| 24/2 |
2026/08/09 12:21 |
llm |
expert |
0m
Model:
Tokens:
input: 20844
output: 31
thoughts: 41
Thoughts: Okay, let's see...
**Delving into `mac80211_hwsim` Device Deletion**
Right, so `mac80211_hwsim` is responsible for setting up these virtual devices, which is key. Now I need to figure out the deletion process. My primary focus is understanding when and how `mac80211_hwsim_del_radio` gets called. That's the crucial function here. I need to trace its call paths to grasp the lifecycle management of these simulated radios. Understanding this deletion path is paramount to ensuring proper resource cleanup and preventing potential issues. Let's dig in and see the control flow.
|
| 25/2 |
2026/08/09 12:21 |
tool |
codesearch-find-references |
0m
Args: map[Name:mac80211_hwsim_del_radio]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hwsim_del_radio_nl SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c SourceLine:6951] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hwsim_exit_net SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c SourceLine:7210] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:mac80211_hwsim_free SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c SourceLine:6292] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:remove_user_radios SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c SourceLine:7130]] TruncatedOutput:false]
|
| 26/2 |
2026/08/09 12:21 |
llm |
expert |
0m
Model:
Tokens:
input: 21347
output: 31
thoughts: 135
Thoughts: **Analyzing the Hardware Simulation Radio Removal Process**
Okay, let's break down how this simulated radio cleanup is supposed to work. My initial understanding, based on these call traces, is that `hwsim_del_radio_nl` is triggered through Netlink, likely when a user wants to remove a simulated radio. Similarly, the `mac80211_hwsim_free` and `remove_user_radios` functions are clearly called during module exit, which makes sense for general cleanup when the module unloads. And, `hwsim_exit_net`, as the name implies, seems to handle cleanup upon a network namespace exiting.
Crucially, none of these obvious candidates are *directly* called from the driver's `remove` callback. This makes me a bit uneasy. I was expecting a more integrated approach there. This suggests a different mechanism for radio removal triggered by the driver itself.
Wait a minute... I need to double-check something. Let's revisit `mac80211_hwsim_del_radio`. Ah, yes, there it is! `mac80211_hwsim_del_radio` *does* call `device_release_driver(data->dev)`. That's the link. So the driver removal is indirectly triggered by the device release, which should then allow the driver's own `remove` function to run. Okay, this is making more sense now. Iβll need to confirm that this flow is correctly implemented and doesnβt introduce any subtle race conditions. The dependency is there, but I need to analyze the implications of releasing the device driver in the context of the overall system.
|
| 27/2 |
2026/08/09 12:21 |
tool |
codesearch-definition-source |
0m
Args: map[Name:mac80211_hwsim_del_radio]
Results: map[SourceCode:6221: static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
6222: const char *hwname,
6223: struct genl_info *info)
6224: {
6225: hwsim_mcast_del_radio(data->idx, hwname, info);
6226: debugfs_remove_recursive(data->debugfs);
6227: ieee80211_unregister_hw(data->hw);
6228: device_release_driver(data->dev);
6229: device_unregister(data->dev);
6230: ieee80211_free_hw(data->hw);
6231: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 28/2 |
2026/08/09 12:21 |
llm |
expert |
0m
Model:
Tokens:
input: 22116
output: 26
thoughts: 428
Thoughts: **Deadlock Investigation: A Deep Dive into Device Locking and Netlink Interactions**
Okay, so I'm looking at this driver and I'm starting to suspect a potential deadlock scenario. I see that `device_release_driver(data->dev)` is taking `device_lock(data->dev)`. That's standard practice, makes sense. But then, `ieee80211_unregister_hw(data->hw)` calls `wiphy_unregister`, which, in turn, takes `device_lock(&rdev->wiphy.dev)`. Now, the crucial part is that `wiphy.dev` is a child of `data->dev`. Alarm bells are starting to go off - are we in a locking order violation situation here?
But wait. No, the `device_lock` is a separate mutex for each `struct device`. So, acquiring the child lock doesn't block if the parent lock is held and vice-versa. Good, that avoids one obvious problem. Now, if the `rt_mutex_handle_deadlock` function is triggered, it would indicate a circular dependency.
Okay, let's think about this more broadly. What if the deadlock is happening due to the `rtnl_lock`? Could `wiphy_unregister` be trying to take `rtnl_lock` when it's already held by someone else? I need to verify what else is running. Let's look again at what happens during `cleanup_net`. This calls `ops_undo_list`, which, in turn, calls `hwsim_exit_net`. Does `cleanup_net` hold `rtnl_lock`? I remember something about that.
Yes, here it is: `cleanup_net` explicitly states that it *doesn't* hold `rtnl_lock`. It's careful about that. It's holding `net_rwsem` and `pernet_ops_rwsem`, not `rtnl_lock`.
Okay, so not that. But wait, what if `hwsim_exit_net` gets called by `hwsim_del_radio_nl`? My radar is up, because I remember that `hwsim_del_radio_nl` is a netlink handler. And netlink handlers for `mac80211_hwsim` *might* be called with `rtnl_lock` already held! That's the real potential issue. I need to go and check `hwsim_del_radio_nl` closely. I've got a feeling that's where the problem is.
|
| 29/2 |
2026/08/09 12:21 |
tool |
codesearch-definition-source |
0m
Args: map[Name:hwsim_del_radio_nl]
Results: map[SourceCode:6915: static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
6916: {
6917: struct mac80211_hwsim_data *data;
6918: s64 idx = -1;
6919: const char *hwname = NULL;
6920:
6921: if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
6922: idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
6923: } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
6924: hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
6925: nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
6926: GFP_KERNEL);
6927: if (!hwname)
6928: return -ENOMEM;
6929: } else
6930: return -EINVAL;
6931:
6932: spin_lock_bh(&hwsim_radio_lock);
6933: list_for_each_entry(data, &hwsim_radios, list) {
6934: if (idx >= 0) {
6935: if (data->idx != idx)
6936: continue;
6937: } else {
6938: if (!hwname ||
6939: strcmp(hwname, wiphy_name(data->hw->wiphy)))
6940: continue;
6941: }
6942:
6943: if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
6944: continue;
6945:
6946: list_del(&data->list);
6947: rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
6948: hwsim_rht_params);
6949: hwsim_radios_generation++;
6950: spin_unlock_bh(&hwsim_radio_lock);
6951: mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
6952: info);
6953: kfree(hwname);
6954: return 0;
6955: }
6956: spin_unlock_bh(&hwsim_radio_lock);
6957:
6958: kfree(hwname);
6959: return -ENODEV;
6960: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 30/2 |
2026/08/09 12:21 |
llm |
expert |
0m
Model:
Tokens:
input: 23915
output: 27
thoughts: 685
Thoughts: **Analyzing a Potential Deadlock in a Generic Netlink Handler**
Okay, so I'm looking at this `hwsim_del_radio_nl` function, which I know is a generic netlink handler. And these handlers, by default, don't hold the `rtnl_lock` unless specifically configured to. The interesting thing is that the deadlock is happening inside `cleanup_net`, and that function is being called from a workqueue. This means there's an asynchronous component to the issue, which adds a layer of complexity.
Let me re-examine the call trace; it's right here: `__rt_mutex_slowlock`, then `__rt_mutex_slowlock_locked`, and down the line to `cleanup_net`. Seeing `rt_mutex_slowlock` in the trace is the key. Now, if `rt_mutex_slowlock` flags a deadlock, that means one of two things: either the current task is trying to acquire the same lock it already holds, which is a classic self-deadlock, or there's a circular dependency β a cycle of tasks trying to grab each other's locks. Since lockdep, which is a useful tool, is not reporting the issue and instead we see a direct "rtmutex deadlock detected", this hints that it could be a self-deadlock scenario. This suggests the kernel's own `rtmutex` deadlock detection is kicking in.
Wait, `rtmutex` has its own, internal deadlock detection mechanism, independent of the general lockdep! Now, if `CONFIG_DEBUG_RT_MUTEXES` isn't enabled, what does `rt_mutex_handle_deadlock` do? Usually, in this case, it just prints a warning. Okay, so that explains why it's not being explicitly reported by lockdep. The kernel's deadlock handling is the first line of defense. Now, what triggers a call to `rt_mutex_handle_deadlock`? The answer must be in `task_blocks_on_rt_mutex` - if it returns `-EDEADLK` then that is a sure sign of a deadlock. I need to dive into that function and understand its behavior in this context. I'll need to see how the task blocking is checked to understand how we got here.
|
| 31/2 |
2026/08/09 12:21 |
tool |
codesearch-definition-source |
0m
Args: map[Name:task_blocks_on_rt_mutex]
Results: map[SourceCode:1205: /*
1206: * Task blocks on lock.
1207: *
1208: * Prepare waiter and propagate pi chain
1209: *
1210: * This must be called with lock->wait_lock held and interrupts disabled
1211: */
1212: static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock,
1213: struct rt_mutex_waiter *waiter,
1214: struct task_struct *task,
1215: struct ww_acquire_ctx *ww_ctx,
1216: enum rtmutex_chainwalk chwalk,
1217: struct wake_q_head *wake_q)
1218: __must_hold(&lock->wait_lock)
1219: {
1220: struct task_struct *owner = rt_mutex_owner(lock);
1221: struct rt_mutex_waiter *top_waiter = waiter;
1222: struct rt_mutex_base *next_lock;
1223: int chain_walk = 0, res;
1224:
1225: lockdep_assert_held(&lock->wait_lock);
1226:
1227: /*
1228: * Early deadlock detection. We really don't want the task to
1229: * enqueue on itself just to untangle the mess later. It's not
1230: * only an optimization. We drop the locks, so another waiter
1231: * can come in before the chain walk detects the deadlock. So
1232: * the other will detect the deadlock and return -EDEADLOCK,
1233: * which is wrong, as the other waiter is not in a deadlock
1234: * situation.
1235: *
1236: * Except for ww_mutex, in that case the chain walk must already deal
1237: * with spurious cycles, see the comments at [3] and [6].
1238: */
1239: if (owner == task && !(build_ww_mutex() && ww_ctx))
1240: return -EDEADLK;
1241:
1242: raw_spin_lock(&task->pi_lock);
1243: waiter->task = task;
1244: waiter->lock = lock;
1245: waiter_update_prio(waiter, task);
1246: waiter_clone_prio(waiter, task);
1247:
1248: /* Get the top priority waiter on the lock */
1249: if (rt_mutex_has_waiters(lock))
1250: top_waiter = rt_mutex_top_waiter(lock);
1251: rt_mutex_enqueue(lock, waiter);
1252:
1253: task->pi_blocked_on = waiter;
1254:
1255: raw_spin_unlock(&task->pi_lock);
1256:
1257: if (build_ww_mutex() && ww_ctx) {
1258: struct rt_mutex *rtm;
1259:
1260: /* Check whether the waiter should back out immediately */
1261: rtm = container_of(lock, struct rt_mutex, rtmutex);
1262: __assume_ctx_lock(&rtm->rtmutex.wait_lock);
1263: res = __ww_mutex_add_waiter(waiter, rtm, ww_ctx, wake_q);
1264: if (res) {
1265: raw_spin_lock(&task->pi_lock);
1266: rt_mutex_dequeue(lock, waiter);
1267: task->pi_blocked_on = NULL;
1268: raw_spin_unlock(&task->pi_lock);
1269: return res;
1270: }
1271: }
1272:
1273: if (!owner)
1274: return 0;
1275:
1276: raw_spin_lock(&owner->pi_lock);
1277: if (waiter == rt_mutex_top_waiter(lock)) {
1278: rt_mutex_dequeue_pi(owner, top_waiter);
1279: rt_mutex_enqueue_pi(owner, waiter);
1280:
1281: rt_mutex_adjust_prio(lock, owner);
1282: if (owner->pi_blocked_on)
1283: chain_walk = 1;
1284: } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
1285: chain_walk = 1;
1286: }
1287:
1288: /* Store the lock on which owner is blocked or NULL */
1289: next_lock = task_blocked_on_lock(owner);
1290:
1291: raw_spin_unlock(&owner->pi_lock);
1292: /*
1293: * Even if full deadlock detection is on, if the owner is not
1294: * blocked itself, we can avoid finding this out in the chain
1295: * walk.
1296: */
1297: if (!chain_walk || !next_lock)
1298: return 0;
1299:
1300: /*
1301: * The owner can't disappear while holding a lock,
1302: * so the owner struct is protected by wait_lock.
1303: * Gets dropped in rt_mutex_adjust_prio_chain()!
1304: */
1305: get_task_struct(owner);
1306:
1307: raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q);
1308:
1309: res = rt_mutex_adjust_prio_chain(owner, chwalk, lock,
1310: next_lock, waiter, task);
1311:
1312: raw_spin_lock_irq(&lock->wait_lock);
1313:
1314: return res;
1315: }
SourceFile:kernel/locking/rtmutex.c]
|
| 32/2 |
2026/08/09 12:21 |
llm |
expert |
0m
Model:
Tokens:
input: 26848
output: 21
thoughts: 488
Thoughts: **Analyzing a Potential Deadlock in the Kernel**
Okay, so I'm tracking down this `-EDEADLK` return from `task_blocks_on_rt_mutex`. It seems the problem arises either because the current task already owns the mutex, which is early deadlock detection, or due to a cycle being detected within the `rt_mutex_adjust_prio_chain`. I'm focused on the case where the task is trying to acquire a lock it already holds. My immediate thought is, "Is `device_lock` held by the same task?". Let's double-check if `device_lock` is being taken twice.
I've got `wiphy_unregister` in my sights because it calls `device_del(&rdev->wiphy.dev)`, which, in turn, calls `device_lock(dev)`. My concern is whether `device_lock` is *already* held when `device_del` attempts to take it. I eliminated `cleanup_net` and `hwsim_exit_net` because, at first glance, they don't seem to hold the lock. `hwsim_exit_net` only uses `spin_lock_bh(&hwsim_radio_lock)`.
Then I looked at `mac80211_hwsim_del_radio`. Aha! That function calls `ieee80211_unregister_hw` which leads to `wiphy_unregister`, and ultimately `device_del`. Critically, `mac80211_hwsim_del_radio` *also* calls `device_release_driver(data->dev)`, which takes `device_lock(data->dev)`. This strongly suggests that `device_lock(data->dev)` is taken *after* `ieee80211_unregister_hw` (and thus `device_del`). But where is `mac80211_hwsim_del_radio` called from? From `hwsim_exit_net` according to the call trace.
Wait a second, could there be a recursive call to `device_lock` *within* `device_del`? That's the key question. We have to examine `device_del` itself to be sure. It could be possible that `device_del` takes the lock and then internally attempts to acquire it again. That's the next step.
|
| 33/2 |
2026/08/09 12:21 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode:3902: /**
3903: * device_del - delete device from system.
3904: * @dev: device.
3905: *
3906: * This is the first part of the device unregistration
3907: * sequence. This removes the device from the lists we control
3908: * from here, has it removed from the other driver model
3909: * subsystems it was added to in device_add(), and removes it
3910: * from the kobject hierarchy.
3911: *
3912: * NOTE: this should be called manually _iff_ device_add() was
3913: * also called manually.
3914: */
3915: void device_del(struct device *dev)
3916: {
3917: struct subsys_private *sp;
3918: struct device *parent = dev->parent;
3919: struct kobject *glue_dir = NULL;
3920: struct class_interface *class_intf;
3921: unsigned int noio_flag;
3922:
3923: device_lock(dev);
3924: kill_device(dev);
3925: device_unlock(dev);
3926:
3927: if (dev->fwnode && dev->fwnode->dev == dev)
3928: dev->fwnode->dev = NULL;
3929:
3930: /* Notify clients of device removal. This call must come
3931: * before dpm_sysfs_remove().
3932: */
3933: noio_flag = memalloc_noio_save();
3934: bus_notify(dev, BUS_NOTIFY_DEL_DEVICE);
3935:
3936: dpm_sysfs_remove(dev);
3937: if (parent)
3938: klist_del(&dev->p->knode_parent);
3939: if (MAJOR(dev->devt)) {
3940: devtmpfs_delete_node(dev);
3941: device_remove_sys_dev_entry(dev);
3942: device_remove_file(dev, &dev_attr_dev);
3943: }
3944:
3945: sp = class_to_subsys(dev->class);
3946: if (sp) {
3947: device_remove_class_symlinks(dev);
3948:
3949: mutex_lock(&sp->mutex);
3950: /* notify any interfaces that the device is now gone */
3951: list_for_each_entry(class_intf, &sp->interfaces, node)
3952: if (class_intf->remove_dev)
3953: class_intf->remove_dev(dev);
3954: /* remove the device from the class list */
3955: klist_del(&dev->p->knode_class);
3956: mutex_unlock(&sp->mutex);
3957: subsys_put(sp);
3958: }
3959: device_remove_file(dev, &dev_attr_uevent);
3960: device_remove_attrs(dev);
3961: bus_remove_device(dev);
3962: device_pm_remove(dev);
3963: driver_deferred_probe_del(dev);
3964: device_platform_notify_remove(dev);
3965: device_links_purge(dev);
3966:
3967: /*
3968: * If a device does not have a driver attached, we need to clean
3969: * up any managed resources. We do this in device_release(), but
3970: * it's never called (and we leak the device) if a managed
3971: * resource holds a reference to the device. So release all
3972: * managed resources here, like we do in driver_detach(). We
3973: * still need to do so again in device_release() in case someone
3974: * adds a new resource after this point, though.
3975: */
3976: devres_release_all(dev);
3977:
3978: bus_notify(dev, BUS_NOTIFY_REMOVED_DEVICE);
3979: kobject_uevent(&dev->kobj, KOBJ_REMOVE);
3980: glue_dir = get_glue_dir(dev);
3981: kobject_del(&dev->kobj);
3982: cleanup_glue_dir(dev, glue_dir);
3983: memalloc_noio_restore(noio_flag);
3984: put_device(parent);
3985: }
SourceFile:drivers/base/core.c]
|
| 34/2 |
2026/08/09 12:21 |
llm |
expert |
1m
Model:
Tokens:
input: 29205
output: 25
thoughts: 993
Thoughts: **Analyzing a Potential Deadlock in Device Deletion**
Okay, so `device_del` is the culprit, and it looks like it's blocking on `device_lock(dev)`. That's line 3923 in `drivers/base/core.c`. The stack trace clearly shows the wait on `device_lock`, which is concerning. The lock is already held by another task or by this very task, which is a potential cycle. If it's the current task, there's a serious bug in the locking order.
Let's quickly check `wiphy_unregister` to see if *it* might be acquiring `device_lock`. No, it takes `wiphy_lock` and `rtnl_lock` instead. Hmm, but could `wiphy_unregister` be called from a context that already *holds* `device_lock`? No, the stacktrace clearly says no.
So, the lock must be held by *another* task, which means a cycle is occurring. This is where things get interesting. What's the other task doing? What is it waiting on? It is holding `device_lock(dev)` and is waiting for `rtnl_lock`, `wiphy_lock`, `net_rwsem`, or `pernet_ops_rwsem` to become free.
Wait a moment, `cleanup_net` acquires `net_rwsem` and `pernet_ops_rwsem`. Let's confirm: it takes the read lock on `pernet_ops_rwsem` *before* calling `ops_undo_list`. Could the other task be holding `device_lock(dev)` and waiting for `pernet_ops_rwsem`? What takes `pernet_ops_rwsem`? Functions like `register_pernet_subsys` and `unregister_pernet_subsys`. It seems unlikely that any of them would hold `device_lock` while dealing with `pernet_ops_rwsem`, though.
Let's turn to `rtnl_lock`. `wiphy_unregister` does take `rtnl_lock`. This is important, as the current task holds `pernet_ops_rwsem` (read), `rtnl_lock`, and `wiphy_lock`. Aha! `wiphy_unregister` does indeed acquire `rtnl_lock` *before* calling `device_del`.
So, the current task holds `rtnl_lock`. If another task holds `device_lock(dev)` and is waiting for `rtnl_lock`, we've got a classic deadlock scenario! Is there a path where a task holds `device_lock` and waits for `rtnl_lock`? In the networking stack, there are *many* such paths. Particularly when sysfs attributes for network devices are involved. The `wiphy.dev` is a `struct device`. Does it have any sysfs attributes that might use `rtnl_lock`? Let's check `net/wireless/sysfs.c`.
|
| 35/2 |
2026/08/09 12:22 |
tool |
codesearch-definition-source |
0m
Args: map[Name:wiphy_sysfs_init]
Results: map[SourceCode: 179: int wiphy_sysfs_init(void)
180: {
181: return class_register(&ieee80211_class);
182: }
SourceFile:net/wireless/sysfs.c]
|
| 36/2 |
2026/08/09 12:22 |
llm |
expert |
0m
Model:
Tokens:
input: 30960
output: 25
thoughts: 20
Thoughts: Okay, here's my take on those thoughts, framed for an expert audience:
**Diving into the `ieee80211_class` Sysfs Attributes**
Alright, time to get my hands dirty. I'm thinking, let's start by digging into the sysfs attributes associated with the `ieee80211_class`. This is my usual first step whenever I'm dealing with the wireless stack and want to understand the current configuration or diagnose some behavior. I need to refresh my memory on what's exposed, see if there are any obvious flags set, or maybe uncover some hidden configuration knobs that are relevant to this current troubleshooting session. I'm expecting to find information about the class ID, possibly some operational flags, and definitely the device count associated with this class. I also need to verify that what I'm expecting to see is actually there and hasn't changed in the current kernel version. If I'm lucky, I'll find a clear indication of the root cause or at least a good starting point for further investigation, especially if this relates to some wireless device performance issue.
|
| 37/2 |
2026/08/09 12:22 |
tool |
grepper |
0m
Error:
Args: map[Expression:DEVICE_ATTR.*ieee80211]
Results:
|
| 38/2 |
2026/08/09 12:22 |
llm |
expert |
0m
Model:
Tokens:
input: 31255
output: 31
thoughts: 20
Thoughts: Here's a first-person summary, tailored for an expert audience, based on the prompt:
**Diving into the Sysfs Implementation**
Okay, so we need to understand how these wireless attributes are exposed through sysfs. My first instinct, and honestly, the most logical place to start, is `net/wireless/sysfs.c`. That file is practically *the* central hub for sysfs interactions within the wireless subsystem. Given how the kernel organizes its structure, I'm expecting `DEVICE_ATTR` macros to be at the heart of the matter. This should give me the entry points, the read/write handlers, and the crucial links to the underlying wireless device structures. From there, I can trace through the associated functions to see how the data flow works and what specific wireless configuration is being exposed to userspace. I'm especially interested in how the interface is structured, how the data is managed (locking, caching, etc.), and how the access permissions are handled. This is the starting point for understanding and potentially extending this sysfs interface.
|
| 39/2 |
2026/08/09 12:22 |
tool |
grepper |
0m
Args: map[Expression:DEVICE_ATTR PathPrefix:net/wireless/sysfs.c]
Results: map[Output:net/wireless/sysfs.c=28=static ssize_t name ## _show(struct device *dev, \
--
net/wireless/sysfs.c-33-} \
net/wireless/sysfs.c:34:static DEVICE_ATTR_RO(name)
net/wireless/sysfs.c-35-
--
net/wireless/sysfs.c=40=static ssize_t name_show(struct device *dev,
--
net/wireless/sysfs.c-47-}
net/wireless/sysfs.c:48:static DEVICE_ATTR_RO(name);
net/wireless/sysfs.c-49-
net/wireless/sysfs.c=50=static ssize_t addresses_show(struct device *dev,
--
net/wireless/sysfs.c-65-}
net/wireless/sysfs.c:66:static DEVICE_ATTR_RO(addresses);
net/wireless/sysfs.c-67-
]
|
| 40/2 |
2026/08/09 12:22 |
llm |
expert |
0m
Model:
Tokens:
input: 31773
output: 21
thoughts: 18
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating Functionality: name\_show or addresses\_show**
Okay, so I'm looking at some code, probably in a debugging or exploration context. My immediate thought is to zero in on specific functions: `name_show` and `addresses_show`. I'm trying to quickly understand their purpose and impact. I need to get a handle on what's going on. I'm likely trying to figure out how data related to names and addresses is handled and presented within the application. Perhaps I'm trying to identify a bug, trace data flow, or even refactor this area. The naming suggests these are likely view functions or functions responsible for displaying data. I need to check the code! I want to understand what exactly they *do*, so I'm diving in.
|
| 41/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 50: static ssize_t addresses_show(struct device *dev,
51: struct device_attribute *attr,
52: char *buf)
53: {
54: struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
55: char *start = buf;
56: int i;
57:
58: if (!wiphy->addresses)
59: return sprintf(buf, "%pM\n", wiphy->perm_addr);
60:
61: for (i = 0; i < wiphy->n_addresses; i++)
62: buf += sprintf(buf, "%pM\n", wiphy->addresses[i].addr);
63:
64: return buf - start;
65: }
SourceFile:net/wireless/sysfs.c]
|
| 42/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 32248
output: 32
thoughts: 22
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, and delivered as a first-person summary:
**Digging into Attribute Locking in the Network Stack**
Alright, so I was just looking at the `addresses_show` function, and it struck me β it doesn't seem to be acquiring the `rtnl_lock`. That's a bit of a surprise, as I would have expected a read operation on address data to be protected by that lock, especially given the concurrent nature of network configuration. This raises immediate questions in my mind, and I need to investigate further.
My immediate follow-up thought is, if `addresses_show` is skipping the lock, which other attributes or data structures might also be operating without the protection of `rtnl_lock`? Is this a consistent pattern across other network device or address attributes, or is it isolated to this specific function? I need to understand the design rationale behind this decision β is it performance-driven, based on the specific read characteristics, or is it a potential race condition waiting to happen? I'm going to have to dive deeper into the code and data access patterns to get to the bottom of this. Specifically, I'll need to explore any potential synchronization mechanisms, or the lack thereof, that are in place to ensure data integrity during concurrent access. It's a key area to scrutinize for potential vulnerabilities or subtle bugs.
|
| 43/2 |
2026/08/09 12:23 |
tool |
grepper |
0m
Args: map[Expression:rtnl_lock PathPrefix:net/wireless/sysfs.c]
Results: map[Output:net/wireless/sysfs.c=94=static int wiphy_suspend(struct device *dev)
--
net/wireless/sysfs.c-100-
net/wireless/sysfs.c:101: rtnl_lock();
net/wireless/sysfs.c-102- if (!rdev->wiphy.registered)
--
net/wireless/sysfs.c=133=static int wiphy_resume(struct device *dev)
--
net/wireless/sysfs.c-140-
net/wireless/sysfs.c:141: rtnl_lock();
net/wireless/sysfs.c-142- wiphy_lock(&rdev->wiphy);
]
|
| 44/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 32786
output: 23
thoughts: 55
Thoughts: **Analyzing wiphy_suspend and wiphy_resume's Locking Behavior**
Right, here's what I'm seeing: `wiphy_suspend` and `wiphy_resume` grab the `rtnl_lock`. That's important. And, if I recall correctly, the Power Management core (PM core) is the one actually calling these functions. The PM core could potentially be holding `device_lock`. So, we've got a potential lock ordering issue here - `rtnl_lock` *after* a `device_lock` might be held. This seems like something that needs a closer look. I'll start by diving into `wiphy_suspend` and see exactly what's happening within that function.
|
| 45/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 94: static int wiphy_suspend(struct device *dev)
95: {
96: struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
97: int ret = 0;
98:
99: rdev->suspend_at = ktime_get_boottime_seconds();
100:
101: rtnl_lock();
102: if (!rdev->wiphy.registered)
103: goto out_unlock_rtnl;
104:
105: if (rdev->wiphy.wowlan_config) {
106: scoped_guard(wiphy, &rdev->wiphy) {
107: cfg80211_process_wiphy_works(rdev, NULL);
108: if (rdev->ops->suspend)
109: ret = rdev_suspend(rdev,
110: rdev->wiphy.wowlan_config);
111: if (ret <= 0)
112: goto out_unlock_rtnl;
113: }
114: }
115:
116: /* Driver refused to configure wowlan (ret = 1) or no wowlan */
117:
118: cfg80211_leave_all(rdev);
119: scoped_guard(wiphy, &rdev->wiphy) {
120: cfg80211_process_rdev_events(rdev);
121: cfg80211_process_wiphy_works(rdev, NULL);
122: if (rdev->ops->suspend)
123: ret = rdev_suspend(rdev, NULL);
124: }
125: out_unlock_rtnl:
126: if (ret == 0)
127: rdev->suspended = true;
128: rtnl_unlock();
129:
130: return ret;
131: }
SourceFile:net/wireless/sysfs.c]
|
| 46/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 33635
output: 34
thoughts: 78
Thoughts: **Analyzing the Potential for Deadlock in Wireless Device Suspension**
Okay, so I'm digging into this `wiphy_suspend` function. The first thing that jumps out is that it grabs the `rtnl_lock()`. Now, the key question is whether `wiphy_suspend` *itself* is ever called while holding a `device_lock(dev)`. That's the critical point for a potential deadlock scenario.
Hmm, yes! I remember now. The PM core, when it calls the suspend/resume callbacks for a device, *guarantees* that the `device_lock(dev)` is held. Excellent, that clarifies things. We need to be absolutely sure the locking order is safe.
Alright, let's take a look at `device_suspend` in `drivers/base/power/main.c`. It's time to trace the execution path and identify how `wiphy_suspend` interacts within the broader device suspension sequence. We need to be super meticulous here.
|
| 47/2 |
2026/08/09 12:23 |
tool |
grepper |
0m
Args: map[Expression:device_lock.*dev PathPrefix:drivers/base/power/main.c]
Results: map[Output:drivers/base/power/main.c=1099=static void device_resume(struct device *dev, pm_message_t state, bool async)
--
drivers/base/power/main.c-1133- dpm_watchdog_set(&wd, dev);
drivers/base/power/main.c:1134: device_lock(dev);
drivers/base/power/main.c-1135-
--
drivers/base/power/main.c=1266=static void device_complete(struct device *dev, pm_message_t state)
--
drivers/base/power/main.c-1273-
drivers/base/power/main.c:1274: device_lock(dev);
drivers/base/power/main.c-1275-
--
drivers/base/power/main.c=1926=static void device_suspend(struct device *dev, pm_message_t state, bool async)
--
drivers/base/power/main.c-1986- dpm_watchdog_set(&wd, dev);
drivers/base/power/main.c:1987: device_lock(dev);
drivers/base/power/main.c-1988-
--
drivers/base/power/main.c=2185=static int device_prepare(struct device *dev, pm_message_t state)
--
drivers/base/power/main.c-2208-
drivers/base/power/main.c:2209: device_lock(dev);
drivers/base/power/main.c-2210-
]
|
| 48/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 34379
output: 26
thoughts: 644
Thoughts: **Deadlock Analysis in Wireless Device Power Management**
Okay, so I've got this scenario in front of me, and it screams deadlock. Let me walk you through my thought process.
First, I see `device_suspend` grabbing `device_lock(dev)` and then invoking the suspend callbacks. That's the starting point. If a device is suspending, the PM core holds `device_lock(dev)` and calls `wiphy_suspend`. Now, `wiphy_suspend` waits for `rtnl_lock()`. Got it.
Concurrently, I've got `cleanup_net`. This is where it gets interesting. Is `cleanup_net` holding `rtnl_lock()`? I had to double-check that. Let's look at the code snippet again⦠Nope! It doesn't hold `rtnl_lock()`. It uses `down_read(&pernet_ops_rwsem)` and `down_write(&net_rwsem)`, which is distinct. `cleanup_net` calls `wiphy_unregister`, which *does* need `device_lock(dev)`.
So, `wiphy_unregister` takes `rtnl_lock()` *first*, then `wiphy_lock()`, then *finally* `device_lock(dev)` inside `device_del`. On the other hand, if `wiphy_suspend` is running at the same time, it acquires `device_lock(dev)` through the PM core, *then* attempts to grab `rtnl_lock()`.
Ah, there it is. Classic AB-BA deadlock situation!
Let's break it down:
* **Task 1 (`wiphy_unregister`):**
1. `rtnl_lock()`
2. `device_lock(dev)` (inside `device_del`)
* **Task 2 (`wiphy_suspend`):**
1. `device_lock(dev)` (inside `device_suspend`)
2. `rtnl_lock()`
This is *exactly* the deadlock condition.
Now, the crucial question. Is this deadlock exploitable? Can an unprivileged user trigger this? To trigger it, we need `wiphy_unregister` and `wiphy_suspend` to run concurrently.
Can an unprivileged user trigger `wiphy_unregister`? That's the key. I remember `mac80211_hwsim`, which lets you create and delete virtual radios. Can an unprivileged user create and delete those radios? Let's go look at `hwsim_new_radio_nl` and `hwsim_del_radio_nl` and see. This could be a significant vulnerability!
|
| 49/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Args: map[Name:hwsim_new_radio_nl]
Results: map[SourceCode:6755: static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
6756: {
6757: struct hwsim_new_radio_params param = { 0 };
6758: const char *hwname = NULL;
6759: int ret;
6760:
6761: param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
6762: param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
6763: param.nan_device = info->attrs[HWSIM_ATTR_SUPPORT_NAN_DEVICE];
6764: param.channels = channels;
6765: param.destroy_on_close =
6766: info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE];
6767:
6768: if (info->attrs[HWSIM_ATTR_CHANNELS])
6769: param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
6770:
6771: if (param.channels < 1) {
6772: GENL_SET_ERR_MSG(info, "must have at least one channel");
6773: return -EINVAL;
6774: }
6775:
6776: if (info->attrs[HWSIM_ATTR_NO_VIF])
6777: param.no_vif = true;
6778:
6779: if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
6780: param.use_chanctx = true;
6781: else
6782: param.use_chanctx = (param.channels > 1);
6783:
6784: if (info->attrs[HWSIM_ATTR_MULTI_RADIO])
6785: param.multi_radio = true;
6786:
6787: if (info->attrs[HWSIM_ATTR_SUPPORT_BACKGROUND_RADAR])
6788: param.background_radar = true;
6789:
6790: if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
6791: param.reg_alpha2 =
6792: nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
6793:
6794: if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
6795: u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
6796:
6797: if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
6798: return -EINVAL;
6799:
6800: idx = array_index_nospec(idx,
6801: ARRAY_SIZE(hwsim_world_regdom_custom));
6802: param.regd = hwsim_world_regdom_custom[idx];
6803: }
6804:
6805: if (info->attrs[HWSIM_ATTR_PERM_ADDR]) {
6806: if (!is_valid_ether_addr(
6807: nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) {
6808: GENL_SET_ERR_MSG(info,"MAC is no valid source addr");
6809: NL_SET_BAD_ATTR(info->extack,
6810: info->attrs[HWSIM_ATTR_PERM_ADDR]);
6811: return -EINVAL;
6812: }
6813:
6814: param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]);
6815: }
6816:
6817: if (info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]) {
6818: param.iftypes =
6819: nla_get_u32(info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]);
6820:
6821: if (param.iftypes & ~HWSIM_IFTYPE_SUPPORT_MASK) {
6822: NL_SET_ERR_MSG_ATTR(info->extack,
6823: info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT],
6824: "cannot support more iftypes than kernel");
6825: return -EINVAL;
6826: }
6827: } else {
6828: param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
6829: }
6830:
6831: /* ensure both flag and iftype support is honored */
6832: if (param.p2p_device ||
6833: param.iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
6834: param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
6835: param.p2p_device = true;
6836: }
6837:
6838: if (param.nan_device) {
6839: if (param.multi_radio) {
6840: NL_SET_ERR_MSG(info->extack,
6841: "NAN is not supported on multi-radio wiphys");
6842: return -EINVAL;
6843: }
6844: param.iftypes |= BIT(NL80211_IFTYPE_NAN) |
6845: BIT(NL80211_IFTYPE_NAN_DATA);
6846: }
6847:
6848: if (info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]) {
6849: u32 len = nla_len(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
6850:
6851: param.ciphers =
6852: nla_data(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
6853:
6854: if (len % sizeof(u32)) {
6855: NL_SET_ERR_MSG_ATTR(info->extack,
6856: info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
6857: "bad cipher list length");
6858: return -EINVAL;
6859: }
6860:
6861: param.n_ciphers = len / sizeof(u32);
6862:
6863: if (param.n_ciphers > ARRAY_SIZE(hwsim_ciphers)) {
6864: NL_SET_ERR_MSG_ATTR(info->extack,
6865: info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
6866: "too many ciphers specified");
6867: return -EINVAL;
6868: }
6869:
6870: if (!hwsim_known_ciphers(param.ciphers, param.n_ciphers)) {
6871: NL_SET_ERR_MSG_ATTR(info->extack,
6872: info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
6873: "unsupported ciphers specified");
6874: return -EINVAL;
6875: }
6876: }
6877:
6878: param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT];
6879:
6880: if (param.mlo || param.multi_radio)
6881: param.use_chanctx = true;
6882:
6883: if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
6884: hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
6885: nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
6886: GFP_KERNEL);
6887: if (!hwname)
6888: return -ENOMEM;
6889: param.hwname = hwname;
6890: }
6891:
6892: if (info->attrs[HWSIM_ATTR_PMSR_SUPPORT]) {
6893: struct cfg80211_pmsr_capabilities *pmsr_capa;
6894:
6895: pmsr_capa = kzalloc_obj(*pmsr_capa);
6896: if (!pmsr_capa) {
6897: ret = -ENOMEM;
6898: goto out_free;
6899: }
6900: param.pmsr_capa = pmsr_capa;
6901:
6902: ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT], pmsr_capa, info);
6903: if (ret)
6904: goto out_free;
6905: }
6906:
6907: ret = mac80211_hwsim_new_radio(info, ¶m);
6908:
6909: out_free:
6910: kfree(hwname);
6911: kfree(param.pmsr_capa);
6912: return ret;
6913: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 50/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 38348
output: 25
thoughts: 38
Thoughts: **Analyzing `hwsim_new_radio_nl`'s Potential Security Implications**
Okay, so `hwsim_new_radio_nl`... that immediately jumped out as a netlink handler. My first thought is, is this something that could be accessed by a process without any special privileges? Netlink interfaces, in general, are a common attack vector if not properly locked down. This warrants further investigation, so I need to check the netlink family definition. I need to understand the access control on this specific handler. That's the key to figuring out the potential for a privilege escalation or other security vulnerability here. I need to know *who* can talk to this thing.
|
| 51/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Error:
Args:
Results: map[SourceCode: SourceFile:]
|
| 52/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 38575
output: 49
thoughts: 19
Thoughts: Here's my thought process, as if I were analyzing that text:
**Digging into the `hwsim_new_radio_nl` File Search**
Okay, so I see a directive to look for `"hwsim_new_radio_nl"` within a file. That immediately tells me this is likely related to the hardware simulator ("hwsim") and some sort of network layer interaction (the "nl" probably standing for Netlink, a common Linux inter-process communication mechanism). The "new_radio" suggests either a new radio technology or a new way to simulate it within the hwsim framework. I'll need to know the context: what project, what codebase, what version? However, my first step is clear - I need to open the specified file and search for that exact string. That keyword is key - so I'll be looking for any instance of the string `hwsim_new_radio_nl`. Hopefully, this will lead me to the relevant code that manages or utilizes this specific "new radio" functionality within the simulator. I suspect this will be the heart of a change or a new feature's implementation. Once I find it, the surrounding code will tell the story of the function.
|
| 53/2 |
2026/08/09 12:23 |
tool |
grepper |
0m
Args: map[Expression:hwsim_new_radio_nl PathPrefix:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
Results: map[Output:drivers/net/wireless/virtual/mac80211_hwsim_main.c=6716=static int parse_pmsr_capa(const struct nlattr *pmsr_capa, struct cfg80211_pmsr_capabilities *out,
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-6754-
drivers/net/wireless/virtual/mac80211_hwsim_main.c:6755:static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
drivers/net/wireless/virtual/mac80211_hwsim_main.c-6756-{
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=7055=static const struct genl_small_ops hwsim_ops[] = {
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7074- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7075: .doit = hwsim_new_radio_nl,
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7076- .flags = GENL_UNS_ADMIN_PERM,
]
|
| 54/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 39275
output: 52
thoughts: 599
Thoughts: **Analyzing a Potential Race Condition**
Okay, so I'm looking at this code and the `.flags = GENL_UNS_ADMIN_PERM` is the key right now. This means it needs `CAP_NET_ADMIN` within the user namespace. Right, so a user namespace is involved, which makes this interesting. `GENL_UNS_ADMIN_PERM` lets a user with `CAP_NET_ADMIN` in *their* namespace trigger this. So, it's user namespace accessible, that's good to know.
Now, the bug report mentions `cleanup_net` is getting triggered. Ah, right, that runs when a network namespace is destroyed. Okay, so an unprivileged user can create a user namespace, then a network namespace, and then create a hwsim radio because of `CAP_NET_ADMIN`. They could then destroy the network namespace by exiting it. That triggers `cleanup_net`, which means `hwsim_exit_net`, and that means `mac80211_hwsim_del_radio`. And that eventually gets to `wiphy_unregister`, which is the dangerous part.
`wiphy_unregister` takes the `rtnl_lock()` and then the `device_lock(dev)`. That's a potential concurrency issue. If at the same time, the system is suspending, `wiphy_suspend` would be called which takes `device_lock(dev)` and *then* the `rtnl_lock()`.
Wait, can an unprivileged user trigger a system suspend? No, suspend needs root, that's not a viable path. But, is there any other way to trigger `wiphy_suspend` or something else that takes `device_lock(dev)` and then the `rtnl_lock()`? Let's check `wiphy_resume` and `unbind` through sysfs... It's the same thing for `wiphy_resume`. What about `unbind`? Ah! If a user writes to `/sys/bus/mac80211_hwsim/devices/hwsim0/driver/unbind`, that calls `device_release_driver`, and that takes `device_lock(dev)`.
So, does `mac80211_hwsim_remove` grab the `rtnl_lock()`? I'll need to check the code around `mac80211_hwsim_remove` or something related. Wait, since `mac80211_hwsim` is virtual, it doesn't even *have* a `remove` callback for the device! Okay... Wait, `mac80211_hwsim_del_radio` calls `device_release_driver(data->dev)`. Does `mac80211_hwsim_driver` have a `remove` callback? That's the next step, I think I'm onto something here.
|
| 55/2 |
2026/08/09 12:23 |
tool |
grepper |
0m
Args: map[Expression:mac80211_hwsim_driver PathPrefix:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
Results: map[Output:drivers/net/wireless/virtual/mac80211_hwsim_main.c=679=static int hwsim_radios_generation = 1;
drivers/net/wireless/virtual/mac80211_hwsim_main.c-680-
drivers/net/wireless/virtual/mac80211_hwsim_main.c:681:static struct platform_driver mac80211_hwsim_driver = {
drivers/net/wireless/virtual/mac80211_hwsim_main.c-682- .driver = {
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=5651=static int mac80211_hwsim_new_radio(struct genl_info *info,
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-5702- }
drivers/net/wireless/virtual/mac80211_hwsim_main.c:5703: data->dev->driver = &mac80211_hwsim_driver.driver;
drivers/net/wireless/virtual/mac80211_hwsim_main.c-5704- err = device_bind_driver(data->dev);
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=7460=static int __init init_mac80211_hwsim(void)
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7477-
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7478: err = platform_driver_register(&mac80211_hwsim_driver);
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7479- if (err)
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7610-out_unregister_driver:
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7611: platform_driver_unregister(&mac80211_hwsim_driver);
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7612-out_unregister_pernet:
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=7620=static void __exit exit_mac80211_hwsim(void)
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7630- unregister_netdev(hwsim_mon);
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7631: platform_driver_unregister(&mac80211_hwsim_driver);
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7632- unregister_pernet_device(&hwsim_net_ops);
]
|
| 56/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 41345
output: 29
thoughts: 19
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the `mac80211_hwsim_driver` Definition**
Okay, I'm thinking I need to refresh my memory on the specifics of the `mac80211_hwsim_driver`. It's been a minute since I last dug into the guts of that particular piece of code. I'll need to go back and check the actual definition. I want to make sure I have the exact structure and internal workings clear in my head before I go any further down this line of thinking. Time to get a quick overview of what's what.
|
| 57/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Args: map[Name:mac80211_hwsim_driver]
Results: map[SourceCode: 681: static struct platform_driver mac80211_hwsim_driver = {
682: .driver = {
683: .name = "mac80211_hwsim",
684: },
685: };
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 58/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 41653
output: 31
thoughts: 974
Thoughts: **Analyzing a Potential Kernel Deadlock in Wireless Driver Unregistration**
Okay, so I'm looking at this kernel deadlock report and it's throwing up some flags. The system's reporting a single thread deadlock, which means the thread is trying to acquire a lock it *already* holds. That's never good.
First off, there's no obvious `remove` callback for this device, so unbinding via sysfs wouldn't trigger anything that takes the `rtnl_lock()`. I need to figure out the path here. Is there some other call that uses `device_lock(dev)` and then `rtnl_lock()`? Let me see... Wait, what about `wiphy_unregister`?
Aha! `wiphy_unregister` *could* be a candidate. If it's called from `hwsim_del_radio_nl`, it takes `rtnl_lock()` and then `device_lock(dev)`. But, hang on, `hwsim_del_radio_nl` doesn't seem to touch `device_lock(dev)`. That doesn't seem to work, though.
Hmm, this deadlock is reported as a *single* thread. The backtrace shows `rt_mutex_handle_deadlock`. That means the thread is trying to reacquire a lock it already has! The stack trace looks like this: `device_del` and then `wiphy_unregister`. `wiphy_unregister` calls `device_del`.
So, the key question: is `device_lock` already held? Let's trace it back to `mac80211_hwsim_del_radio`. Let's look at that function again.
```c
static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
const char *hwname,
struct genl_info *info)
{
hwsim_mcast_del_radio(data->idx, hwname, info);
debugfs_remove_recursive(data->debugfs);
ieee80211_unregister_hw(data->hw);
device_release_driver(data->dev);
device_unregister(data->dev);
ieee80211_free_hw(data->hw);
}
```
`ieee80211_unregister_hw` eventually calls `wiphy_unregister`, which does a `device_del(&rdev->wiphy.dev)`. Now we're getting somewhere. Is `wiphy.dev` *the same* as `data->dev`? If so, this is where the deadlock occurs. I need to track down how these devices are created to confirm. This looks like the smoking gun.
|
| 59/2 |
2026/08/09 12:23 |
tool |
codesearch-definition-source |
0m
Args: map[Name:mac80211_hwsim_new_radio]
Results: map[SourceCode:5651: static int mac80211_hwsim_new_radio(struct genl_info *info,
5652: struct hwsim_new_radio_params *param)
5653: {
5654: int err;
5655: u8 addr[ETH_ALEN];
5656: struct mac80211_hwsim_data *data;
5657: struct ieee80211_hw *hw;
5658: enum nl80211_band band;
5659: const struct ieee80211_ops *ops = &mac80211_hwsim_ops;
5660: struct net *net;
5661: int idx, i;
5662: int n_limits = 0;
5663: int n_bands = 0;
5664:
5665: if (WARN_ON(param->channels > 1 && !param->use_chanctx))
5666: return -EINVAL;
5667:
5668: spin_lock_bh(&hwsim_radio_lock);
5669: idx = hwsim_radio_idx++;
5670: spin_unlock_bh(&hwsim_radio_lock);
5671:
5672: if (param->mlo)
5673: ops = &mac80211_hwsim_mlo_ops;
5674: else if (param->use_chanctx)
5675: ops = &mac80211_hwsim_mchan_ops;
5676: hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname);
5677: if (!hw) {
5678: pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n");
5679: err = -ENOMEM;
5680: goto failed;
5681: }
5682:
5683: /* ieee80211_alloc_hw_nm may have used a default name */
5684: param->hwname = wiphy_name(hw->wiphy);
5685:
5686: if (info)
5687: net = genl_info_net(info);
5688: else
5689: net = &init_net;
5690: wiphy_net_set(hw->wiphy, net);
5691:
5692: data = hw->priv;
5693: data->hw = hw;
5694:
5695: data->dev = device_create(&hwsim_class, NULL, 0, hw, "hwsim%d", idx);
5696: if (IS_ERR(data->dev)) {
5697: printk(KERN_DEBUG
5698: "mac80211_hwsim: device_create failed (%ld)\n",
5699: PTR_ERR(data->dev));
5700: err = -ENOMEM;
5701: goto failed_drvdata;
5702: }
5703: data->dev->driver = &mac80211_hwsim_driver.driver;
5704: err = device_bind_driver(data->dev);
5705: if (err != 0) {
5706: pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n",
5707: err);
5708: goto failed_bind;
5709: }
5710:
5711: skb_queue_head_init(&data->pending);
5712:
5713: SET_IEEE80211_DEV(hw, data->dev);
5714: if (!param->perm_addr) {
5715: eth_zero_addr(addr);
5716: addr[0] = 0x02;
5717: addr[3] = idx >> 8;
5718: addr[4] = idx;
5719: memcpy(data->addresses[0].addr, addr, ETH_ALEN);
5720: /* Why need here second address ? */
5721: memcpy(data->addresses[1].addr, addr, ETH_ALEN);
5722: data->addresses[1].addr[0] |= 0x40;
5723: memcpy(data->addresses[2].addr, addr, ETH_ALEN);
5724: data->addresses[2].addr[0] |= 0x50;
5725:
5726: hw->wiphy->n_addresses = 3;
5727: hw->wiphy->addresses = data->addresses;
5728: /* possible address clash is checked at hash table insertion */
5729: } else {
5730: memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN);
5731: /* compatibility with automatically generated mac addr */
5732: memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN);
5733: memcpy(data->addresses[2].addr, param->perm_addr, ETH_ALEN);
5734: hw->wiphy->n_addresses = 3;
5735: hw->wiphy->addresses = data->addresses;
5736: }
5737:
5738: data->channels = param->channels;
5739: data->use_chanctx = param->use_chanctx;
5740: data->idx = idx;
5741: data->destroy_on_close = param->destroy_on_close;
5742: if (info)
5743: data->portid = info->snd_portid;
5744:
5745: /* setup interface limits, only on interface types we support */
5746: if (param->iftypes & BIT(NL80211_IFTYPE_ADHOC)) {
5747: data->if_limits[n_limits].max = 1;
5748: data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_ADHOC);
5749: n_limits++;
5750: }
5751:
5752: if (param->iftypes & HWSIM_DEFAULT_IF_LIMIT) {
5753: data->if_limits[n_limits].max = 2048;
5754: /*
5755: * For this case, we may only support a subset of
5756: * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the
5757: * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have.
5758: */
5759: data->if_limits[n_limits].types =
5760: HWSIM_DEFAULT_IF_LIMIT & param->iftypes;
5761: n_limits++;
5762: }
5763:
5764: if (param->iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
5765: data->if_limits[n_limits].max = 1;
5766: data->if_limits[n_limits].types =
5767: BIT(NL80211_IFTYPE_P2P_DEVICE);
5768: n_limits++;
5769: }
5770:
5771: if (param->iftypes & BIT(NL80211_IFTYPE_NAN)) {
5772: data->if_limits[n_limits].max = 1;
5773: data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_NAN);
5774: n_limits++;
5775:
5776: hw->wiphy->nan_supported_bands = BIT(NL80211_BAND_2GHZ) |
5777: BIT(NL80211_BAND_5GHZ);
5778:
5779: hw->wiphy->nan_capa.flags = WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC |
5780: WIPHY_NAN_FLAGS_USERSPACE_DE;
5781: hw->wiphy->nan_capa.op_mode = NAN_OP_MODE_PHY_MODE_MASK |
5782: NAN_OP_MODE_80P80MHZ |
5783: NAN_OP_MODE_160MHZ;
5784:
5785: hw->wiphy->nan_capa.n_antennas = 0x22;
5786: hw->wiphy->nan_capa.max_channel_switch_time = 0;
5787:
5788: wiphy_ext_feature_set(hw->wiphy,
5789: NL80211_EXT_FEATURE_SECURE_NAN);
5790:
5791: hrtimer_setup(&data->nan.slot_timer,
5792: mac80211_hwsim_nan_slot_timer,
5793: CLOCK_BOOTTIME, HRTIMER_MODE_ABS_SOFT);
5794: hrtimer_setup(&data->nan.resume_txqs_timer,
5795: mac80211_hwsim_nan_resume_txqs_timer,
5796: CLOCK_BOOTTIME, HRTIMER_MODE_ABS_SOFT);
5797: hrtimer_setup(&data->nan.discovery_beacon_timer,
5798: mac80211_hwsim_nan_discovery_beacon_timer,
5799: CLOCK_BOOTTIME, HRTIMER_MODE_ABS_SOFT);
5800:
5801: spin_lock_init(&data->nan.state_lock);
5802: }
5803:
5804: if (param->iftypes & BIT(NL80211_IFTYPE_NAN_DATA)) {
5805: data->if_limits[n_limits].max = 2;
5806: data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_NAN_DATA);
5807: n_limits++;
5808:
5809: hw->wiphy->nan_capa.phy.ht = hwsim_nan_ht_cap;
5810: hw->wiphy->nan_capa.phy.vht = hwsim_nan_vht_cap;
5811: hw->wiphy->nan_capa.phy.he = hwsim_nan_he_cap;
5812:
5813: /*
5814: * NAN switches between bands/channels per its schedule,
5815: * so mac80211 rate control can't work here.
5816: */
5817: ieee80211_hw_set(hw, HAS_RATE_CONTROL);
5818: }
5819:
5820: data->if_combination.radar_detect_widths =
5821: BIT(NL80211_CHAN_WIDTH_5) |
5822: BIT(NL80211_CHAN_WIDTH_10) |
5823: BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5824: BIT(NL80211_CHAN_WIDTH_20) |
5825: BIT(NL80211_CHAN_WIDTH_40) |
5826: BIT(NL80211_CHAN_WIDTH_80) |
5827: BIT(NL80211_CHAN_WIDTH_160);
5828:
5829: if (data->use_chanctx) {
5830: hw->wiphy->max_scan_ssids = 255;
5831: hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
5832: hw->wiphy->max_remain_on_channel_duration = 1000;
5833: data->if_combination.num_different_channels = data->channels;
5834: } else {
5835: data->if_combination.num_different_channels = 1;
5836: }
5837:
5838: if (!n_limits) {
5839: err = -EINVAL;
5840: goto failed_hw;
5841: }
5842:
5843: data->if_combination.max_interfaces = 0;
5844: for (i = 0; i < n_limits; i++)
5845: data->if_combination.max_interfaces +=
5846: data->if_limits[i].max;
5847:
5848: data->if_combination.n_limits = n_limits;
5849: data->if_combination.limits = data->if_limits;
5850:
5851: /*
5852: * If we actually were asked to support combinations,
5853: * advertise them - if there's only a single thing like
5854: * only IBSS then don't advertise it as combinations.
5855: */
5856: if (data->if_combination.max_interfaces > 1) {
5857: hw->wiphy->iface_combinations = &data->if_combination;
5858: hw->wiphy->n_iface_combinations = 1;
5859: }
5860:
5861: if (param->ciphers) {
5862: memcpy(data->ciphers, param->ciphers,
5863: param->n_ciphers * sizeof(u32));
5864: hw->wiphy->cipher_suites = data->ciphers;
5865: hw->wiphy->n_cipher_suites = param->n_ciphers;
5866: }
5867:
5868: hw->wiphy->mbssid_max_interfaces = 8;
5869: hw->wiphy->ema_max_profile_periodicity = 3;
5870:
5871: spin_lock_init(&data->tsf_offset_lock);
5872:
5873: data->rx_rssi = DEFAULT_RX_RSSI;
5874:
5875: INIT_DELAYED_WORK(&data->roc_start, hw_roc_start);
5876: INIT_DELAYED_WORK(&data->roc_done, hw_roc_done);
5877: INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work);
5878:
5879: hw->queues = 5;
5880: hw->offchannel_tx_hw_queue = 4;
5881:
5882: ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
5883: ieee80211_hw_set(hw, CHANCTX_STA_CSA);
5884: ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
5885: ieee80211_hw_set(hw, QUEUE_CONTROL);
5886: ieee80211_hw_set(hw, WANT_MONITOR_VIF);
5887: ieee80211_hw_set(hw, AMPDU_AGGREGATION);
5888: ieee80211_hw_set(hw, MFP_CAPABLE);
5889: ieee80211_hw_set(hw, SIGNAL_DBM);
5890: ieee80211_hw_set(hw, SUPPORTS_PS);
5891: ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
5892: ieee80211_hw_set(hw, TDLS_WIDER_BW);
5893: ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
5894: ieee80211_hw_set(hw, STRICT);
5895: ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
5896: ieee80211_hw_set(hw, STA_MMPDU_TXQ);
5897:
5898: if (param->mlo) {
5899: hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
5900: ieee80211_hw_set(hw, HAS_RATE_CONTROL);
5901: ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
5902: ieee80211_hw_set(hw, CONNECTION_MONITOR);
5903: ieee80211_hw_set(hw, AP_LINK_PS);
5904:
5905: hw->wiphy->iftype_ext_capab = mac80211_hwsim_iftypes_ext_capa;
5906: hw->wiphy->num_iftype_ext_capab =
5907: ARRAY_SIZE(mac80211_hwsim_iftypes_ext_capa);
5908: } else {
5909: ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
5910: ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
5911: if (rctbl)
5912: ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
5913: }
5914:
5915: hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
5916: hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
5917: WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5918: WIPHY_FLAG_AP_UAPSD |
5919: WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5920: hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
5921: hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
5922: NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
5923: NL80211_FEATURE_STATIC_SMPS |
5924: NL80211_FEATURE_DYNAMIC_SMPS |
5925: NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
5926: NL80211_FEATURE_AP_SCAN;
5927: wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
5928: wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
5929: wiphy_ext_feature_set(hw->wiphy,
5930: NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
5931: wiphy_ext_feature_set(hw->wiphy,
5932: NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
5933: wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
5934:
5935: wiphy_ext_feature_set(hw->wiphy,
5936: NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
5937: wiphy_ext_feature_set(hw->wiphy,
5938: NL80211_EXT_FEATURE_BSS_COLOR);
5939: wiphy_ext_feature_set(hw->wiphy,
5940: NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
5941: wiphy_ext_feature_set(hw->wiphy,
5942: NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
5943: wiphy_ext_feature_set(hw->wiphy,
5944: NL80211_EXT_FEATURE_EXT_KEY_ID);
5945: wiphy_ext_feature_set(hw->wiphy,
5946: NL80211_EXT_FEATURE_ASSOC_FRAME_ENCRYPTION);
5947:
5948: hw->wiphy->interface_modes = param->iftypes;
5949:
5950: /* ask mac80211 to reserve space for magic */
5951: hw->vif_data_size = sizeof(struct hwsim_vif_priv);
5952: hw->sta_data_size = sizeof(struct hwsim_sta_priv);
5953: hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv);
5954: hw->txq_data_size = 0;
5955:
5956: memcpy(data->channels_2ghz, hwsim_channels_2ghz,
5957: sizeof(hwsim_channels_2ghz));
5958: memcpy(data->channels_5ghz, hwsim_channels_5ghz,
5959: sizeof(hwsim_channels_5ghz));
5960: memcpy(data->channels_6ghz, hwsim_channels_6ghz,
5961: sizeof(hwsim_channels_6ghz));
5962: memcpy(data->channels_s1g, hwsim_channels_s1g,
5963: sizeof(hwsim_channels_s1g));
5964: memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
5965:
5966: for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
5967: struct ieee80211_supported_band *sband = &data->bands[band];
5968: struct wiphy_radio_freq_range *radio_range;
5969: const struct ieee80211_channel *c;
5970: struct wiphy_radio *radio;
5971:
5972: sband->band = band;
5973:
5974: switch (band) {
5975: case NL80211_BAND_2GHZ:
5976: sband->channels = data->channels_2ghz;
5977: sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz);
5978: sband->bitrates = data->rates;
5979: sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
5980: break;
5981: case NL80211_BAND_5GHZ:
5982: sband->channels = data->channels_5ghz;
5983: sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz);
5984: sband->bitrates = data->rates + 4;
5985: sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
5986:
5987: sband->vht_cap.vht_supported = true;
5988: sband->vht_cap.cap =
5989: IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
5990: IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ |
5991: IEEE80211_VHT_CAP_RXLDPC |
5992: IEEE80211_VHT_CAP_SHORT_GI_80 |
5993: IEEE80211_VHT_CAP_SHORT_GI_160 |
5994: IEEE80211_VHT_CAP_TXSTBC |
5995: IEEE80211_VHT_CAP_RXSTBC_4 |
5996: IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
5997: sband->vht_cap.vht_mcs.rx_mcs_map =
5998: cpu_to_le16(HWSIM_VHT_MCS_MAP);
5999: sband->vht_cap.vht_mcs.tx_mcs_map =
6000: sband->vht_cap.vht_mcs.rx_mcs_map;
6001: break;
6002: case NL80211_BAND_6GHZ:
6003: sband->channels = data->channels_6ghz;
6004: sband->n_channels = ARRAY_SIZE(hwsim_channels_6ghz);
6005: sband->bitrates = data->rates + 4;
6006: sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
6007: break;
6008: case NL80211_BAND_S1GHZ:
6009: memcpy(&sband->s1g_cap, &hwsim_s1g_cap,
6010: sizeof(sband->s1g_cap));
6011: sband->channels = data->channels_s1g;
6012: sband->n_channels = ARRAY_SIZE(hwsim_channels_s1g);
6013: break;
6014: default:
6015: continue;
6016: }
6017:
6018: if (band != NL80211_BAND_6GHZ){
6019: sband->ht_cap.ht_supported = true;
6020: sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
6021: IEEE80211_HT_CAP_GRN_FLD |
6022: IEEE80211_HT_CAP_SGI_20 |
6023: IEEE80211_HT_CAP_SGI_40 |
6024: IEEE80211_HT_CAP_DSSSCCK40 |
6025: IEEE80211_HT_CAP_TX_STBC |
6026: IEEE80211_HT_CAP_RX_STBC;
6027: sband->ht_cap.ampdu_factor = 0x3;
6028: sband->ht_cap.ampdu_density = 0x6;
6029: memset(&sband->ht_cap.mcs, 0,
6030: sizeof(sband->ht_cap.mcs));
6031: sband->ht_cap.mcs.rx_mask[0] = 0xff;
6032: sband->ht_cap.mcs.rx_mask[1] = 0xff;
6033: sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
6034: }
6035:
6036: mac80211_hwsim_sband_capab(sband);
6037:
6038: hw->wiphy->bands[band] = sband;
6039:
6040: if (!param->multi_radio)
6041: continue;
6042:
6043: c = sband->channels;
6044: radio_range = &data->radio_range[n_bands];
6045: radio_range->start_freq = ieee80211_channel_to_khz(c) - 10000;
6046:
6047: c += sband->n_channels - 1;
6048: radio_range->end_freq = ieee80211_channel_to_khz(c) + 10000;
6049:
6050: radio = &data->radio[n_bands++];
6051: radio->freq_range = radio_range;
6052: radio->n_freq_range = 1;
6053: radio->iface_combinations = &data->if_combination_radio;
6054: radio->n_iface_combinations = 1;
6055: }
6056:
6057: if (param->multi_radio) {
6058: hw->wiphy->radio = data->radio;
6059: hw->wiphy->n_radio = n_bands;
6060:
6061: memcpy(&data->if_combination_radio, &data->if_combination,
6062: sizeof(data->if_combination));
6063: data->if_combination.num_different_channels *= n_bands;
6064: }
6065:
6066: if (data->use_chanctx)
6067: data->if_combination.radar_detect_widths = 0;
6068:
6069: /* By default all radios belong to the first group */
6070: data->group = 1;
6071: mutex_init(&data->mutex);
6072:
6073: data->netgroup = hwsim_net_get_netgroup(net);
6074: data->wmediumd = hwsim_net_get_wmediumd(net);
6075:
6076: /* Enable frame retransmissions for lossy channels */
6077: hw->max_rates = 4;
6078: hw->max_rate_tries = 11;
6079:
6080: hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands;
6081: hw->wiphy->n_vendor_commands =
6082: ARRAY_SIZE(mac80211_hwsim_vendor_commands);
6083: hw->wiphy->vendor_events = mac80211_hwsim_vendor_events;
6084: hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events);
6085:
6086: if (param->reg_strict)
6087: hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
6088: if (param->regd) {
6089: data->regd = param->regd;
6090: hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6091: wiphy_apply_custom_regulatory(hw->wiphy, param->regd);
6092: /* give the regulatory workqueue a chance to run */
6093: schedule_timeout_interruptible(1);
6094: }
6095:
6096: wiphy_ext_feature_set(hw->wiphy,
6097: NL80211_EXT_FEATURE_DFS_CONCURRENT);
6098: if (param->background_radar)
6099: wiphy_ext_feature_set(hw->wiphy,
6100: NL80211_EXT_FEATURE_RADAR_BACKGROUND);
6101:
6102: if (param->no_vif)
6103: ieee80211_hw_set(hw, NO_AUTO_VIF);
6104:
6105: wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
6106: wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_PUNCT);
6107:
6108: for (i = 0; i < ARRAY_SIZE(data->link_data); i++) {
6109: hrtimer_setup(&data->link_data[i].beacon_timer, mac80211_hwsim_beacon,
6110: CLOCK_MONOTONIC, HRTIMER_MODE_ABS_SOFT);
6111: data->link_data[i].link_id = i;
6112: }
6113:
6114: err = ieee80211_register_hw(hw);
6115: if (err < 0) {
6116: pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
6117: err);
6118: goto failed_hw;
6119: }
6120:
6121: wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr);
6122:
6123: if (param->reg_alpha2) {
6124: data->alpha2[0] = param->reg_alpha2[0];
6125: data->alpha2[1] = param->reg_alpha2[1];
6126: regulatory_hint(hw->wiphy, param->reg_alpha2);
6127: }
6128:
6129: data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir);
6130: debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
6131: debugfs_create_file("group", 0666, data->debugfs, data,
6132: &hwsim_fops_group);
6133: debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
6134: &hwsim_fops_rx_rssi);
6135: if (!data->use_chanctx)
6136: debugfs_create_file("dfs_simulate_radar", 0222,
6137: data->debugfs,
6138: data, &hwsim_simulate_radar);
6139: if (param->background_radar)
6140: debugfs_create_file("dfs_background_cac", 0200,
6141: data->debugfs,
6142: data, &hwsim_background_cac_ops);
6143: debugfs_create_file("simulate_incumbent_signal_interference", 0200,
6144: data->debugfs,
6145: data, &hwsim_simulate_incumbent_signal_fops);
6146:
6147: if (param->pmsr_capa) {
6148: data->pmsr_capa = *param->pmsr_capa;
6149: hw->wiphy->pmsr_capa = &data->pmsr_capa;
6150: }
6151:
6152: spin_lock_bh(&hwsim_radio_lock);
6153: err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht,
6154: hwsim_rht_params);
6155: if (err < 0) {
6156: if (info) {
6157: GENL_SET_ERR_MSG(info, "perm addr already present");
6158: NL_SET_BAD_ATTR(info->extack,
6159: info->attrs[HWSIM_ATTR_PERM_ADDR]);
6160: }
6161: spin_unlock_bh(&hwsim_radio_lock);
6162: goto failed_final_insert;
6163: }
6164:
6165: list_add_tail(&data->list, &hwsim_radios);
6166: hwsim_radios_generation++;
6167: spin_unlock_bh(&hwsim_radio_lock);
6168:
6169: hwsim_mcast_new_radio(idx, info, param);
6170:
6171: return idx;
6172:
6173: failed_final_insert:
6174: debugfs_remove_recursive(data->debugfs);
6175: ieee80211_unregister_hw(data->hw);
6176: failed_hw:
6177: device_release_driver(data->dev);
6178: failed_bind:
6179: device_unregister(data->dev);
6180: failed_drvdata:
6181: ieee80211_free_hw(hw);
6182: failed:
6183: return err;
6184: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 60/2 |
2026/08/09 12:23 |
llm |
expert |
0m
Model:
Tokens:
input: 53489
output: 25
thoughts: 1235
Thoughts: **Deadlock Analysis in Network Device Unregistration**
Okay, so I'm looking at this deadlock and I think I've got a handle on it. Initially, I was confused because I was assuming that `data->dev` and `wiphy.dev` were essentially the same device, but they're not. `data->dev` is created first, and then `wiphy.dev` is a child. Their locks are distinct, which means the initial suspicion of a simple lock order issue between the two devices was wrong.
The stack trace tells the tale β it's a single thread deadlock, which means the thread already has a lock it's trying to re-acquire. `device_lock(&rdev->wiphy.dev)` is the culprit. Now, I ruled out a couple of possibilities like `wiphy_unregister` taking the same lock twice, or `rtnl_lock` being held recursively.
The key insight is that this is not *necessarily* within the same thread. What about other threads that could be holding a lock needed by this thread. So I considered the possibility that the `rtnl_lock` could be held by a different thread, blocking this one from finishing. I immediately started thinking about workqueues.
Bingo! `wiphy_unregister` calls `rtnl_lock()`. Now, is it possible that `rtnl_lock()` is *already* held by a different thread, possibly in a workqueue? That got me thinking about other related locks. Then it hit me: If Thread A holds `rtnl_lock()` and is waiting for `pernet_ops_rwsem`, and Thread B (`cleanup_net`) holds `pernet_ops_rwsem` (read) and is waiting for `rtnl_lock()`, we have a deadlock!
Now, the question is: is there a path that takes `rtnl_lock()` and then `pernet_ops_rwsem`? I checked the `register_pernet_subsys` and `register_netdev` routines. Neither of them directly takes `pernet_ops_rwsem` after acquiring `rtnl_lock()`. I then looked at `cleanup_net` and how it interacts with `net_rwsem`. It holds the write lock, but releases it BEFORE calling `ops_undo_list`, so `net_rwsem` isn't the problem here. It *does* hold `pernet_ops_rwsem` (read). So this looks like a textbook `rtnl_lock()` -> `pernet_ops_rwsem` deadlock. I need to dig deeper into the code to find the exact path that's leading to this lock ordering. Let's start with a search for `pernet_ops_rwsem`.
|
| 61/2 |
2026/08/09 12:24 |
tool |
grepper |
0m
Args: map[Expression:down_write.*pernet_ops_rwsem]
Results: map[Output:net/core/dev.c=1972=int register_netdevice_notifier(struct notifier_block *nb)
--
net/core/dev.c-1977- /* Close race with setup_net() and cleanup_net() */
net/core/dev.c:1978: down_write(&pernet_ops_rwsem);
net/core/dev.c-1979-
--
net/core/dev.c=2027=int unregister_netdevice_notifier(struct notifier_block *nb)
--
net/core/dev.c-2032- /* Close race with setup_net() and cleanup_net() */
net/core/dev.c:2033: down_write(&pernet_ops_rwsem);
net/core/dev.c-2034- rtnl_lock();
--
net/core/net_namespace.c=740=void net_ns_barrier(void)
net/core/net_namespace.c-741-{
net/core/net_namespace.c:742: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-743- up_write(&pernet_ops_rwsem);
--
net/core/net_namespace.c=1263=void __init net_ns_init(void)
--
net/core/net_namespace.c-1294-
net/core/net_namespace.c:1295: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-1296- if (setup_net(&init_net))
--
net/core/net_namespace.c=1436=int register_pernet_subsys(struct pernet_operations *ops)
--
net/core/net_namespace.c-1438- int error;
net/core/net_namespace.c:1439: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-1440- error = register_pernet_operations(first_device, ops);
--
net/core/net_namespace.c=1455=void unregister_pernet_subsys(struct pernet_operations *ops)
net/core/net_namespace.c-1456-{
net/core/net_namespace.c:1457: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-1458- unregister_pernet_operations(ops);
--
net/core/net_namespace.c=1482=int register_pernet_device(struct pernet_operations *ops)
--
net/core/net_namespace.c-1484- int error;
net/core/net_namespace.c:1485: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-1486- error = register_pernet_operations(&pernet_list, ops);
--
net/core/net_namespace.c=1503=void unregister_pernet_device(struct pernet_operations *ops)
net/core/net_namespace.c-1504-{
net/core/net_namespace.c:1505: down_write(&pernet_ops_rwsem);
net/core/net_namespace.c-1506- if (&ops->list == first_device)
--
net/core/rtnetlink.c=701=void rtnl_link_unregister(struct rtnl_link_ops *ops)
--
net/core/rtnetlink.c-713- /* Close the race with setup_net() and cleanup_net() */
net/core/rtnetlink.c:714: down_write(&pernet_ops_rwsem);
net/core/rtnetlink.c-715- rtnl_lock_unregistering_all();
]
|
| 62/2 |
2026/08/09 12:24 |
llm |
expert |
0m
Model:
Tokens:
input: 56334
output: 26
thoughts: 409
Thoughts: **Analyzing Potential Deadlock in Network Device Unregistration**
Okay, so I'm looking at this network device unregistration flow, and something's not sitting quite right. My initial observation was that `unregister_netdevice_notifier` takes `down_write(&pernet_ops_rwsem)` and then `rtnl_lock()`, but let me rephrase that. It takes `pernet_ops_rwsem` first, then `rtnl_lock()`. So, it's holding `pernet_ops_rwsem` in write mode and is waiting on the `rtnl_lock()`.
Now, if I compare that to something like `cleanup_net`, that holds `pernet_ops_rwsem` in read mode and also waits on `rtnl_lock()` through a function call like `wiphy_unregister`. Now, that's where things get interesting. If `cleanup_net` is already holding `pernet_ops_rwsem` in read mode, and then `unregister_netdevice_notifier` tries to grab `pernet_ops_rwsem` in write mode, it *should* block, right?
But *hang on*... `cleanup_net` *already* holds `pernet_ops_rwsem` in read mode, then it calls `wiphy_unregister`, which will then try to take `rtnl_lock()`. If some other thread *holds* `rtnl_lock()` and *then* tries to get `pernet_ops_rwsem` (write), we've got a problem. The issue is that `unregister_netdevice_notifier` takes `pernet_ops_rwsem` first, and *then* tries for `rtnl_lock()`. So, the lock ordering prevents it from holding `rtnl_lock()` while waiting for `pernet_ops_rwsem`! It can't happen!
What about `rtnl_link_unregister`? Looking at the code:
```c
down_write(&pernet_ops_rwsem);
rtnl_lock_unregistering_all();
```
It also grabs `pernet_ops_rwsem` *first*. So, we have the same locking order here. Now my question is, is there *any* code path where `rtnl_lock()` is taken *before* `pernet_ops_rwsem`? That's what I need to investigate. I should search inside `rtnl_lock` itself to see where it might use `pernet_ops_rwsem`.
|
| 63/2 |
2026/08/09 12:24 |
tool |
grepper |
0m
Error:
Args: map[Expression:rtnl_lock.*pernet_ops_rwsem]
Results:
|
| 64/2 |
2026/08/09 12:24 |
llm |
expert |
0m
Model:
Tokens:
input: 57334
output: 25
thoughts: 678
Thoughts: **Analyzing a Potential Deadlock in the Network Device Registration/Unregistration Code**
Okay, let's break this down. My initial thought was to look for instances where `down_read(&pernet_ops_rwsem)` or `down_write(&pernet_ops_rwsem)` were called while `rtnl_lock` was already held, because that screams deadlock potential. I know `cleanup_net` holds `pernet_ops_rwsem` in read mode. If another thread, let's call it Thread B, is holding `rtnl_lock` and tries to take `pernet_ops_rwsem` for writing, it'll block, waiting for `cleanup_net` to release its read lock. That's a classic situation. Then `cleanup_net` tries to take `rtnl_lock` and blocks because Thread B holds it. Deadlock!
The next question: Does Thread B even *exist* in that scenario? My thinking process moves to finding if there are other paths. Clearly, Thread B needs to be holding `rtnl_lock()` and then attempting to write-lock `pernet_ops_rwsem`. However, `unregister_netdevice_notifier` and `rtnl_link_unregister` take `pernet_ops_rwsem` *before* `rtnl_lock()`. Hmm, not there.
Okay, let's consider another option, let's look at `register_netdevice_notifier`. Yep, `register_netdevice_notifier` also grabs `pernet_ops_rwsem` *before* `rtnl_lock()`.
Now, what if Thread B *was* holding `rtnl_lock()` and then tried to take `pernet_ops_rwsem` (read)? In that scenario, it wouldn't block, as `cleanup_net` holds the lock for reading. Then I remember that `rwsem` is fair. If there is a pending writer (e.g. `register_netdevice_notifier`), then new readers will block! So, the real deadlock scenario is something much more complex.
I've got it. It's a three-thread deadlock! Here's how it shakes out:
1. Thread A (presumably `cleanup_net`) takes `pernet_ops_rwsem` (read).
2. Thread B (probably `register_netdevice_notifier`) tries to take `pernet_ops_rwsem` (write). It blocks, waiting for Thread A.
3. Thread C (some random netlink handler, say) takes `rtnl_lock()`.
4. Thread C tries to take `pernet_ops_rwsem` (read). It blocks, waiting for Thread B (because writers have priority).
5. Thread A (`cleanup_net`) tries to take `rtnl_lock()` (in `wiphy_unregister`). It blocks, waiting for Thread C.
Deadlock! Thread A holds `pernet_ops_rwsem` (read), but waits for `rtnl_lock()`. Thread B waits for `pernet_ops_rwsem` (write). Thread C holds `rtnl_lock()`, but waits for `pernet_ops_rwsem` (read). This needs verification that there is a path that takes `rtnl_lock()` then tries to take `pernet_ops_rwsem`. I'll search for `down_read(&pernet_ops_rwsem)`.
|
| 65/2 |
2026/08/09 12:24 |
tool |
grepper |
0m
Args: map[Expression:down_read.*pernet_ops_rwsem]
Results: map[Output:net/core/net_namespace.c=553=struct net *copy_net_ns(u64 flags,
--
net/core/net_namespace.c-578-
net/core/net_namespace.c:579: rv = down_read_killable(&pernet_ops_rwsem);
net/core/net_namespace.c-580- if (rv < 0)
--
net/core/net_namespace.c=666=static void cleanup_net(struct work_struct *work)
--
net/core/net_namespace.c-676-
net/core/net_namespace.c:677: down_read(&pernet_ops_rwsem);
net/core/net_namespace.c-678-
]
|
| 66/2 |
2026/08/09 12:24 |
llm |
expert |
0m
Model:
Tokens:
input: 58991
output: 27
thoughts: 1658
Thoughts: **Deadlock Analysis in a PREEMPT_RT Kernel**
Okay, let's break this down. My initial thought was to examine the locking order with `copy_net_ns` and `cleanup_net`, but that quickly led nowhere because `copy_net_ns` doesn't hold `rtnl_lock()`. I considered the possibility of a deadlock unrelated to `pernet_ops_rwsem`, which turned out to be the right direction. The key clue here is that the bug report specifies a `PREEMPT_RT` kernel. That changes everything. In a `PREEMPT_RT` environment, both `rwsem` and `mutex` are built on top of `rt_mutex`. This means that `rt_mutex` deadlock detection *can* detect cycles involving *both* `rwsem` and `mutex`!
So, the next question is, is there a deadlock? It looks like we have:
1. `cleanup_net` and potentially another thread.
Let's work through this. One thread (`cleanup_net`) holds `pernet_ops_rwsem` (read), potentially `rtnl_lock()` and is waiting for something else, since the warning is a rtmutex deadlock. The other thread would then need to acquire `pernet_ops_rwsem` (write) after holding `rtnl_lock()`, and would be waiting. However, we have already found that `unregister_netdevice_notifier` takes `pernet_ops_rwsem` and then `rtnl_lock()` and if this were the case then the first thread could *not* hold `pernet_ops_rwsem` at the same time.
But, the stack trace for `cleanup_net` shows it's blocked on `device_lock(dev)`. Aha! Now we're getting somewhere. The stack traces reveal that `cleanup_net` is blocked on `device_lock(dev)`. We need to figure out which other thread might be the cause. My understanding of the code here is that `cleanup_net` holds read access on `pernet_ops_rwsem`, holds `rtnl_lock()` and is waiting for `device_lock(dev)`. This strongly suggests a classic deadlock scenario. Let's trace this back. First, re-verifying that `wiphy_unregister` is taking `rtnl_lock()`:
```c
rtnl_lock();
wiphy_lock(&rdev->wiphy);
...
device_del(&rdev->wiphy.dev);
```
Yes, it does. So, `cleanup_net` DOES hold `rtnl_lock()`, and is waiting for `device_lock(dev)`. This seems like a 2-thread deadlock:
* Thread A (`cleanup_net`): Holds `rtnl_lock()` and waits for `device_lock(dev)`.
* Thread B: Holds `device_lock(dev)` and waits for `rtnl_lock()`.
Now, we need to find Thread B. One possibility is `wiphy_suspend`, which takes `rtnl_lock()` while `device_lock(dev)` is held.
Let's check other options like `sysfs` attributes and debugfs, or unbinding drivers. Those seem unlikely to be the cause. Looking again at `device_del`, it only takes `device_lock(dev)`. The critical question now is, what else *can* lock the `wiphy` device (`wiphy.dev`)? My next step would be to carefully examine all the code paths that interact with the wiphy device, especially those that involve `device_lock` and the `rtnl_lock()`. And focus on how the PM core interacts here.
|
| 67/2 |
2026/08/09 12:24 |
tool |
grepper |
0m
Error:
Args: map[Expression:device_lock PathPrefix:net/wireless/]
Results:
|
| 68/2 |
2026/08/09 12:24 |
llm |
expert |
0m
Model:
Tokens:
input: 61498
output: 30
thoughts: 12
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Initial Inquiry: Navigating the Wireless Core**
My mind immediately zeroes in on `net/wireless/core.c`. This isn't just a random file choice; it's practically a reflex. Given the general nature of the prompt, "What about `net/wireless/core.c`?", itβs the place to start. It's the central hub for the kernel's wireless subsystem, the foundation upon which everything wireless-related is built. I'm likely thinking, "is *that* where the problem lies?" "Could that be the key component to understand?" I'm thinking about the low-level functions that establish the structure for all wireless communication at that moment.
|
| 69/2 |
2026/08/09 12:24 |
tool |
grepper |
0m
Error:
Args: map[Expression:device_lock PathPrefix:net/wireless/core.c]
Results:
|
| 70/2 |
2026/08/09 12:24 |
llm |
expert |
0m
Model:
Tokens:
input: 61726
output: 27
thoughts: 646
Thoughts: **Analyzing a Deadlock in the Wireless Subsystem**
Okay, so I'm trying to figure out this deadlock in the wireless subsystem. First, I noticed `device_lock` isn't called directly within the `net/wireless/` code. It's used by the driver core, things like `device_del`, `device_suspend`, and `device_release_driver`. I quickly checked if `uevent` uses it, but no, that's not the culprit.
Then, I thought about `wiphy_resume`. Looking at the code:
```c
static int wiphy_resume(struct device *dev)
{
...
rtnl_lock();
wiphy_lock(&rdev->wiphy);
...
}
```
Aha! `wiphy_resume` takes `rtnl_lock()` *while* the PM core holds `device_lock(dev)`. This seems promising. Could this be triggered by a suspend/resume cycle launched by syzkaller? It's certainly possible, given syzkaller's abilities with things like `/sys/power/state`.
If syzkaller triggers a suspend, the PM core grabs `device_lock(&rdev->wiphy.dev)` and calls `wiphy_suspend`, which in turn waits for `rtnl_lock()`. At the *same* time, `cleanup_net` might be running. It takes `rtnl_lock()` and then calls `device_del(&rdev->wiphy.dev)`, which, critically, waits for `device_lock(&rdev->wiphy.dev)`. Bingo! This perfectly explains the deadlock β two threads waiting for each other's lock.
But wait, can this be triggered by a user? Let's check. Writing to `/sys/power/state` requires root privileges, specifically `CAP_SYS_ADMIN` or similar, and the file permissions are `rw-r--r--` for root. So an unprivileged user cannot trigger suspend/resume. That's a good thing!
Okay, so how *else* could we trigger `device_lock(&rdev->wiphy.dev)`? I considered `device_release_driver(&rdev->wiphy.dev)`. Could a user somehow unbind the wiphy device? But then I remember, the wiphy device *doesn't* have a driver! It's a class device. In `wiphy_register` it clearly shows:
```c
rdev->wiphy.dev.class = &ieee80211_class;
...
err = device_add(&rdev->wiphy.dev);
```
So, unbinding is not an option.
Alright, what about other sysfs operations on `wiphy.dev`? Do reads/writes to attributes require `device_lock`? Typically, no. Sysfs interactions don't use `device_lock` directly. They might use it in more specific operations like `bind`/`unbind`, `uevent`, or `online`/`offline`. Hold on, does `wiphy.dev` even *support* `online`/`offline`? Let's check the `ieee80211_class` structure...
So, I think I'm zeroing in on this suspend/resume cycle as the root cause, and I need to explore the interaction between that and `cleanup_net`.
|
| 71/2 |
2026/08/09 12:25 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ieee80211_class]
Results: map[SourceCode: 170: struct class ieee80211_class = {
171: .name = "ieee80211",
172: .dev_release = wiphy_dev_release,
173: .dev_groups = ieee80211_groups,
174: .pm = WIPHY_PM_OPS,
175: .ns_type = &net_ns_type_operations,
176: .namespace = wiphy_namespace,
177: };
SourceFile:net/wireless/sysfs.c]
|
| 72/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 63319
output: 25
thoughts: 26
Thoughts: Here's a summary of my thought process, as if I were analyzing that code snippet:
**Diving into the Power Management Ops**
Okay, so I see a line that sets `.pm` to `WIPHY_PM_OPS`. My immediate reaction is to dig into what `WIPHY_PM_OPS` *is*. I need to understand the structure being assigned there. It's almost certainly a set of function pointers related to power management operations, given the naming convention. Now, let's go check what `WIPHY_PM_OPS` actually defines; understanding those operations is critical to understanding the power management flow. I need to see if it's got the right suspend/resume functions, PM runtime methods, and so on. That is the next step to figure out if it is the correct assignment for the given device.
|
| 73/2 |
2026/08/09 12:25 |
tool |
codesearch-definition-source |
0m
Error:
Args:
Results: map[SourceCode: SourceFile:]
|
| 74/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 63570
output: 35
thoughts: 25
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating a Wireless Configuration Variable**
Alright, time to dig into this. Based on that identifier, `WIPHY_PM_OPS`, it sounds like we're dealing with something related to power management operations for wireless devices. Since the hint points us toward `net/wireless/sysfs.c`, that's a pretty strong indication that this is exposed, at least partially, through the sysfs interface. This makes sense; sysfs is the go-to place for device drivers to provide control and status information in a standard, user-space accessible way. My immediate guess is that `WIPHY_PM_OPS` is a structure or a set of function pointers used to handle power management-related requests for a Wi-Fi physical device (Wiphy) within the wireless subsystem. I'd expect to find things like suspend/resume handlers, perhaps clock management routines, or maybe even routines that implement runtime power management policies. Let's see if we can find it and unpack the details.
|
| 75/2 |
2026/08/09 12:25 |
tool |
grepper |
0m
Args: map[Expression:WIPHY_PM_OPS PathPrefix:net/wireless/sysfs.c]
Results: map[Output:net/wireless/sysfs.c=157=static SIMPLE_DEV_PM_OPS(wiphy_pm_ops, wiphy_suspend, wiphy_resume);
net/wireless/sysfs.c:158:#define WIPHY_PM_OPS (&wiphy_pm_ops)
net/wireless/sysfs.c-159-#else
net/wireless/sysfs.c:160:#define WIPHY_PM_OPS NULL
net/wireless/sysfs.c-161-#endif
--
net/wireless/sysfs.c=170=struct class ieee80211_class = {
--
net/wireless/sysfs.c-173- .dev_groups = ieee80211_groups,
net/wireless/sysfs.c:174: .pm = WIPHY_PM_OPS,
net/wireless/sysfs.c-175- .ns_type = &net_ns_type_operations,
]
|
| 76/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 64109
output: 27
thoughts: 17
Thoughts: Here's my attempt at summarizing those thoughts, considering I'm an expert:
**Assessment of Limited Feature Set**
Okay, so I'm looking at this and it's clear the design is focusing solely on suspend/resume functionality. That's a very specific, and perhaps limiting, scope. I need to understand if this is intentional, a simplified initial implementation, or a major oversight. I'm wondering what's missing, or what's been purposely excluded.
Specifically, I'm thinking about how this interacts with `dev_groups`. Are there any plans to incorporate that functionality into this implementation? Or is this designed to operate independently from the grouping features that I'm used to? It could impact how I integrate this with existing infrastructure, and also changes my expectations for how it will scale. I need to know where I can expect to see that functionality.
|
| 77/2 |
2026/08/09 12:25 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ieee80211_groups]
Results: map[SourceCode: 76: ATTRIBUTE_GROUPS(ieee80211);
SourceFile:net/wireless/sysfs.c]
|
| 78/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 64386
output: 27
thoughts: 15
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Diving into `ieee80211_attrs`**
Alright, time to dig in. The problem at hand, whatever it may be, feels like itβs probably related to 802.11 attributes. Therefore, first thing's first, I need to check `ieee80211_attrs`. I know this structure intimately; it's the heart of how we configure and interact with the wireless hardware. I'll need to remember the specific fields relevant to this current challenge β whether it's related to security settings, rate selection, power management, or some other aspect of the 802.11 protocol. Hopefully, the issue is exposed there, and I don't need to trace more code to resolve it. Time to get started.
|
| 79/2 |
2026/08/09 12:25 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ieee80211_attrs]
Results: map[SourceCode: 68: static struct attribute *ieee80211_attrs[] = {
69: &dev_attr_index.attr,
70: &dev_attr_macaddress.attr,
71: &dev_attr_address_mask.attr,
72: &dev_attr_addresses.attr,
73: &dev_attr_name.attr,
74: NULL,
75: };
SourceFile:net/wireless/sysfs.c]
|
| 80/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 64769
output: 23
thoughts: 2209
Thoughts: **Deadlock Analysis in Wireless Device Unregistration**
Okay, so I've been digging into this wireless device driver code, and I think I've found a nasty potential deadlock situation. Let's break it down.
First, I noticed that there's no obvious way to trigger any complex operations through the sysfs attributes of `wiphy.dev` because all the attributes are read-only. That's not the problem. The real concern is around device unregistration with `wiphy_unregister`.
The main question is, what other code paths might be contending for the same locks? Specifically, could there be a race between `wiphy_unregister` and something else? My initial thought was concurrent calls to `wiphy_unregister`, but that's ruled out by the `rtnl_lock()`. It is global, so concurrent calls are impossible.
Let's think about `wiphy_register`. No, that also takes `rtnl_lock()`, so no concurrency there either. What about netlink? Nope, netlink doesn't touch the `device_lock`. RFKill? The `wiphy.rfkill` is registered. Checking `rfkill_unregister`, this is called BEFORE the `rtnl_lock()` is taken. And `rfkill` has its own device, not the `wiphy.dev`. So nothing there either.
Now, could the current thread (the one running `cleanup_net`) be holding the lock itself, causing it to block? Tracing the lock acquisition, I can see the thread calls `device_lock(&rdev->wiphy.dev)` *after* a series of other operations. It doesn't seem like the lock would be held by this thread.
Since the current thread doesn't hold the lock, it *must* be a 2-thread deadlock where another thread is holding the `device_lock` and waiting for the `rtnl_lock`. The only path that could do this is suspend/resume cycles, and it takes the `rtnl_lock` and it is called with `device_lock(dev)` held, which is a big red flag. The test systems using syzkaller frequently test suspend/resume, so it is a likely cause.
I started to dig deeper. What if `cfg80211_dev_free` or `wiphy_dev_release` are in play? Nope, they don't take `rtnl_lock()`. What about `cfg80211_process_wiphy_works`? That's called from `wiphy_suspend` and `wiphy_unregister`, but it doesn't take the `device_lock` directly. Or `rdev_suspend`, which calls driver's suspend callback? The driver for `mac80211_hwsim` doesn't have a suspend callback, but the *class* of `wiphy.dev` has `wiphy_suspend`. Okay, so `wiphy_suspend` is the key.
Let's verify that `wiphy_suspend` takes the `rtnl_lock`. It does! And the PM core calls it with the `device_lock` already held! I've confirmed that this is a guaranteed AB-BA deadlock if `wiphy_unregister` runs concurrently with system suspend.
Now, can an attacker trigger this? An unprivileged user can't trigger system suspend via `/sys/power/state`, but they *can* trigger `wiphy_unregister` by creating and destroying a network namespace with a hwsim radio. They can't trigger suspend, they can only wait for the system to suspend and then strike. So it's a Denial of Service. However, if system suspend happens (a laptop going to sleep, server being suspended), and a user triggers unregistration, the system crashes.
Could the user trigger suspend in some other way? No. Is there any other path to `wiphy_suspend` or `wiphy_resume`? What about runtime PM? No, it looks like runtime PM is not enabled for `wiphy.dev` because `WIPHY_PM_OPS` is just setting suspend and resume but not runtime suspend/resume. So it is ONLY called during system-wide suspend/hibernate.
Finally, what about other lock ordering issues in this code? It seems like there isn't any issue with `wiphy_lock` followed by `rtnl_lock` anywhere. However, I need to check if there is an AB-BA deadlock between `wiphy_lock` and `rtnl_lock`. `wiphy_unregister` itself takes `rtnl_lock`, then `wiphy_lock()`, then deletes the device. There isn't an issue with lock ordering.
Therefore, the key is the AB-BA deadlock
|
| 81/2 |
2026/08/09 12:25 |
tool |
grepper |
0m
Error:
Args: map[Expression:wiphy_lock.*rtnl_lock]
Results:
|
| 82/2 |
2026/08/09 12:25 |
llm |
expert |
0m
Model:
Tokens:
input: 68040
output: 22
thoughts: 1093
Thoughts: **Analyzing a Deadlock in the Network Subsystem**
Okay, so I'm looking at this stack trace and immediately, I'm thinking about potential lock contention, particularly around `rtnl_lock` because that is a classic area for trouble. My initial thought was to see if `rtnl_lock` was nested inside something that holds `wiphy_lock`, but I remembered that `wiphy_lock` is a mutex. The stack trace, though, is showing something interesting: it's `device_lock` that is actually the contended lock, not `rtnl_lock` or `wiphy_lock`! That's unexpected.
Now, let's assess the impact. Exploitable? No, thankfully. It's a hang β a deadlock. No chance for memory corruption or information leaks. But Denial of Service? Absolutely, this is serious. The deadlock is within the `cleanup_net` workqueue. This means any attempt to destroy a network namespace will be blocked, and, critically, system suspend will also be blocked. Because `rtnl_lock` is held by `cleanup_net`, any further operation that requires this lock will lock up and the system will hang! The entire network subsystem is effectively locked.
The vulnerability is accessible to unprivileged users, since they can create user and network namespaces and a hwsim radio before exiting and triggering `cleanup_net` and `wiphy_unregister`. It doesn't require any specific setup on VMs, network interfaces or other external triggers, which makes it much simpler to replicate. The exploit only requires `CAP_NET_ADMIN` in the user namespace, which is concerning.
Okay, let's explore if this deadlock can be triggered without triggering system suspend. We want to find alternative paths where `device_lock(&rdev->wiphy.dev)` is acquired and there's a dependency on `rtnl_lock()`. I'm going to look at other possible scenarios to exploit this.
Could this be a driver unbinding issue? If a user unbinds the driver of `wiphy.dev`... wait, `wiphy.dev` doesn't have a driver! What about the parent, `data->dev`? If the user unbinds the driver of `data->dev`, would that trigger a relevant callback? But the `mac80211_hwsim_driver` has no `remove` callback, so that's a dead end.
Maybe `device_del(&rdev->wiphy.dev)` is being called twice? Could `mac80211_hwsim_del_radio` be called twice for the same radio? No, `mac80211_hwsim_del_radio` removes it from the list, so it can't be called again. `hwsim_del_radio_nl` and `hwsim_exit_net` both remove the radio, then call `mac80211_hwsim_del_radio`, so that's also ruled out.
What about `rfkill`? Does `rfkill` ever take `device_lock(&rdev->wiphy.dev)`? No, it operates on `rfkill_dev`.
What about sysfs attributes? I'm going to check if any sysfs attributes take `rtnl_lock()`. We previously checked `ieee80211_attrs` and none have a `store` method. What about `wiphy.dev`'s parent, `data->dev`? Does `data->dev` have any sysfs attributes? It's created with `device_create`, so I'll need to check the `hwsim_class` to confirm.
|
| 83/2 |
2026/08/09 12:26 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 335: static const struct class hwsim_class = {
336: .name = "mac80211_hwsim"
337: };
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 84/2 |
2026/08/09 12:26 |
llm |
expert |
3m
Model:
Tokens:
input: 70033
output: 27
thoughts: 868
Thoughts: **Analyzing a Potential RT Mutex Deadlock**
Okay, so I'm looking at this potential deadlock issue. The core of it seems to be related to resource locking, specifically within the `rtnl_lock()` and the `device_lock()`. My initial thought was, "Well, there aren't any obvious attributes here," but then I recalled the relationship between `netdev` sysfs attributes (like `wlan0`) and the `wiphy.dev`. Accessing a `netdev` attribute *could* trigger an `rtnl_lock()`. However, it should acquire the `device_lock(&netdev->dev)` and not `device_lock(&rdev->wiphy.dev)`, so I discounted that as a direct cause.
The key here might be a single-thread deadlock. Let's revisit `rt_mutex_handle_deadlock`. If it returns `-EDEADLK`, that means the `task_blocks_on_rt_mutex` function also returned `-EDEADLK`. That, in turn, can happen for two reasons: either the `owner` of the mutex is the current `task`, indicating the task is trying to lock something it already holds, or `rt_mutex_adjust_prio_chain` has detected a cycle. My gut says the former is more likely.
So, the question becomes: Could `device_lock(&rdev->wiphy.dev)` *already* be held by the current task? To figure this out, I started retracing the execution of `cleanup_net`, leading into `hwsim_exit_net`. This in turn calls `mac80211_hwsim_del_radio`, which leads to:
1. `ieee80211_unregister_hw` which contains: `wiphy_unregister(hw->wiphy);`
2. `wiphy_unregister` which contains: `rtnl_lock()` then `wiphy_lock(&rdev->wiphy);` then `device_del(&rdev->wiphy.dev);`
My suspicion is that `device_lock(&rdev->wiphy.dev)` is held before reaching the line which contains `device_del(&rdev->wiphy.dev);`, and I must figure out how. Is it possible for `hwsim_mcast_del_radio` to be holding the lock? Let me look at that function now...
|
| 85/2 |
2026/08/09 12:29 |
tool |
codesearch-definition-source |
0m
Args: map[Name:hwsim_mcast_del_radio]
Results: map[SourceCode:6186: static void hwsim_mcast_del_radio(int id, const char *hwname,
6187: struct genl_info *info)
6188: {
6189: struct sk_buff *skb;
6190: void *data;
6191: int ret;
6192:
6193: skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
6194: if (!skb)
6195: return;
6196:
6197: data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
6198: HWSIM_CMD_DEL_RADIO);
6199: if (!data)
6200: goto error;
6201:
6202: ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
6203: if (ret < 0)
6204: goto error;
6205:
6206: ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname),
6207: hwname);
6208: if (ret < 0)
6209: goto error;
6210:
6211: genlmsg_end(skb, data);
6212:
6213: hwsim_mcast_config_msg(skb, info);
6214:
6215: return;
6216:
6217: error:
6218: nlmsg_free(skb);
6219: }
SourceFile:drivers/net/wireless/virtual/mac80211_hwsim_main.c]
|
| 86/2 |
2026/08/09 12:29 |
llm |
expert |
0m
Model:
Tokens:
input: 71966
output: 66
thoughts: 1246
Thoughts: **Deadlock Analysis: A Denial of Service Vulnerability**
Okay, let's break this down. My initial thought was that a netlink message was sent, that's all. Then I started to chase potential points of failure, first ruling out the obvious candidates for releasing the resource. No, `debugfs_remove_recursive`, `wiphy_unregister`, or `cleanup_net` weren't the culprits. This led me to conclude that the `device_lock(&rdev->wiphy.dev)` *definitely* wasn't held by the same task as the potential resource release, meaning a cycle was at play.
It became clear: this has to be a deadlock, and the cycle is centered around `rtnl_lock()`. The critical observation here is that `wiphy_suspend` takes `rtnl_lock()` while `device_lock` is already held, creating the classic AB-BA deadlock scenario. This is a known issue, a classic case of denial-of-service, right?
The next question: is this exploitable? After a previous analysis, a simple denial-of-service makes more sense. My analysis showed that an unprivileged user can trigger a `wiphy_unregister` by simply creating and destroying a network namespace. They *cannot* directly trigger `wiphy_suspend`, however. So, they can only trigger this deadlock if the system is suspending concurrently.
I started digging for any other methods to trigger `wiphy_suspend`, but there aren't any, also ruled out alternatives like `wiphy_resume`, `wiphy_sysfs_init`, and even `unbind`, `uevent`, and `online`/`offline`.
Then, I shifted my focus. What if the deadlock *isn't* with `wiphy_suspend`? Could it be with `netdev` registration? Nope. It grabs `rtnl_lock()` but not `device_lock`. The `cfg80211_netdev_notifier_call` also holds `rtnl_lock()`, but not `device_lock`. I continued examining `mac80211_hwsim`, checking for potential sysfs attributes that could provide an alternative path. There are no other ways.
My analysis kept coming back to `wiphy_suspend` or `wiphy_resume`. Syzkaller specifically tests suspend/resume cycles, so this is highly probable. The conclusion is that this bug is a denial-of-service. It's accessible from unprivileged processes because they can trigger one half of the deadlock. But, importantly, they can't trigger the other half (suspension). However, since they *can* trigger one side, they can intentionally cause a deadlock during system suspension, which hangs the network subsystem. So, denial-of-service.
Now, let's fill in the results.
- Exploitable: No (deadlock).
- Denial of Service: Yes.
- Accessible from Unprivileged Processes: Yes (can trigger `wiphy_unregister`).
- Accessible from User Namespaces: Yes (requires `CAP_NET_ADMIN` in user namespace to create hwsim radio).
- VM Guest Trigger: No.
- VM Host Trigger: No.
- Ethernet Network Trigger: No.
- Other Remote Trigger: No.
- Peripheral Trigger: No.
- Malicious Filesystem Trigger: No.
Wait, is `hwsim_new_radio_nl` accessible from unprivileged processes? Yes. User namespaces give `CAP_NET_ADMIN`. It's restricted to CAP_NET_ADMIN, so an unprivileged user CAN create a hwsim radio in a user namespace. The network namespace destruction leads to `wiphy_unregister`. An unprivileged user CAN trigger `wiphy_unregister`.
Okay, there's another route to trigger `wiphy_unregister` via `HWSIM_CMD_DEL_RADIO` via netlink. `hwsim_del_radio_nl` also needs `CAP_NET_ADMIN`. Meaning an unprivileged user could call `hwsim_del_radio_nl`, which calls `wiphy_unregister`. Wait. Does it hold `rtnl_lock()`? No! That's the key. `hwsim_del_radio_nl` *doesn't* hold `rtnl_lock()`. This means an unprivileged user can call this concurrently with system suspend!
This changes everything. It's a proper denial-of-service from an unprivileged user!
Let's double-check: `hwsim_del_radio_nl` requires `CAP_NET_ADMIN`? Yes.
Call `set-results`.
|
| 87/2 |
2026/08/09 12:29 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 88/2 |
2026/08/09 12:29 |
llm |
expert |
0m
Model:
Tokens:
input: 74347
output: 557
thoughts: 303
Thoughts: **My Analysis Concluded: The Deadlock and its Implications**
Okay, the analysis is done. Time to synthesize my understanding into a concise explanation. Essentially, what we're looking at is a classic AB-BA deadlock scenario. Thread 1, specifically within the `wiphy_unregister` context, grabs the `rtnl_lock`. It then calls `device_del` on the `wiphy` device, and *that* function attempts to acquire the `device_lock` associated with the same device.
Meanwhile, Thread 2 β which is triggered during system suspend or resume operations through the PM core β is holding *this* `device_lock`. The crucial point is that `wiphy_suspend` or `wiphy_resume`, running in Thread 2, *also* attempts to grab the `rtnl_lock`. And there it is, the AB-BA: Thread 1 needs A (rtnl) then B (device), while Thread 2 has B then A. Deadlock.
The interesting part is how this can be triggered. An unprivileged user can manipulate this situation by using user namespaces and leveraging netlink to create and delete a `mac80211_hwsim` radio. They can create a radio, delete it via netlink, or by simply destroying the network namespace. That triggers Thread 1. While the user *can't* directly call system suspend to directly trigger Thread 2, they can cause the deadlock to occur when the system _does_ attempt a suspend or resume. It's not a direct exploit for privilege escalation or memory corruption, but it's a denial-of-service vulnerability, specifically by hanging the network subsystem. This effectively prevents power state transitions, which is a significant problem.
|
| 89/1 |
2026/08/09 12:29 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the provided kernel bug report and source code, here is
the assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock involving `rtnl_lock` and `device_lock`.
1. **Path 1 (`wiphy_unregister`)**: When a `mac80211_hwsim` radio is deleted
(e.g., via netlink or when its network namespace is destroyed),
`wiphy_unregister()` is called. This function first acquires the global
`rtnl_lock()`, and later calls `device_del(&rdev->wiphy.dev)`, which attempts to
acquire `device_lock(&rdev->wiphy.dev)`.
2. **Path 2 (`wiphy_suspend` / `wiphy_resume`)**: During a system-wide suspend
or resume, the Power Management (PM) core iterates over devices and calls their
suspend/resume callbacks. The PM core inherently holds `device_lock(dev)` while
doing this. The suspend callback for the wiphy device (`wiphy_suspend()`) then
attempts to acquire `rtnl_lock()`.
If a radio is being unregistered at the exact same time the system is suspending
or resuming, the two threads will deadlock, each holding one lock and waiting
for the other.
**Security Impact:**
* **Exploitable:** No. This is a pure logic bug (deadlock) that results in a
thread hang. It does not cause memory corruption, out-of-bounds accesses, or
information leaks, so it cannot be exploited for privilege escalation or
arbitrary code execution.
* **Denial of Service (DoS):** Yes. The deadlock will permanently hang the
`rtnl_lock`, which is a critical global lock used by the entire network
subsystem. Any subsequent attempts to modify network configurations
(adding/removing interfaces, changing IP addresses, routing, etc.) will hang
indefinitely. It also prevents the system from completing its suspend/resume
cycle.
* **Accessible from Unprivileged Processes / User Namespaces:** Yes. The
`mac80211_hwsim` netlink commands (`HWSIM_CMD_NEW_RADIO` and
`HWSIM_CMD_DEL_RADIO`) are registered with the `GENL_UNS_ADMIN_PERM` flag. This
means they can be invoked by a user who has `CAP_NET_ADMIN` in their current
user namespace. An unprivileged user can create a new user/network namespace,
acquire the necessary capabilities, and continuously create and delete virtual
radios. If the system attempts to suspend while this is happening, the user will
successfully trigger the deadlock.]
|