| 0/0 |
2026/05/18 13:31 |
flow |
assessment-security |
29m
Results: map[DenialOfService:true Explanation:**Analysis of the Bug**
The bug is a classic Use-After-Free (UAF) vulnerability in the error handling
path of the `hackrf` USB SDR driver (`drivers/media/usb/hackrf/hackrf.c`).
During the device initialization in `hackrf_probe()`, the driver attempts to
register two V4L2 video devices: a receiver (`rx_vdev`) and a transmitter
(`tx_vdev`). The registration is done sequentially:
1. `video_register_device(&dev->rx_vdev, ...)` is called. If successful, the
device node (e.g., `/dev/swradio0`) becomes immediately visible and accessible
to userspace.
2. `video_register_device(&dev->tx_vdev, ...)` is called next.
If the registration of the transmitter (`tx_vdev`) failsβfor example, due to
minor number exhaustion (which an attacker can trigger by plugging in multiple
SDR devices) or memory allocation failuresβthe driver jumps to the error
handling path.
The error path calls `video_unregister_device(&dev->rx_vdev)` and then directly
calls `kfree(dev)` to free the `struct hackrf_dev` object. However, if a
userspace process managed to open the `/dev/swradioX` node in the small race
window between its registration and unregistration, the V4L2 core will hold a
reference to the `video_device` (and transitively the `v4l2_device`).
Because `hackrf_probe()` bypasses the proper refcounting mechanism (it should
have called `v4l2_device_put()` instead of `kfree()`), the `hackrf_dev`
structure is freed prematurely while userspace still holds an open file
descriptor. When the userspace process subsequently closes the file descriptor
(or issues `ioctl`s), the kernel attempts to access the freed `hackrf_dev`
memory, resulting in a Use-After-Free.
**Security Impact**
* **Exploitable:** **Yes.** The freed `struct hackrf_dev` contains embedded
`struct video_device` objects, which in turn contain pointers to operations
structures (`vdev->fops`, `vdev->ioctl_ops`). An attacker can spray the kernel
heap to overwrite the freed object with controlled data. When the attacker
subsequently calls an `ioctl` or `close` on the open file descriptor, the kernel
will dereference the attacker-controlled function pointers, leading to arbitrary
code execution and privilege escalation.
* **Denial Of Service:** **Yes.** If the freed memory is not carefully groomed
by an attacker, the invalid memory accesses will cause a kernel panic, leading
to a denial of service.
* **Accessible From Unprivileged Processes:** **Yes.** By default (and via
standard `udev` rules like systemd's `70-uaccess.rules`), video and SDR device
nodes are accessible to the locally logged-in unprivileged user. The attacker's
unprivileged process can open the device node to trigger the UAF.
* **Peripheral Trigger:** **Yes.** The bug is in a USB device driver's probe
function. An attacker with physical access can trigger the vulnerability by
plugging in a malicious USB device (or multiple devices to exhaust the 64
available SDR minor numbers).
* **User Namespaces / VM / Remote / Filesystem:** **No.** The bug is strictly
tied to the local USB subsystem and character device node access. It cannot be
triggered remotely, via network packets, or by mounting filesystems. User
namespaces do not provide any additional access to physical USB devices. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/18 13:31 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/18 13:31 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/4aa618f477ef968aedd012f20995436dd0e1cd45]
|
| 3/1 |
2026/05/18 13:31 |
action |
kernel-builder |
13m
Results: map[KernelObj:/app/workdir/cache/build/8d1cc357f0745da10571f475a79d583b8d5ed030]
|
| 4/1 |
2026/05/18 13:45 |
action |
codesearch-prepare |
10m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/18 13:56 |
agent |
expert |
5m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:true UserNamespace:false 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 greeping
".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).
Don't make assumptions; verify them with source code access. 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 or elevated privileges.
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 completly 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 tranfers, that's 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 exploitabability depends on how exactly the uninit value
is used in the code, and what it affects.
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 Confidetial 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.
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:
==================================================================
BUG: KASAN: slab-use-after-free in vb2_core_queue_release+0x150/0x190 drivers/media/common/videobuf2/videobuf2-core.c:2679
Read of size 4 at addr ffff88802d000f48 by task v4l_id/21137
CPU: 0 UID: 0 PID: 21137 Comm: v4l_id Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/18/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x156/0x4c9 mm/kasan/report.c:482
kasan_report+0xdf/0x1e0 mm/kasan/report.c:595
vb2_core_queue_release+0x150/0x190 drivers/media/common/videobuf2/videobuf2-core.c:2679
vb2_queue_release drivers/media/common/videobuf2/videobuf2-v4l2.c:956 [inline]
_vb2_fop_release+0xe8/0x280 drivers/media/common/videobuf2/videobuf2-v4l2.c:1159
v4l2_release+0x280/0x390 drivers/media/v4l2-core/v4l2-dev.c:471
__fput+0x3ff/0xb40 fs/file_table.c:469
fput_close_sync+0x118/0x250 fs/file_table.c:574
__do_sys_close fs/open.c:1509 [inline]
__se_sys_close fs/open.c:1494 [inline]
__x64_sys_close+0x8b/0x120 fs/open.c:1494
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1adb8a7407
Code: 48 89 fa 4c 89 df e8 38 aa 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffe883bdfc0 EFLAGS: 00000202 ORIG_RAX: 0000000000000003
RAX: ffffffffffffffda RBX: 00007f1adbff2880 RCX: 00007f1adb8a7407
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00007f1adbff26e8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 00007ffe883be1f0 R14: 00007f1adc159000 R15: 0000562e7d91b4d8
</TASK>
Allocated by task 29:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415
kmalloc_noprof include/linux/slab.h:950 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
hackrf_probe+0xcf/0x5d0 drivers/media/usb/hackrf/hackrf.c:1351
usb_probe_interface+0x303/0x8f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:643 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:721
__driver_probe_device+0x1de/0x400 drivers/base/dd.c:863
driver_probe_device+0x4c/0x1b0 drivers/base/dd.c:893
__device_attach_driver+0x1df/0x340 drivers/base/dd.c:1021
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1093
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1148
bus_probe_device+0x64/0x160 drivers/base/bus.c:613
device_add+0x11d9/0x1950 drivers/base/core.c:3691
usb_set_configuration+0xd97/0x1c60 drivers/usb/core/message.c:2266
usb_generic_driver_probe+0xa1/0xe0 drivers/usb/core/generic.c:250
usb_probe_device+0xef/0x400 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:643 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:721
__driver_probe_device+0x1de/0x400 drivers/base/dd.c:863
driver_probe_device+0x4c/0x1b0 drivers/base/dd.c:893
__device_attach_driver+0x1df/0x340 drivers/base/dd.c:1021
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1093
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1148
bus_probe_device+0x64/0x160 drivers/base/bus.c:613
device_add+0x11d9/0x1950 drivers/base/core.c:3691
usb_new_device.cold+0x685/0x115c drivers/usb/core/hub.c:2695
hub_port_connect drivers/usb/core/hub.c:5567 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x314d/0x4af0 drivers/usb/core/hub.c:5953
process_one_work+0xa23/0x19a0 kernel/workqueue.c:3276
process_scheduled_works kernel/workqueue.c:3359 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3440
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x754/0xd80 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Freed by task 29:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
kasan_save_free_info+0x3b/0x70 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2685 [inline]
slab_free mm/slub.c:6165 [inline]
kfree+0x1f6/0x6b0 mm/slub.c:6483
hackrf_probe.cold+0x40/0x12f9 drivers/media/usb/hackrf/hackrf.c:1523
usb_probe_interface+0x303/0x8f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:643 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:721
__driver_probe_device+0x1de/0x400 drivers/base/dd.c:863
driver_probe_device+0x4c/0x1b0 drivers/base/dd.c:893
__device_attach_driver+0x1df/0x340 drivers/base/dd.c:1021
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1093
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1148
bus_probe_device+0x64/0x160 drivers/base/bus.c:613
device_add+0x11d9/0x1950 drivers/base/core.c:3691
usb_set_configuration+0xd97/0x1c60 drivers/usb/core/message.c:2266
usb_generic_driver_probe+0xa1/0xe0 drivers/usb/core/generic.c:250
usb_probe_device+0xef/0x400 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:643 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:721
__driver_probe_device+0x1de/0x400 drivers/base/dd.c:863
driver_probe_device+0x4c/0x1b0 drivers/base/dd.c:893
__device_attach_driver+0x1df/0x340 drivers/base/dd.c:1021
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1093
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1148
bus_probe_device+0x64/0x160 drivers/base/bus.c:613
device_add+0x11d9/0x1950 drivers/base/core.c:3691
usb_new_device.cold+0x685/0x115c drivers/usb/core/hub.c:2695
hub_port_connect drivers/usb/core/hub.c:5567 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x314d/0x4af0 drivers/usb/core/hub.c:5953
process_one_work+0xa23/0x19a0 kernel/workqueue.c:3276
process_scheduled_works kernel/workqueue.c:3359 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3440
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x754/0xd80 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff88802d000000
which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 3912 bytes inside of
freed 8192-byte region [ffff88802d000000, ffff88802d002000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2d000
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88813fe41280 dead000000000100 dead000000000122
raw: 0000000000000000 0000000800020002 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88813fe41280 dead000000000100 dead000000000122
head: 0000000000000000 0000000800020002 00000000f5000000 0000000000000000
head: 00fff00000000003 ffffea0000b40001 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 11594, tgid 11586 (syz.1.1536), ts 456308172457, free_ts 456186809005
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x153/0x170 mm/page_alloc.c:1889
prep_new_page mm/page_alloc.c:1897 [inline]
get_page_from_freelist+0x111d/0x3140 mm/page_alloc.c:3962
__alloc_frozen_pages_noprof+0x27c/0x2ba0 mm/page_alloc.c:5250
alloc_slab_page mm/slub.c:3292 [inline]
allocate_slab mm/slub.c:3481 [inline]
new_slab+0xa6/0x6b0 mm/slub.c:3539
refill_objects+0x26b/0x400 mm/slub.c:7175
refill_sheaf mm/slub.c:2812 [inline]
__pcs_replace_empty_main+0x1ab/0x660 mm/slub.c:4615
alloc_from_pcs mm/slub.c:4717 [inline]
slab_alloc_node mm/slub.c:4851 [inline]
__do_kmalloc_node mm/slub.c:5259 [inline]
__kmalloc_noprof+0x688/0x850 mm/slub.c:5272
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
tomoyo_init_log+0x1224/0x20c0 security/tomoyo/audit.c:275
tomoyo_supervisor+0x506/0x1340 security/tomoyo/common.c:2232
tomoyo_audit_path_log security/tomoyo/file.c:169 [inline]
tomoyo_path_permission security/tomoyo/file.c:592 [inline]
tomoyo_path_permission+0x270/0x3b0 security/tomoyo/file.c:577
tomoyo_path_perm+0x3d6/0x460 security/tomoyo/file.c:843
tomoyo_path_symlink+0x97/0xe0 security/tomoyo/tomoyo.c:212
security_path_symlink+0x152/0x2d0 security/security.c:1477
filename_symlinkat+0x122/0x560 fs/namei.c:5644
__do_sys_symlink fs/namei.c:5673 [inline]
__se_sys_symlink fs/namei.c:5669 [inline]
__x64_sys_symlink+0x79/0xb0 fs/namei.c:5669
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
page last free pid 5181 tgid 5181 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0x7e1/0x10d0 mm/page_alloc.c:2978
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xe0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:350
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4538 [inline]
slab_alloc_node mm/slub.c:4866 [inline]
__do_kmalloc_node mm/slub.c:5259 [inline]
__kvmalloc_node_noprof+0x316/0xa00 mm/slub.c:6752
seq_buf_alloc fs/seq_file.c:39 [inline]
seq_read_iter+0x819/0x1270 fs/seq_file.c:211
kernfs_fop_read_iter+0x46c/0x610 fs/kernfs/file.c:297
new_sync_read fs/read_write.c:493 [inline]
vfs_read+0x825/0xb30 fs/read_write.c:574
ksys_read+0x12a/0x250 fs/read_write.c:717
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88802d000e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88802d000e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88802d000f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88802d000f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88802d001000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Reply: **Analysis of the Bug**
The bug is a classic Use-After-Free (UAF) vulnerability in the error handling path of the `hackrf` USB SDR driver (`drivers/media/usb/hackrf/hackrf.c`).
During the device initialization in `hackrf_probe()`, the driver attempts to register two V4L2 video devices: a receiver (`rx_vdev`) and a transmitter (`tx_vdev`). The registration is done sequentially:
1. `video_register_device(&dev->rx_vdev, ...)` is called. If successful, the device node (e.g., `/dev/swradio0`) becomes immediately visible and accessible to userspace.
2. `video_register_device(&dev->tx_vdev, ...)` is called next.
If the registration of the transmitter (`tx_vdev`) failsβfor example, due to minor number exhaustion (which an attacker can trigger by plugging in multiple SDR devices) or memory allocation failuresβthe driver jumps to the error handling path.
The error path calls `video_unregister_device(&dev->rx_vdev)` and then directly calls `kfree(dev)` to free the `struct hackrf_dev` object. However, if a userspace process managed to open the `/dev/swradioX` node in the small race window between its registration and unregistration, the V4L2 core will hold a reference to the `video_device` (and transitively the `v4l2_device`).
Because `hackrf_probe()` bypasses the proper refcounting mechanism (it should have called `v4l2_device_put()` instead of `kfree()`), the `hackrf_dev` structure is freed prematurely while userspace still holds an open file descriptor. When the userspace process subsequently closes the file descriptor (or issues `ioctl`s), the kernel attempts to access the freed `hackrf_dev` memory, resulting in a Use-After-Free.
**Security Impact**
* **Exploitable:** **Yes.** The freed `struct hackrf_dev` contains embedded `struct video_device` objects, which in turn contain pointers to operations structures (`vdev->fops`, `vdev->ioctl_ops`). An attacker can spray the kernel heap to overwrite the freed object with controlled data. When the attacker subsequently calls an `ioctl` or `close` on the open file descriptor, the kernel will dereference the attacker-controlled function pointers, leading to arbitrary code execution and privilege escalation.
* **Denial Of Service:** **Yes.** If the freed memory is not carefully groomed by an attacker, the invalid memory accesses will cause a kernel panic, leading to a denial of service.
* **Accessible From Unprivileged Processes:** **Yes.** By default (and via standard `udev` rules like systemd's `70-uaccess.rules`), video and SDR device nodes are accessible to the locally logged-in unprivileged user. The attacker's unprivileged process can open the device node to trigger the UAF.
* **Peripheral Trigger:** **Yes.** The bug is in a USB device driver's probe function. An attacker with physical access can trigger the vulnerability by plugging in a malicious USB device (or multiple devices to exhaust the 64 available SDR minor numbers).
* **User Namespaces / VM / Remote / Filesystem:** **No.** The bug is strictly tied to the local USB subsystem and character device node access. It cannot be triggered remotely, via network packets, or by mounting filesystems. User namespaces do not provide any additional access to physical USB devices.
|
| 6/2 |
2026/05/18 13:56 |
llm |
expert |
0m
Model:
Tokens:
input: 10302
output: 46
thoughts: 505
Thoughts: **KASAN Slab-Use-After-Free Vulnerability Analysis**
Okay, I'm looking at a KASAN slab-use-after-free, a nasty one, right here in `vb2_core_queue_release` in `drivers/media/common/videobuf2/videobuf2-core.c:2679`. A read of size 4 bytes is happening at address `ffff88802d000f48`. From the traces, I see the object was originally allocated by `hackrf_probe` and then, unfortunately, freed by `hackrf_probe.cold`. That suggests some kind of error path or a disconnect scenario is causing the premature free.
Let's break down the traces: The allocation happens in `hackrf_probe+0xcf/0x5d0` within the `hackrf.c` driver, specifically at line 1351. This is triggered through `usb_probe_interface`. Now for the free, that's happening with a `kfree` call within `hackrf_probe.cold`, starting at line 1523. Again, the free occurs through the same `usb_probe_interface` path. That strongly implies a disconnect or error path is calling the free function and causing this issue.
The use trace points directly to our problem: `vb2_core_queue_release`, and it's being called as part of a chain leading up to `__fput` in `fs/file_table.c`. So a file descriptor is being released, and the freed object is being accessed during this process. This means that a `vb2_core_queue_release` function call, which should be operating on a valid, but is not due to a freed object.
Given this, I need to focus on what happens in `hackrf_probe` to identify why the object is being freed. I need to examine the error paths, the disconnect handling, and the resource management within that function more closely. The `hackrf.c` driver is the key here, and specifically the `hackrf_probe` and `hackrf_probe.cold` sections. I will now jump into the code and focus on the `hackrf` driver.
|
| 7/2 |
2026/05/18 13:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/hackrf/hackrf.c IncludeLines:true Name:hackrf_probe]
Results: map[SourceCode:1344: static int hackrf_probe(struct usb_interface *intf,
1345: const struct usb_device_id *id)
1346: {
1347: struct hackrf_dev *dev;
1348: int ret;
1349: u8 u8tmp, buf[BUF_SIZE];
1350:
1351: dev = kzalloc_obj(*dev);
1352: if (!dev) {
1353: ret = -ENOMEM;
1354: goto err;
1355: }
1356:
1357: mutex_init(&dev->v4l2_lock);
1358: mutex_init(&dev->vb_queue_lock);
1359: spin_lock_init(&dev->buffer_list_lock);
1360: INIT_LIST_HEAD(&dev->rx_buffer_list);
1361: INIT_LIST_HEAD(&dev->tx_buffer_list);
1362: dev->intf = intf;
1363: dev->dev = &intf->dev;
1364: dev->udev = interface_to_usbdev(intf);
1365: dev->pixelformat = formats[0].pixelformat;
1366: dev->buffersize = formats[0].buffersize;
1367: dev->f_adc = bands_adc_dac[0].rangelow;
1368: dev->f_dac = bands_adc_dac[0].rangelow;
1369: dev->f_rx = bands_rx_tx[0].rangelow;
1370: dev->f_tx = bands_rx_tx[0].rangelow;
1371: set_bit(RX_ADC_FREQUENCY, &dev->flags);
1372: set_bit(TX_DAC_FREQUENCY, &dev->flags);
1373: set_bit(RX_RF_FREQUENCY, &dev->flags);
1374: set_bit(TX_RF_FREQUENCY, &dev->flags);
1375:
1376: /* Detect device */
1377: ret = hackrf_ctrl_msg(dev, CMD_BOARD_ID_READ, 0, 0, &u8tmp, 1);
1378: if (ret == 0)
1379: ret = hackrf_ctrl_msg(dev, CMD_VERSION_STRING_READ, 0, 0,
1380: buf, BUF_SIZE);
1381: if (ret) {
1382: dev_err(dev->dev, "Could not detect board\n");
1383: goto err_kfree;
1384: }
1385:
1386: buf[BUF_SIZE - 1] = '\0';
1387: dev_info(dev->dev, "Board ID: %02x\n", u8tmp);
1388: dev_info(dev->dev, "Firmware version: %s\n", buf);
1389:
1390: /* Init vb2 queue structure for receiver */
1391: dev->rx_vb2_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
1392: dev->rx_vb2_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF |
1393: VB2_READ;
1394: dev->rx_vb2_queue.ops = &hackrf_vb2_ops;
1395: dev->rx_vb2_queue.mem_ops = &vb2_vmalloc_memops;
1396: dev->rx_vb2_queue.drv_priv = dev;
1397: dev->rx_vb2_queue.buf_struct_size = sizeof(struct hackrf_buffer);
1398: dev->rx_vb2_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1399: dev->rx_vb2_queue.lock = &dev->vb_queue_lock;
1400: ret = vb2_queue_init(&dev->rx_vb2_queue);
1401: if (ret) {
1402: dev_err(dev->dev, "Could not initialize rx vb2 queue\n");
1403: goto err_kfree;
1404: }
1405:
1406: /* Init vb2 queue structure for transmitter */
1407: dev->tx_vb2_queue.type = V4L2_BUF_TYPE_SDR_OUTPUT;
1408: dev->tx_vb2_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF |
1409: VB2_WRITE;
1410: dev->tx_vb2_queue.ops = &hackrf_vb2_ops;
1411: dev->tx_vb2_queue.mem_ops = &vb2_vmalloc_memops;
1412: dev->tx_vb2_queue.drv_priv = dev;
1413: dev->tx_vb2_queue.buf_struct_size = sizeof(struct hackrf_buffer);
1414: dev->tx_vb2_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1415: dev->tx_vb2_queue.lock = &dev->vb_queue_lock;
1416: ret = vb2_queue_init(&dev->tx_vb2_queue);
1417: if (ret) {
1418: dev_err(dev->dev, "Could not initialize tx vb2 queue\n");
1419: goto err_kfree;
1420: }
1421:
1422: /* Register controls for receiver */
1423: v4l2_ctrl_handler_init(&dev->rx_ctrl_handler, 5);
1424: dev->rx_bandwidth_auto = v4l2_ctrl_new_std(&dev->rx_ctrl_handler,
1425: &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
1426: 0, 1, 0, 1);
1427: dev->rx_bandwidth = v4l2_ctrl_new_std(&dev->rx_ctrl_handler,
1428: &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_BANDWIDTH,
1429: 1750000, 28000000, 50000, 1750000);
1430: v4l2_ctrl_auto_cluster(2, &dev->rx_bandwidth_auto, 0, false);
1431: dev->rx_rf_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler,
1432: &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_RF_GAIN, 0, 12, 12, 0);
1433: dev->rx_lna_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler,
1434: &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 40, 8, 0);
1435: dev->rx_if_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler,
1436: &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_IF_GAIN, 0, 62, 2, 0);
1437: if (dev->rx_ctrl_handler.error) {
1438: ret = dev->rx_ctrl_handler.error;
1439: dev_err(dev->dev, "Could not initialize controls\n");
1440: goto err_v4l2_ctrl_handler_free_rx;
1441: }
1442: v4l2_ctrl_grab(dev->rx_rf_gain, !hackrf_enable_rf_gain_ctrl);
1443: v4l2_ctrl_handler_setup(&dev->rx_ctrl_handler);
1444:
1445: /* Register controls for transmitter */
1446: v4l2_ctrl_handler_init(&dev->tx_ctrl_handler, 4);
1447: dev->tx_bandwidth_auto = v4l2_ctrl_new_std(&dev->tx_ctrl_handler,
1448: &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
1449: 0, 1, 0, 1);
1450: dev->tx_bandwidth = v4l2_ctrl_new_std(&dev->tx_ctrl_handler,
1451: &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_BANDWIDTH,
1452: 1750000, 28000000, 50000, 1750000);
1453: v4l2_ctrl_auto_cluster(2, &dev->tx_bandwidth_auto, 0, false);
1454: dev->tx_lna_gain = v4l2_ctrl_new_std(&dev->tx_ctrl_handler,
1455: &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 47, 1, 0);
1456: dev->tx_rf_gain = v4l2_ctrl_new_std(&dev->tx_ctrl_handler,
1457: &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_RF_GAIN, 0, 15, 15, 0);
1458: if (dev->tx_ctrl_handler.error) {
1459: ret = dev->tx_ctrl_handler.error;
1460: dev_err(dev->dev, "Could not initialize controls\n");
1461: goto err_v4l2_ctrl_handler_free_tx;
1462: }
1463: v4l2_ctrl_grab(dev->tx_rf_gain, !hackrf_enable_rf_gain_ctrl);
1464: v4l2_ctrl_handler_setup(&dev->tx_ctrl_handler);
1465:
1466: /* Register the v4l2_device structure */
1467: dev->v4l2_dev.release = hackrf_video_release;
1468: ret = v4l2_device_register(&intf->dev, &dev->v4l2_dev);
1469: if (ret) {
1470: dev_err(dev->dev, "Failed to register v4l2-device (%d)\n", ret);
1471: goto err_v4l2_ctrl_handler_free_tx;
1472: }
1473:
1474: /* Init video_device structure for receiver */
1475: dev->rx_vdev = hackrf_template;
1476: dev->rx_vdev.queue = &dev->rx_vb2_queue;
1477: dev->rx_vdev.v4l2_dev = &dev->v4l2_dev;
1478: dev->rx_vdev.ctrl_handler = &dev->rx_ctrl_handler;
1479: dev->rx_vdev.lock = &dev->v4l2_lock;
1480: dev->rx_vdev.vfl_dir = VFL_DIR_RX;
1481: dev->rx_vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE |
1482: V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER;
1483: video_set_drvdata(&dev->rx_vdev, dev);
1484: ret = video_register_device(&dev->rx_vdev, VFL_TYPE_SDR, -1);
1485: if (ret) {
1486: dev_err(dev->dev,
1487: "Failed to register as video device (%d)\n", ret);
1488: goto err_v4l2_device_unregister;
1489: }
1490: dev_info(dev->dev, "Registered as %s\n",
1491: video_device_node_name(&dev->rx_vdev));
1492:
1493: /* Init video_device structure for transmitter */
1494: dev->tx_vdev = hackrf_template;
1495: dev->tx_vdev.queue = &dev->tx_vb2_queue;
1496: dev->tx_vdev.v4l2_dev = &dev->v4l2_dev;
1497: dev->tx_vdev.ctrl_handler = &dev->tx_ctrl_handler;
1498: dev->tx_vdev.lock = &dev->v4l2_lock;
1499: dev->tx_vdev.vfl_dir = VFL_DIR_TX;
1500: dev->tx_vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE |
1501: V4L2_CAP_SDR_OUTPUT | V4L2_CAP_MODULATOR;
1502: video_set_drvdata(&dev->tx_vdev, dev);
1503: ret = video_register_device(&dev->tx_vdev, VFL_TYPE_SDR, -1);
1504: if (ret) {
1505: dev_err(dev->dev,
1506: "Failed to register as video device (%d)\n", ret);
1507: goto err_video_unregister_device_rx;
1508: }
1509: dev_info(dev->dev, "Registered as %s\n",
1510: video_device_node_name(&dev->tx_vdev));
1511:
1512: dev_notice(dev->dev, "SDR API is still slightly experimental and functionality changes may follow\n");
1513: return 0;
1514: err_video_unregister_device_rx:
1515: video_unregister_device(&dev->rx_vdev);
1516: err_v4l2_device_unregister:
1517: v4l2_device_unregister(&dev->v4l2_dev);
1518: err_v4l2_ctrl_handler_free_tx:
1519: v4l2_ctrl_handler_free(&dev->tx_ctrl_handler);
1520: err_v4l2_ctrl_handler_free_rx:
1521: v4l2_ctrl_handler_free(&dev->rx_ctrl_handler);
1522: err_kfree:
1523: kfree(dev);
1524: err:
1525: dev_dbg(&intf->dev, "failed=%d\n", ret);
1526: return ret;
1527: }
SourceFile:drivers/media/usb/hackrf/hackrf.c]
|
| 8/2 |
2026/05/18 13:56 |
llm |
expert |
0m
Model:
Tokens:
input: 15469
output: 52
thoughts: 137
Thoughts: **Analyzing a Potential Memory Leak in hackrf_probe**
Okay, so I'm digging into this `hackrf_probe` function, and I've hit a potential snag. I'm seeing that on the error path, specifically around line 1523, it just calls `kfree(dev)` to release the `dev` structure. That's a red flag. The thing is, `vb2_queue_init` has been called earlier for both `dev->rx_vb2_queue` and `dev->tx_vb2_queue`. Now I'm wondering, if `vb2_queue_init` actually *did* succeed, what did it do? Could it have allocated some resources internally, or linked the queues somewhere that we haven't accounted for?
Hold on... I'm getting ahead of myself. `vb2_queue_init` doesn't *allocate* the queue itself, right? It just initializes the data structures within the `vb2_queue`. It's just a setup function. But... does it allocate something else? I think maybe it does? Okay, time to go back to the source and double-check exactly what `vb2_queue_init` *does*. I need to understand its behavior completely.
|
| 9/2 |
2026/05/18 13:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/common/videobuf2/videobuf2-core.c IncludeLines:true Name:vb2_queue_init]
Results: map[SourceCode: 948: int vb2_queue_init(struct vb2_queue *q)
949: {
950: return vb2_queue_init_name(q, NULL);
951: }
SourceFile:drivers/media/common/videobuf2/videobuf2-v4l2.c]
|
| 10/2 |
2026/05/18 13:56 |
llm |
expert |
0m
Model:
Tokens:
input: 16032
output: 54
thoughts: 25
Thoughts: Here's a summary of my thought process:
**Diving into the Verbose Buffer Queue Initialization**
Okay, so I'm looking at how this verbose buffer queue is initialized. I need to pinpoint the relevant initialization function. Let's see... the most likely candidates are `vb2_queue_init_name` or, since it's core to the structure, `vb2_core_queue_init`. I'll probably need to understand the differences between the two, which one is responsible for setting up the core elements, versus the named variation. It's time to dive into the code and see which function's functionality aligns with what I expect from an initialization routine. I have a feeling I'll be looking for memory allocation, structure setup, and maybe some initial state configuration.
|
| 11/2 |
2026/05/18 13:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/common/videobuf2/videobuf2-core.c IncludeLines:true Name:vb2_core_queue_init]
Results: map[SourceCode:2590: int vb2_core_queue_init(struct vb2_queue *q)
2591: {
2592: /*
2593: * Sanity check
2594: */
2595: /*
2596: * For drivers who don't support max_num_buffers ensure
2597: * a backward compatibility.
2598: */
2599: if (!q->max_num_buffers)
2600: q->max_num_buffers = VB2_MAX_FRAME;
2601:
2602: /* The maximum is limited by offset cookie encoding pattern */
2603: q->max_num_buffers = min_t(unsigned int, q->max_num_buffers, MAX_BUFFER_INDEX);
2604:
2605: if (WARN_ON(!q) ||
2606: WARN_ON(!q->ops) ||
2607: WARN_ON(!q->mem_ops) ||
2608: WARN_ON(!q->type) ||
2609: WARN_ON(!q->io_modes) ||
2610: WARN_ON(!q->ops->queue_setup) ||
2611: WARN_ON(!q->ops->buf_queue))
2612: return -EINVAL;
2613:
2614: if (WARN_ON(q->max_num_buffers < VB2_MAX_FRAME) ||
2615: WARN_ON(q->min_queued_buffers > q->max_num_buffers))
2616: return -EINVAL;
2617:
2618: if (WARN_ON(q->requires_requests && !q->supports_requests))
2619: return -EINVAL;
2620:
2621: /*
2622: * This combination is not allowed since a non-zero value of
2623: * q->min_queued_buffers can cause vb2_core_qbuf() to fail if
2624: * it has to call start_streaming(), and the Request API expects
2625: * that queueing a request (and thus queueing a buffer contained
2626: * in that request) will always succeed. There is no method of
2627: * propagating an error back to userspace.
2628: */
2629: if (WARN_ON(q->supports_requests && q->min_queued_buffers))
2630: return -EINVAL;
2631:
2632: /*
2633: * If the driver needs 'min_queued_buffers' in the queue before
2634: * calling start_streaming() then the minimum requirement is
2635: * 'min_queued_buffers + 1' to keep at least one buffer available
2636: * for userspace.
2637: */
2638: if (q->min_reqbufs_allocation < q->min_queued_buffers + 1)
2639: q->min_reqbufs_allocation = q->min_queued_buffers + 1;
2640:
2641: if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers))
2642: return -EINVAL;
2643:
2644: /* Warn if q->lock is NULL */
2645: if (WARN_ON(!q->lock))
2646: return -EINVAL;
2647:
2648: INIT_LIST_HEAD(&q->queued_list);
2649: INIT_LIST_HEAD(&q->done_list);
2650: spin_lock_init(&q->done_lock);
2651: mutex_init(&q->mmap_lock);
2652: init_waitqueue_head(&q->done_wq);
2653:
2654: q->memory = VB2_MEMORY_UNKNOWN;
2655:
2656: if (q->buf_struct_size == 0)
2657: q->buf_struct_size = sizeof(struct vb2_buffer);
2658:
2659: if (q->bidirectional)
2660: q->dma_dir = DMA_BIDIRECTIONAL;
2661: else
2662: q->dma_dir = q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
2663:
2664: if (q->name[0] == '\0')
2665: snprintf(q->name, sizeof(q->name), "%s-%p",
2666: q->is_output ? "out" : "cap", q);
2667:
2668: return 0;
2669: }
SourceFile:drivers/media/common/videobuf2/videobuf2-core.c]
|
| 12/2 |
2026/05/18 13:56 |
llm |
expert |
0m
Model:
Tokens:
input: 17612
output: 57
thoughts: 25
Thoughts: Okay, let's see what I can make of this. Here's my take on those thoughts, presented as a first-person summary, and tailored for someone who knows their way around kernel code:
**Diving into `videobuf2-v4l2.c` and a Key Initialization Function**
Alright, my focus is zeroing in on `videobuf2_queue_init_name` function, specifically within the `videobuf2-v4l2.c` source file. It's that critical initialization point for the video buffer queues, the very backbone for transferring image data in V4L2. This is where the magic begins, where the driver sets up the essential structures and parameters for efficient video capture or output. I'm keen to dissect how it handles the naming, which is usually a vital indicator of proper setup and easier debugging. It's the first step to ensure things start correctly, and that the queue can be easily identified later, especially when handling multiple devices or streams. This level of initial setup directly affects the performance and stability of video pipelines.
|
| 13/2 |
2026/05/18 13:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/common/videobuf2/videobuf2-v4l2.c IncludeLines:true Name:vb2_queue_init_name]
Results: map[SourceCode: 904: int vb2_queue_init_name(struct vb2_queue *q, const char *name)
905: {
906: /* vb2_memory should match with v4l2_memory */
907: BUILD_BUG_ON(VB2_MEMORY_MMAP != (int)V4L2_MEMORY_MMAP);
908: BUILD_BUG_ON(VB2_MEMORY_USERPTR != (int)V4L2_MEMORY_USERPTR);
909: BUILD_BUG_ON(VB2_MEMORY_DMABUF != (int)V4L2_MEMORY_DMABUF);
910:
911: /*
912: * Sanity check
913: */
914: if (WARN_ON(!q) ||
915: WARN_ON(q->timestamp_flags &
916: ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
917: V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
918: return -EINVAL;
919:
920: /* Warn that the driver should choose an appropriate timestamp type */
921: WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
922: V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
923:
924: if (q->buf_struct_size == 0)
925: q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
926:
927: q->buf_ops = &v4l2_buf_ops;
928: q->is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
929: q->is_output = V4L2_TYPE_IS_OUTPUT(q->type);
930: q->copy_timestamp = (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK)
931: == V4L2_BUF_FLAG_TIMESTAMP_COPY;
932: /*
933: * For compatibility with vb1: if QBUF hasn't been called yet, then
934: * return EPOLLERR as well. This only affects capture queues, output
935: * queues will always initialize waiting_for_buffers to false.
936: */
937: q->quirk_poll_must_check_waiting_for_buffers = true;
938:
939: if (name)
940: strscpy(q->name, name, sizeof(q->name));
941: else
942: q->name[0] = '\0';
943:
944: return vb2_core_queue_init(q);
945: }
SourceFile:drivers/media/common/videobuf2/videobuf2-v4l2.c]
|
| 14/2 |
2026/05/18 13:56 |
llm |
expert |
0m
Model:
Tokens:
input: 18740
output: 46
thoughts: 1394
Thoughts: **Analyzing a Potential Use-After-Free Vulnerability**
Okay, so I'm looking at this crash in `vb2_core_queue_release`. My initial thought was, "Hey, `vb2_queue_init` doesn't allocate anything, it just initializes the queue structure." But the backtrace from the bug report tells a different story: `v4l2_release` is being called. That means a file descriptor is being closed, implying the device was opened. But the crash occurs after a probe that failed to initialize the device. How can this be? If `hackrf_probe` failed, wouldn't the device be freed?
Let's re-examine `hackrf_probe`. I see it registers two video devices: one for receive (`rx_vdev`) and one for transmit (`tx_vdev`). Importantly, if registering the *transmit* device fails, the code unregisters the *receive* device and proceeds to clean up. The critical point is: `video_register_device` makes the device accessible to userspace. I'm starting to see the issue.
What if userspace opens the device *before* `video_unregister_device` is called? It gets a valid file descriptor. Then, `video_unregister_device` is called, essentially marking the device as unregistered, but the open file descriptor remains. The driver continues to clean up and eventually calls `kfree(dev)`. Then, when userspace closes that file descriptor, it triggers `v4l2_release` -> `_vb2_fop_release` -> `vb2_queue_release` -> `vb2_core_queue_release`, which tries to access `dev->rx_vb2_queue` and other related structures β but `dev` is already freed! That's a classic use-after-free scenario.
The question then becomes: is `video_unregister_device` sufficient to prevent this use-after-free? Generally, `video_device` structures include a `release` callback that should handle deallocation of the embedded `dev` structure. Let's dig into `hackrf_template` to confirm this assumption and to identify the appropriate release callback. I need to make sure the standard mechanism for releasing the device is in place to prevent the underlying `dev` from being freed prematurely.
|
| 15/2 |
2026/05/18 13:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/hackrf/hackrf.c IncludeLines:true Name:hackrf_template]
Results: map[SourceCode:1244: static const struct video_device hackrf_template = {
1245: .name = "HackRF One",
1246: .release = video_device_release_empty,
1247: .fops = &hackrf_fops,
1248: .ioctl_ops = &hackrf_ioctl_ops,
1249: };
SourceFile:drivers/media/usb/hackrf/hackrf.c]
|
| 16/2 |
2026/05/18 13:57 |
llm |
expert |
0m
Model:
Tokens:
input: 20814
output: 48
thoughts: 110
Thoughts: **Analyzing the Video Device Release**
Okay, so `video_device_release_empty`... that tells me the `video_device` struct itself isn't dynamically allocated on its own. At least, it's not responsible for freeing any memory itself. Alright, that's important to understand the memory lifecycle. If this function is being used, then the driver *is* responsible for freeing the `video_device` struct. But I need to be absolutely sure: it can only do that *after* all associated file descriptors have been properly closed. Gotta ensure no dangling pointers here. Now, where is this all happening? Ah, the `v4l2_device_release` callback... that's set to `hackrf_video_release`. Okay, I need to take a look at that callback function, make sure it's doing everything correctly.
|
| 17/2 |
2026/05/18 13:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/hackrf/hackrf.c IncludeLines:true Name:hackrf_video_release]
Results: map[SourceCode:1251: static void hackrf_video_release(struct v4l2_device *v)
1252: {
1253: struct hackrf_dev *dev = container_of(v, struct hackrf_dev, v4l2_dev);
1254:
1255: dev_dbg(dev->dev, "\n");
1256:
1257: v4l2_ctrl_handler_free(&dev->rx_ctrl_handler);
1258: v4l2_ctrl_handler_free(&dev->tx_ctrl_handler);
1259: v4l2_device_unregister(&dev->v4l2_dev);
1260: kfree(dev);
1261: }
SourceFile:drivers/media/usb/hackrf/hackrf.c]
|
| 18/2 |
2026/05/18 13:57 |
llm |
expert |
0m
Model:
Tokens:
input: 21387
output: 46
thoughts: 98
Thoughts: **My Analysis of the HackRF Video Driver Release Sequence**
Okay, so `hackrf_video_release` is the function that actually frees the `dev` structure. That's good; it's the expected clean-up function. The question now is: *when* is this function called? Ah, right. It's the `release` callback registered with the `v4l2_device`. That makes sense. So, `v4l2_device_put` triggers this callback, specifically when the reference count of the `v4l2_device` reaches zero. That's a classic pattern.
But wait a minute... I need to be absolutely certain of the reference counting. Did `video_register_device` increase the refcount of the `v4l2_device`? I know that function, but I need to make sure I am not missing a refcount issue here. I will head over to the `hackrf_disconnect` function and follow the logic from there. It seems to be the logical entry point for the device teardown.
|
| 19/2 |
2026/05/18 13:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/hackrf/hackrf.c IncludeLines:true Name:hackrf_disconnect]
Results: map[SourceCode: 704: /* The user yanked out the cable... */
705: static void hackrf_disconnect(struct usb_interface *intf)
706: {
707: struct v4l2_device *v = usb_get_intfdata(intf);
708: struct hackrf_dev *dev = container_of(v, struct hackrf_dev, v4l2_dev);
709:
710: dev_dbg(dev->dev, "\n");
711:
712: mutex_lock(&dev->vb_queue_lock);
713: mutex_lock(&dev->v4l2_lock);
714: /* No need to keep the urbs around after disconnection */
715: dev->udev = NULL;
716: v4l2_device_disconnect(&dev->v4l2_dev);
717: video_unregister_device(&dev->tx_vdev);
718: video_unregister_device(&dev->rx_vdev);
719: mutex_unlock(&dev->v4l2_lock);
720: mutex_unlock(&dev->vb_queue_lock);
721:
722: v4l2_device_put(&dev->v4l2_dev);
723: }
SourceFile:drivers/media/usb/hackrf/hackrf.c]
|
| 20/2 |
2026/05/18 13:57 |
llm |
expert |
0m
Model:
Tokens:
input: 22150
output: 54
thoughts: 301
Thoughts: **Analyzing the Video4Linux (V4L2) Device Disconnect and Probe Logic**
Okay, so I'm looking at the `hackrf_disconnect` function. It seems straightforward enough: it calls `v4l2_device_put(&dev->v4l2_dev)`. That should decrement the reference count of the V4L2 device. But my concern is the error handling in `hackrf_probe`. I noticed that if the video device registration for transmit (`video_register_device(&dev->tx_vdev)`) fails, there's a specific cleanup sequence: it unregisters the receive video device, unregisters the V4L2 device, frees the control handlers, and then frees the device itself.
Now, my intuition is piqued by the scenario where `video_register_device(&dev->rx_vdev)` *succeeds*. That means a userspace application could potentially open the receive video device. If a userspace application has the device open, wouldn't there be a call to `v4l2_device_get` somewhere? Or does `video_device` handle the reference count independently of `v4l2_device`? I need to clarify how the reference counting is handled across these operations.
To confirm the behavior, I need to understand what happens when a V4L2 device is opened. I'll take a look at the `v4l2_open` function in `drivers/media/v4l2-core/v4l2-dev.c` to see how that interacts with the device reference count. That should give me a better understanding of how the device lifecycle is managed in the presence of userspace access.
|
| 21/2 |
2026/05/18 13:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-dev.c IncludeLines:true Name:v4l2_open]
Results: map[SourceCode: 410: /* Override for the open function */
411: static int v4l2_open(struct inode *inode, struct file *filp)
412: {
413: struct video_device *vdev;
414: int ret;
415:
416: /* Check if the video device is available */
417: mutex_lock(&videodev_lock);
418: vdev = video_devdata(filp);
419: /* return ENODEV if the video device has already been removed. */
420: if (vdev == NULL || !video_is_registered(vdev)) {
421: mutex_unlock(&videodev_lock);
422: return -ENODEV;
423: }
424: /* and increase the device refcount */
425: video_get(vdev);
426: mutex_unlock(&videodev_lock);
427:
428: if (!video_is_registered(vdev)) {
429: ret = -ENODEV;
430: goto done;
431: }
432:
433: ret = vdev->fops->open(filp);
434: if (ret)
435: goto done;
436:
437: /* All drivers must use v4l2_fh. */
438: if (WARN_ON(!test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags))) {
439: vdev->fops->release(filp);
440: ret = -ENODEV;
441: }
442:
443: done:
444: if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
445: dprintk("%s: open (%d)\n",
446: video_device_node_name(vdev), ret);
447:
448: /* decrease the refcount in case of an error */
449: if (ret)
450: video_put(vdev);
451: return ret;
452: }
SourceFile:drivers/media/v4l2-core/v4l2-dev.c]
|
| 22/2 |
2026/05/18 13:57 |
llm |
expert |
0m
Model:
Tokens:
input: 23535
output: 53
thoughts: 865
Thoughts: **Use-After-Free Vulnerability in hackrf Driver: Deep Dive**
Okay, let's break this down. My initial observation is that `v4l2_open` eventually calls `video_get`. So I need to understand what `video_get` does. Ah, it increments the reference count of the embedded `struct device` within the `video_device` structure. And symmetrically, `video_put` decrements this count. Got it. When the count hits zero, the `vdev->release` callback gets invoked.
Now, for the `hackrf` driver, `vdev->release` points to `video_device_release_empty`. But that function *does nothing*! That's a red flag. If it does nothing, how is the memory freed? The answer is `hackrf_video_release`, the v4l2 device's release callback.
But here's where it gets interesting. I see that `hackrf_probe`, on error, directly calls `kfree(dev)`. That bypasses `v4l2_device_put` and `video_put` altogether. That's a classic code smell!
Digging deeper into `hackrf_probe`, I see this sequence:
1. `video_register_device` is called for `dev->tx_vdev`.
2. If this registration *fails*, it jumps to `err_video_unregister_device_rx`.
3. Critically, `rx_vdev` has already been *successfully* registered!
4. Then `video_unregister_device(&dev->rx_vdev)` is called.
5. Following this, `kfree(dev)` is called directly.
Now it's clicking! If the registration of `tx_vdev` fails, and `rx_vdev` was already opened by a user, then `video_get` would have been called. When the file descriptor is closed, `v4l2_release` is called, which accesses the freed `dev->rx_vdev`. Bingo! This looks like a solid use-after-free. Specifically, `v4l2_release` calls `vdev->fops->release(filp)`, which is `_vb2_fop_release`. Then, `_vb2_fop_release` accesses `dev->rx_vb2_queue` (which is within the freed memory).
The crucial question is, how easily can this be exploited?
Okay, let's think like an attacker. Can an unprivileged user trigger this? Potentially, yes! If they can plug in a malicious USB device (or the USB device is faulty in a way that causes the `tx_vdev` registration to fail), they could trigger the error path. Or, if for some reason, the driver fails to register the tx_vdev (e.g., out of memory or a minor number exhaustion), an unprivileged user could trigger the bug.
And finally, can they *open* the device? Yes, usually, devices like `/dev/swradio0` are accessible to users in the `video` group, or via `uaccess` from the console user (via logind/systemd). So it seems very reachable!
Therefore, the exploit requirements are:
* An unprivileged user.
* The ability to open the device node, e.g., `/dev/swradio0`.
* A failure during the registration of `tx_vdev`. This can be triggered by a faulting USB device.
So, this is a legitimate use-after-free, and I can confirm that this vulnerability is reachable by an unprivileged user.
|
| 23/2 |
2026/05/18 13:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-dev.c IncludeLines:true Name:video_register_device]
Results: map[SourceCode: 369: /**
370: * video_register_device - register video4linux devices
371: *
372: * @vdev: struct video_device to register
373: * @type: type of device to register, as defined by &enum vfl_devnode_type
374: * @nr: which device node number is desired:
375: * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)
376: *
377: * Internally, it calls __video_register_device(). Please see its
378: * documentation for more details.
379: *
380: * .. note::
381: * if video_register_device fails, the release() callback of
382: * &struct video_device structure is *not* called, so the caller
383: * is responsible for freeing any data. Usually that means that
384: * you video_device_release() should be called on failure.
385: */
386: static inline int __must_check video_register_device(struct video_device *vdev,
387: enum vfl_devnode_type type,
388: int nr)
389: {
390: return __video_register_device(vdev, type, nr, 1, vdev->fops->owner);
391: }
SourceFile:include/media/v4l2-dev.h]
|
| 24/2 |
2026/05/18 13:58 |
llm |
expert |
0m
Model:
Tokens:
input: 25684
output: 44
thoughts: 1320
Thoughts: **Analyzing a Potential Use-After-Free Vulnerability in the HackRF Driver**
Okay, so I'm digging into this reported issue, and my initial thought is, can a malicious USB device somehow trigger a failure in `__video_register_device`? That seems like a logical starting point. But, `__video_register_device` fails due to limited minor numbers, memory allocation issues, or a device registration failure, so a malicious USB device isn't directly the cause.
I see that `hackrf_probe` registers `rx_vdev` first and then `tx_vdev`, and there's nothing in between that directly interacts with the USB device. The code snippet clearly shows this sequence: `video_register_device(&dev->rx_vdev)`, followed by `video_register_device(&dev->tx_vdev)`. So, if the second registration fails, it's very likely due to minor number exhaustion. If you connect a bunch of devices, you could reach this limit.
The syzbot report is interesting: I see the `usb_new_device` function called, which is relevant to USB device handling. And the free trace comes from `hackrf_probe.cold`, specifically `kfree(dev)`. This indicates a potential failure after device setup. The report suggests `video_register_device(&dev->tx_vdev)` is failing. If `rx_vdev` is already registered, that narrows it down.
Thinking about it, syzbot uses `vhci_hcd` to emulate USB devices, and it's also known to use fault injection. Maybe itβs fault injection.
Is there any other trigger? What if the USB device is disconnected mid-probe? No, `video_register_device` doesn't talk to the USB device. However, if it's disconnected, `hackrf_disconnect` should be called, but that's only called on successful probe, and the USB core locks the device during probe, so a disconnect cannot run concurrently.
Let's re-examine all the error paths, and there's only one relevant to my situation, and that's `video_register_device(&dev->tx_vdev)` failing after `video_register_device(&dev->rx_vdev)` succeeds.
A possible race condition seems plausible now! If registration for `/dev/swradio0` succeeds, userspace might open that device. Then, if `video_register_device(&dev->tx_vdev)` fails, `hackrf_probe` unregisters `rx_vdev`, removing the device node, but the file descriptor is still valid. Then, `kfree(dev)` is called, and the file descriptor becomes a dangling pointer. If userspace closes the fd or calls ioctls, that's a use-after-free!
Is this exploitable?
Absolutely. A classic use-after-free of a large `struct hackrf_dev`. It contains mutexes, spinlocks, and pointers to internal structures. When userspace touches the freed `dev`, those pointers and locks are used. This makes it exploitable! An attacker could spray the heap to overwrite `struct hackrf_dev` with data. The `vdev->fops` pointer is probably const, but it's embedded within the freed `dev`! An attacker can overwrite this with their own structure, and when `v4l2_release` calls `vdev->fops->release`, it will jump to their controlled address. This looks like a really interesting avenue for a local privilege escalation. This is something I definitely need to verify.
|
| 25/2 |
2026/05/18 13:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/media/v4l2-dev.h IncludeLines:true Name:video_device]
Results: map[SourceCode: 264: struct video_device {
265: #if defined(CONFIG_MEDIA_CONTROLLER)
266: struct media_entity entity;
267: struct media_intf_devnode *intf_devnode;
268: struct media_pipeline pipe;
269: #endif
270: const struct v4l2_file_operations *fops;
271:
272: u32 device_caps;
273:
274: /* sysfs */
275: struct device dev;
276: struct cdev *cdev;
277:
278: struct v4l2_device *v4l2_dev;
279: struct device *dev_parent;
280:
281: struct v4l2_ctrl_handler *ctrl_handler;
282:
283: struct vb2_queue *queue;
284:
285: struct v4l2_prio_state *prio;
286:
287: /* device info */
288: char name[64];
289: enum vfl_devnode_type vfl_type;
290: enum vfl_devnode_direction vfl_dir;
291: int minor;
292: u16 num;
293: unsigned long flags;
294: int index;
295:
296: /* V4L2 file handles */
297: spinlock_t fh_lock;
298: struct list_head fh_list;
299:
300: int dev_debug;
301:
302: v4l2_std_id tvnorms;
303:
304: /* callbacks */
305: void (*release)(struct video_device *vdev);
306: const struct v4l2_ioctl_ops *ioctl_ops;
307: DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
308:
309: struct mutex *lock;
310: };
SourceFile:include/media/v4l2-dev.h]
|
| 26/2 |
2026/05/18 13:58 |
llm |
expert |
0m
Model:
Tokens:
input: 28469
output: 54
thoughts: 249
Thoughts: **Exploitation Potential: `struct video_device` Vulnerability**
Okay, so I've zeroed in on something juicy. The `struct video_device` in this context has `fops` and `ioctl_ops` function pointers, and I can see that `struct video_device` is nested within `struct hackrf_dev`. Excellent. If an attacker can control or overwrite the `hackrf_dev` structure after it's been freed, they could control those function pointers within the `video_device` structure. That's practically a guarantee of arbitrary code execution! If I can spray the kernel memory or force a user-controlled fake struct, any subsequent syscall, like `ioctl`, `read`, or `close` on the file descriptor associated with this device will cause the kernel to execute whatever code I point it to. This is a classic privilege escalation scenario and highly exploitable.
The next critical step is figuring out how to trigger this. I need `video_register_device(&dev->tx_vdev)` to fail. The question is, can an unprivileged user cause this? I need to dig into the failure paths. The call chain is `video_register_device` which calls `__video_register_device`. Let's analyze what conditions within `__video_register_device` could be leveraged by an attacker to ensure that it fails so that I can then attempt my exploit.
|
| 27/2 |
2026/05/18 13:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-dev.c IncludeLines:true Name:__video_register_device]
Results: map[SourceCode: 910: int __video_register_device(struct video_device *vdev,
911: enum vfl_devnode_type type,
912: int nr, int warn_if_nr_in_use,
913: struct module *owner)
914: {
915: int i = 0;
916: int ret;
917: int minor_offset = 0;
918: int minor_cnt = VIDEO_NUM_DEVICES;
919: const char *name_base;
920:
921: /* A minor value of -1 marks this video device as never
922: having been registered */
923: vdev->minor = -1;
924:
925: /* the release callback MUST be present */
926: if (WARN_ON(!vdev->release))
927: return -EINVAL;
928: /* the v4l2_dev pointer MUST be present */
929: if (WARN_ON(!vdev->v4l2_dev))
930: return -EINVAL;
931: /* the device_caps field MUST be set for all but subdevs */
932: if (WARN_ON(type != VFL_TYPE_SUBDEV && !vdev->device_caps))
933: return -EINVAL;
934: /* the open and release file operations are mandatory */
935: if (WARN_ON(!vdev->fops || !vdev->fops->open || !vdev->fops->release))
936: return -EINVAL;
937:
938: /* v4l2_fh support */
939: spin_lock_init(&vdev->fh_lock);
940: INIT_LIST_HEAD(&vdev->fh_list);
941:
942: /* Part 1: check device type */
943: switch (type) {
944: case VFL_TYPE_VIDEO:
945: name_base = "video";
946: break;
947: case VFL_TYPE_VBI:
948: name_base = "vbi";
949: break;
950: case VFL_TYPE_RADIO:
951: name_base = "radio";
952: break;
953: case VFL_TYPE_SUBDEV:
954: name_base = "v4l-subdev";
955: break;
956: case VFL_TYPE_SDR:
957: /* Use device name 'swradio' because 'sdr' was already taken. */
958: name_base = "swradio";
959: break;
960: case VFL_TYPE_TOUCH:
961: name_base = "v4l-touch";
962: break;
963: default:
964: pr_err("%s called with unknown type: %d\n",
965: __func__, type);
966: return -EINVAL;
967: }
968:
969: vdev->vfl_type = type;
970: vdev->cdev = NULL;
971: if (vdev->dev_parent == NULL)
972: vdev->dev_parent = vdev->v4l2_dev->dev;
973: if (vdev->ctrl_handler == NULL)
974: vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
975: /* If the prio state pointer is NULL, then use the v4l2_device
976: prio state. */
977: if (vdev->prio == NULL)
978: vdev->prio = &vdev->v4l2_dev->prio;
979:
980: /* Part 2: find a free minor, device node number and device index. */
981: #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
982: /* Keep the ranges for the first four types for historical
983: * reasons.
984: * Newer devices (not yet in place) should use the range
985: * of 128-191 and just pick the first free minor there
986: * (new style). */
987: switch (type) {
988: case VFL_TYPE_VIDEO:
989: minor_offset = 0;
990: minor_cnt = 64;
991: break;
992: case VFL_TYPE_RADIO:
993: minor_offset = 64;
994: minor_cnt = 64;
995: break;
996: case VFL_TYPE_VBI:
997: minor_offset = 224;
998: minor_cnt = 32;
999: break;
1000: default:
1001: minor_offset = 128;
1002: minor_cnt = 64;
1003: break;
1004: }
1005: #endif
1006:
1007: /* Pick a device node number */
1008: mutex_lock(&videodev_lock);
1009: nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
1010: if (nr == minor_cnt)
1011: nr = devnode_find(vdev, 0, minor_cnt);
1012: if (nr == minor_cnt) {
1013: pr_err("could not get a free device node number\n");
1014: mutex_unlock(&videodev_lock);
1015: return -ENFILE;
1016: }
1017: #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
1018: /* 1-on-1 mapping of device node number to minor number */
1019: i = nr;
1020: #else
1021: /* The device node number and minor numbers are independent, so
1022: we just find the first free minor number. */
1023: for (i = 0; i < VIDEO_NUM_DEVICES; i++)
1024: if (video_devices[i] == NULL)
1025: break;
1026: if (i == VIDEO_NUM_DEVICES) {
1027: mutex_unlock(&videodev_lock);
1028: pr_err("could not get a free minor\n");
1029: return -ENFILE;
1030: }
1031: #endif
1032: vdev->minor = i + minor_offset;
1033: vdev->num = nr;
1034:
1035: /* Should not happen since we thought this minor was free */
1036: if (WARN_ON(video_devices[vdev->minor])) {
1037: mutex_unlock(&videodev_lock);
1038: pr_err("video_device not empty!\n");
1039: return -ENFILE;
1040: }
1041: devnode_set(vdev);
1042: vdev->index = get_index(vdev);
1043: video_devices[vdev->minor] = vdev;
1044: mutex_unlock(&videodev_lock);
1045:
1046: if (vdev->ioctl_ops)
1047: determine_valid_ioctls(vdev);
1048:
1049: /* Part 3: Initialize the character device */
1050: vdev->cdev = cdev_alloc();
1051: if (vdev->cdev == NULL) {
1052: ret = -ENOMEM;
1053: goto cleanup;
1054: }
1055: vdev->cdev->ops = &v4l2_fops;
1056: vdev->cdev->owner = owner;
1057: ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
1058: if (ret < 0) {
1059: pr_err("%s: cdev_add failed\n", __func__);
1060: kfree(vdev->cdev);
1061: vdev->cdev = NULL;
1062: goto cleanup;
1063: }
1064:
1065: /* Part 4: register the device with sysfs */
1066: vdev->dev.class = &video_class;
1067: vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
1068: vdev->dev.parent = vdev->dev_parent;
1069: vdev->dev.release = v4l2_device_release;
1070: dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
1071:
1072: /* Increase v4l2_device refcount */
1073: v4l2_device_get(vdev->v4l2_dev);
1074:
1075: mutex_lock(&videodev_lock);
1076: ret = device_register(&vdev->dev);
1077: if (ret < 0) {
1078: mutex_unlock(&videodev_lock);
1079: pr_err("%s: device_register failed\n", __func__);
1080: put_device(&vdev->dev);
1081: return ret;
1082: }
1083:
1084: if (nr != -1 && nr != vdev->num && warn_if_nr_in_use)
1085: pr_warn("%s: requested %s%d, got %s\n", __func__,
1086: name_base, nr, video_device_node_name(vdev));
1087:
1088: /* Part 5: Register the entity. */
1089: ret = video_register_media_controller(vdev);
1090:
1091: /* Part 6: Activate this minor. The char device can now be used. */
1092: set_bit(V4L2_FL_REGISTERED, &vdev->flags);
1093: mutex_unlock(&videodev_lock);
1094:
1095: return 0;
1096:
1097: cleanup:
1098: mutex_lock(&videodev_lock);
1099: if (vdev->cdev)
1100: cdev_del(vdev->cdev);
1101: video_devices[vdev->minor] = NULL;
1102: devnode_clear(vdev);
1103: mutex_unlock(&videodev_lock);
1104: /* Mark this video device as never having been registered. */
1105: vdev->minor = -1;
1106: return ret;
1107: }
SourceFile:drivers/media/v4l2-core/v4l2-dev.c]
|
| 28/2 |
2026/05/18 13:58 |
llm |
expert |
0m
Model:
Tokens:
input: 32234
output: 56
thoughts: 2077
Thoughts: **Vulnerability Analysis: HackRF Device Driver**
Okay, so I've got this race condition in the HackRF driver. It's triggered when registering video devices (`rx_vdev` and `tx_vdev`) associated with a HackRF SDR device, specifically when the system runs out of minor numbers. Here's the deal:
If `__video_register_device` fails, it's bad news. It can fail because `devnode_find` fails, which means no more minor numbers are available. For SDR devices, there's a limit of 64. So, the 65th device registration will always fail. It could also fail due to memory allocation or device registration errors, but the minor number exhaustion is the most likely.
Now, could an unprivileged user actually trigger this? Yep, if they have physical access to a machine. They can plug in USB devices β a hub, maybe, and emulate a bunch of SDR devices. Let's say they plug in 32 HackRFs, each using two minors (rx and tx). The 32nd device will register its `rx_vdev` (taking the 63rd minor) but fail to register the `tx_vdev` because all the minors are used. Then, `hackrf_probe` will fail, unregister the `rx_vdev`, and free the device.
Here's the juicy part: If an attacker has a process constantly trying to open `/dev/swradio63` in a loop, it could open it *right* after `rx_vdev` is registered but *before* `tx_vdev` fails and `rx_vdev` is unregistered. This creates a really reliable race condition!
The attacker plugs in 31 HackRF devices, then the 32nd. The kernel registers `rx_vdev` as `/dev/swradio63`. The attacker's process opens that file. The kernel tries to register `tx_vdev`, fails because no minors are left. The kernel *unregisters* `rx_vdev` and frees `dev`. Boom β the attacker's process *still* has an open file descriptor to the freed device! Now they can spray the heap, overwrite `dev`, and call `ioctl` to get code execution.
This is a textbook privilege escalation vulnerability, either via a physical USB device, or a virtual USB device if the attacker can access `/dev/vhci`, which is a privileged device.
To summarize the key points:
* **Exploitable:** Absolutely, yes.
* **Denial of Service:** Yes, because the attacker can make the system unstable.
* **Accessible from Unprivileged Processes:** Yes, if they can open the device node. Device nodes are often accessible to the console user or the `video` group.
* **Peripheral Trigger:** Yes, requires plugging in a USB device.
Is this pattern in other drivers? It's possible; many media drivers might have similar code. But for now, I'm focusing on this specific bug.
Is there a way to trigger the failure of `video_register_device` other than minor number exhaustion? Memory allocation failure is possible, but minor exhaustion is much more reliable.
Okay, let me double-check about user access. The device node, by default, is created with permissions `0600` root:root. But udev rules often change this. The `uaccess.rules` file means the logged-in user gets an ACL, so they can read/write the device. So, yeah, an unprivileged *local* user can open it.
What about user namespaces? A user namespace won't give you access to physical USB devices unless the host explicitly passes them. You can't mount a USB gadget in a user namespace unless you have access to configfs, which you don't in unprivileged namespaces. The answer here is No.
What about VM Guest Trigger? No, this bug is in the USB driver, running in the guest if the host passes the USB device, so it doesn't trigger a host kernel issue.
Confidential computing? No.
Ethernet/other remote triggers? Nope.
Malicious filesystem? No.
Okay, let's look at that release callback again. The `hackrf_template` uses `video_device_release_empty`. But the `rx_vdev` and `tx_vdev` structs are *dynamically* allocated, *inside* the `hackrf_dev` struct. If they are embedded in a dynamically allocated struct, the release callback should free the struct! But `struct hackrf_dev` contains two `video_device` structs and also a `v4l2_device`. The standard way for V4L2 is to have
|
| 29/2 |
2026/05/18 13:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-dev.c IncludeLines:true Name:v4l2_device_release]
Results: map[SourceCode: 176: /* Called when the last user of the video device exits. */
177: static void v4l2_device_release(struct device *cd)
178: {
179: struct video_device *vdev = to_video_device(cd);
180: struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
181:
182: mutex_lock(&videodev_lock);
183: if (WARN_ON(video_devices[vdev->minor] != vdev)) {
184: /* should not happen */
185: mutex_unlock(&videodev_lock);
186: return;
187: }
188:
189: /* Free up this device for reuse */
190: video_devices[vdev->minor] = NULL;
191:
192: /* Delete the cdev on this minor as well */
193: cdev_del(vdev->cdev);
194: /* Just in case some driver tries to access this from
195: the release() callback. */
196: vdev->cdev = NULL;
197:
198: /* Mark device node number as free */
199: devnode_clear(vdev);
200:
201: mutex_unlock(&videodev_lock);
202:
203: #if defined(CONFIG_MEDIA_CONTROLLER)
204: if (v4l2_dev->mdev && vdev->vfl_dir != VFL_DIR_M2M) {
205: /* Remove interfaces and interface links */
206: media_devnode_remove(vdev->intf_devnode);
207: if (vdev->entity.function != MEDIA_ENT_F_UNKNOWN)
208: media_device_unregister_entity(&vdev->entity);
209: }
210: #endif
211:
212: /* Do not call v4l2_device_put if there is no release callback set.
213: * Drivers that have no v4l2_device release callback might free the
214: * v4l2_dev instance in the video_device release callback below, so we
215: * must perform this check here.
216: *
217: * TODO: In the long run all drivers that use v4l2_device should use the
218: * v4l2_device release callback. This check will then be unnecessary.
219: */
220: if (v4l2_dev->release == NULL)
221: v4l2_dev = NULL;
222:
223: /* Release video_device and perform other
224: cleanups as needed. */
225: vdev->release(vdev);
226:
227: /* Decrease v4l2_device refcount */
228: if (v4l2_dev)
229: v4l2_device_put(v4l2_dev);
230: }
SourceFile:drivers/media/v4l2-core/v4l2-dev.c]
|
| 30/2 |
2026/05/18 13:59 |
llm |
expert |
0m
Model:
Tokens:
input: 36312
output: 53
thoughts: 215
Thoughts: **Memory Management Conundrum**
Okay, so I'm tracing the lifecycle of this video device and the associated memory. It looks like `v4l2_device_release` is the key here. It first calls `vdev->release(vdev)`, but that's just an empty operation, so no worries there. Then, it calls `v4l2_device_put(v4l2_dev)`.
Now, *this* is interesting. When `v4l2_device_put` decrements the reference count of `v4l2_dev` to zero, that triggers a call to `v4l2_dev->release`. And, aha, *that* points to `hackrf_video_release`, which then uses `kfree(dev)`. That means the memory *is* indeed freed when the last reference to the `video_device` is dropped. That's a relief, at least.
But wait a minute, I need to make sure I haven't missed something. If `video_register_device` succeeds, it increments the reference count of `v4l2_dev`, doesn't it? So, that means it's holding a reference to the `v4l2_dev`.
And when `video_unregister_device` is called, it decrements the reference to the `video_device`, which it does by calling `device_unregister(&vdev->dev)`. I need to make absolutely sure of that. Ah, yep, it's calling `video_unregister_device`. I need to double-check that part and make sure it behaves as expected. Let me see what `video_unregister_device` actually does...
|
| 31/2 |
2026/05/18 13:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-dev.c IncludeLines:true Name:video_unregister_device]
Results: map[SourceCode:1110: /**
1111: * video_unregister_device - unregister a video4linux device
1112: * @vdev: the device to unregister
1113: *
1114: * This unregisters the passed device. Future open calls will
1115: * be met with errors.
1116: */
1117: void video_unregister_device(struct video_device *vdev)
1118: {
1119: /* Check if vdev was ever registered at all */
1120: if (!vdev || !video_is_registered(vdev))
1121: return;
1122:
1123: mutex_lock(&videodev_lock);
1124: /* This must be in a critical section to prevent a race with v4l2_open.
1125: * Once this bit has been cleared video_get may never be called again.
1126: */
1127: clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
1128: mutex_unlock(&videodev_lock);
1129: v4l2_event_wake_all(vdev);
1130: device_unregister(&vdev->dev);
1131: }
SourceFile:drivers/media/v4l2-core/v4l2-dev.c]
|
| 32/2 |
2026/05/18 13:59 |
llm |
expert |
0m
Model:
Tokens:
input: 37336
output: 56
thoughts: 1244
Thoughts: **Vulnerability Analysis: HackRF USB Driver Use-After-Free**
Okay, so here's the breakdown of this bug and what's got my attention. It seems the `hackrf` USB driver has a serious use-after-free vulnerability in its error handling within the `hackrf_probe` function. Let me lay this out clearly.
The driver follows a standard V4L2 device lifecycle. When a device is registered and opened, the `video_get()` function is called, incrementing the reference count of the video device (`vdev->dev`). This prevents premature freeing as long as userspace holds a file descriptor. The reference count of `vdev->dev` won't drop to zero until userspace closes the device.
Here's the problem: on the error path in `hackrf_probe`, after a device unregistration, `kfree(dev)` is called *immediately*. It calls `video_unregister_device(&dev->rx_vdev)` and then proceeds to `kfree(dev)` without checking if a userspace process already has the device open. This assumes synchronous freeing. If the unregistration is successful, then the device could be already open.
So, here's what happens: `hackrf_probe` registers the device, the device is accessible. If any subsequent operation fails, and the error path is triggered, `kfree` is called prematurely. The `kfree` call frees the `dev` structure. Crucially, the V4L2 device's reference count might *still* be non-zero because a userspace process has the device open. When userspace then attempts to close the device, the driver tries to access the already freed `dev` structure, causing a use-after-free.
This is ripe for exploitation. An attacker can exploit this in a relatively straightforward manner. The attacker opens the device node, the kernel frees `dev`, the attacker sprays the heap, and then calls `ioctl` or `close` to trigger the use-after-free and gain code execution.
This vulnerability is accessible by unprivileged processes. Any process that can open the `/dev/swradioX` device node is vulnerable. There doesn't appear to be any capability check in `v4l2_open` to prevent this.
The trigger is clearly peripheral. The vulnerability *requires* a USB device with the HackRF USB ID to be plugged in to trigger the error path in `hackrf_probe`. This is not a software-only trigger.
So, in summary: This is a critical vulnerability. It's exploitable, leads to a denial of service, and is accessible to unprivileged processes, and a peripheral device. This needs immediate attention.
|
| 33/2 |
2026/05/18 13:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-fh.c IncludeLines:true Name:v4l2_fh_open]
Results: map[SourceCode: 57: int v4l2_fh_open(struct file *filp)
58: {
59: struct video_device *vdev = video_devdata(filp);
60: struct v4l2_fh *fh = kzalloc_obj(*fh);
61:
62: if (fh == NULL)
63: return -ENOMEM;
64: v4l2_fh_init(fh, vdev);
65: v4l2_fh_add(fh, filp);
66: return 0;
67: }
SourceFile:drivers/media/v4l2-core/v4l2-fh.c]
|
| 34/2 |
2026/05/18 13:59 |
llm |
expert |
0m
Model:
Tokens:
input: 39411
output: 47
thoughts: 25
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Initial Concerns Regarding Driver Implementation**
Right, so I'm looking at this `v4l2_fh_open` function, and it strikes me immediately that there aren't any obvious capability checks implemented there. That's a potential vulnerability, or at the very least, a missed opportunity for robust error handling. I'm wondering if this omission is intentional, part of a trade-off for performance, or simply an oversight. It certainly warrants a deeper dive into the surrounding code.
Then I start thinking about similar drivers, specifically the `hackrf_fops` implementation, and whether that handles capabilities any differently. It's a related class of devices, so comparing its approach would be useful. Maybe they're taking a different tack altogether in how they manage device access and feature configuration. I need to refresh my memory and see how the HackRF driver manages capabilities. I bet if that is different, then the V4L2 implementation may suffer issues.
|
| 35/2 |
2026/05/18 13:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/hackrf/hackrf.c IncludeLines:true Name:hackrf_fops]
Results: map[SourceCode:1233: static const struct v4l2_file_operations hackrf_fops = {
1234: .owner = THIS_MODULE,
1235: .open = v4l2_fh_open,
1236: .release = vb2_fop_release,
1237: .read = vb2_fop_read,
1238: .write = vb2_fop_write,
1239: .poll = vb2_fop_poll,
1240: .mmap = vb2_fop_mmap,
1241: .unlocked_ioctl = video_ioctl2,
1242: };
SourceFile:drivers/media/usb/hackrf/hackrf.c]
|
| 36/2 |
2026/05/18 13:59 |
llm |
expert |
0m
Model:
Tokens:
input: 39928
output: 56
thoughts: 1961
Thoughts: **Analysis of the Video Device Registration Vulnerability**
Okay, so I'm looking at this `video_register_device` function and considering the potential for a vulnerability. The code doesn't seem to have any explicit capability checks, meaning an unprivileged user can trigger this. My immediate thought is about triggering a failure during the registration process.
Specifically, can I force `video_register_device` to fail, other than through minor device exhaustion? The code snippet shows several failure points within `__video_register_device`. `cdev_alloc`, `cdev_add`, and `device_register` could all return errors. The classic vulnerability would be a Use-After-Free (UAF) on one of the error paths.
The key question is how to reliably trigger those failures. Minor device exhaustion seems to be the most dependable method. Let me review the set-results tool's parameters to make sure: Exploitable: True, DenialOfService: True, Unprivileged: True, UserNamespace: False, VMGuestTrigger: False, VMHostTrigger: False, NetworkTrigger: False, RemoteTrigger: False, PeripheralTrigger: True, FilesystemTrigger: False - those seem to fit.
Could there be a way a malicious USB device could cause `video_register_device` to fail? But `video_register_device` doesn't do any USB communication itself, just registers the V4L2 device. The `hackrf_probe` function *does* involve USB interaction with control messages before registering. It reads board ID and version string before calling `video_register_device`. If the device replied incorrectly to those, it could fail. But the interaction is done before the call to `video_register_device` . There is no further USB interaction between the `rx_vdev` and `tx_vdev` registration. So failure of the `tx_vdev` registration must be a host side issue (e.g. minor exhaustion). The syzbot report is using fault injection to fail memory allocations, which would be an effective method to trigger errors in `cdev_alloc` or `device_register`. I'm seeing that the free trace is in `hackrf_probe.cold`, meaning it's an error path. The system can be put into a memory pressure state, and then the usb device can be plugged in. In a real world attack, minor device exhaustion can be achieved by plugging in multiple devices.
Are there other error paths after the second `video_register_device` call, specifically for `tx_vdev`? No, after that, `hackrf_probe` just returns 0. So the error path `err_video_unregister_device_rx` is only reachable if `video_register_device(&dev->tx_vdev)` fails.
What about `v4l2_device_register` failing, does that matter? This happens *before* `rx_vdev` is registered. That would not expose it to user space.
Okay, let's consider the scenario where the user unplugs the device while `hackrf_probe` is running. Would that cause a failure? If unplugged, the `usb_control_msg` call may fail, but that happens *before* `video_register_device`. The registration itself doesn't involve any USB interaction, so an unplug during it won't cause it to fail. So again, minor exhaustion or memory allocation failure are the only options.
Is minor device exhaustion feasible? If a user has physical access, they can use a USB hub with multiple microcontrollers that emulate these devices. This would be a cheap attack. If they have access to `/dev/vhci`, they can do it in software. But `/dev/vhci` requires root. Thus it is a valid peripheral trigger.
Can an unprivileged user trigger memory allocation failure? Yes, by filling up memory with allocations (e.g. with mmap), and then plugging the device. Minor exhaustion seems more reliable though.
Let's double-check the `set-results` tool parameters:
```json
{
"Exploitable": true,
"DenialOfService": true,
"Unprivileged": true,
"UserNamespace": false,
"VMGuestTrigger": false,
"VMHostTrigger": false,
"NetworkTrigger": false,
"RemoteTrigger": false,
"PeripheralTrigger": true,
"FilesystemTrigger": false
}
```
Could `video_register_device` *not* be accessible to unprivileged users? The device node created is `/dev/swradioX` which is initially created with permissions `0600` root:root. But udev rules typically change that. A standard desktop environment will have rules (like `7
|
| 37/2 |
2026/05/18 14:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-device.c IncludeLines:true Name:v4l2_device_unregister]
Results: map[SourceCode: 88: void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
89: {
90: struct v4l2_subdev *sd, *next;
91:
92: /* Just return if v4l2_dev is NULL or if it was already
93: * unregistered before. */
94: if (v4l2_dev == NULL || !v4l2_dev->name[0])
95: return;
96: v4l2_device_disconnect(v4l2_dev);
97:
98: /* Unregister subdevs */
99: list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) {
100: v4l2_device_unregister_subdev(sd);
101: if (sd->flags & V4L2_SUBDEV_FL_IS_I2C)
102: v4l2_i2c_subdev_unregister(sd);
103: else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI)
104: v4l2_spi_subdev_unregister(sd);
105: }
106: /* Mark as unregistered, thus preventing duplicate unregistrations */
107: v4l2_dev->name[0] = '\0';
108: }
SourceFile:drivers/media/v4l2-core/v4l2-device.c]
|
| 38/2 |
2026/05/18 14:00 |
llm |
expert |
0m
Model:
Tokens:
input: 43402
output: 56
thoughts: 67
Thoughts: Okay, let me think this through.
**Unregistering a Subdevice: Implications and Verification**
So, this `v4l2_device_unregister` function is doing something specific: it's unregistering subdevices and marking them as, well, *unregistered*. But hang on a second...it doesn't actually *free* the `v4l2_device` itself or decrement its reference count. That's a key distinction. I need to keep that in mind when considering the overall device lifecycle and memory management.
Wait a minute, I seem to recall that `v4l2_device_register` initializes that refcount to 1. I need to make sure I am thinking about that right, and not making an incorrect assumption.
Just to be absolutely certain of the whole process, I need to go back and verify how `v4l2_device_register` actually works. Better double-check the source code for `v4l2_device_register` to confirm the refcount initialization, and also to see how it interacts with the rest of the registration process. Gotta confirm my understanding.
|
| 39/2 |
2026/05/18 14:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/v4l2-core/v4l2-device.c IncludeLines:true Name:v4l2_device_register]
Results: map[SourceCode: 17: int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
18: {
19: if (v4l2_dev == NULL)
20: return -EINVAL;
21:
22: INIT_LIST_HEAD(&v4l2_dev->subdevs);
23: spin_lock_init(&v4l2_dev->lock);
24: v4l2_prio_init(&v4l2_dev->prio);
25: kref_init(&v4l2_dev->ref);
26: get_device(dev);
27: v4l2_dev->dev = dev;
28: if (dev == NULL) {
29: /* If dev == NULL, then name must be filled in by the caller */
30: if (WARN_ON(!v4l2_dev->name[0]))
31: return -EINVAL;
32: return 0;
33: }
34:
35: /* Set name to driver name + device name if it is empty. */
36: if (!v4l2_dev->name[0])
37: snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
38: dev->driver->name, dev_name(dev));
39: if (!dev_get_drvdata(dev))
40: dev_set_drvdata(dev, v4l2_dev);
41: return 0;
42: }
SourceFile:drivers/media/v4l2-core/v4l2-device.c]
|
| 40/2 |
2026/05/18 14:00 |
llm |
expert |
0m
Model:
Tokens:
input: 44242
output: 66
thoughts: 1122
Thoughts: **Bug Analysis: HackRF USB SDR Driver - Use-After-Free Vulnerability**
Okay, let's break this down. First, the `kref_init(&v4l2_dev->ref)` initializes the reference count to 1, right? Then, `v4l2_device_register` also sets the initial refcount to 1. When we call `video_register_device`, `v4l2_device_get` bumps that refcount to 2. Then, unregistering calls `v4l2_device_put`, decrementing the refcount back to 1. But here's the kicker: In the error path of `hackrf_probe`, if something goes wrong *after* a successful `video_register_device`, the code jumps right to `kfree(dev)`. It doesn't call `v4l2_device_put`!
But wait, if `hackrf_probe` is successful, the refcount remains at 1 (plus 1 for each registered video device). When the device is disconnected, `hackrf_disconnect` is called and *that* calls `v4l2_device_put`. This drops the initial reference taken by `v4l2_device_register`. So, on an error path, the code SHOULD be calling `v4l2_device_put(&dev->v4l2_dev)` before `kfree(dev)`. If it did, the refcount would drop to 0 (if no video device is open), then `hackrf_video_release` would be called, and it would then free the memory. If a video device is open, the refcount would drop to 1, and the memory *wouldn't* be freed until the device is closed.
Therefore, the bug is that `hackrf_probe` directly calls `kfree(dev)` on the error path, instead of `v4l2_device_put(&dev->v4l2_dev)`. This confirms my understanding of this bug and how it's exploited.
So here's the core of the issue for a final reply:
* **Vulnerability:** A Use-After-Free bug in the `hackrf` USB SDR driver.
* **Trigger:** Occurs during device probing (`hackrf_probe`). The driver registers two video devices (`rx_vdev`, `tx_vdev`).
* **Scenario:** If `rx_vdev` registration succeeds, but `tx_vdev` fails (e.g., minor number issues), the error handling unregisters `rx_vdev` and incorrectly frees the `hackrf_dev` structure using `kfree(dev)`.
* **Race Condition:** Between the successful registration of `rx_vdev` and its unregistration, a user can open the device `/dev/swradioX`. This action takes a reference to `video_device` (and the `v4l2_device`).
* **The Problem:** `hackrf_probe` frees the `hackrf_dev` structure *without* properly dropping the reference held by the V4L2 core using `v4l2_device_put()`.
* **Exploitation:** When the user closes the device (or calls certain ioctls), the kernel accesses the freed `hackrf_dev` structure, leading to a Use-After-Free condition.
* **Impact:** The freed structure contains function pointers (`vdev->fops`, `vdev->ioctl_ops`), making this a high-impact vulnerability with potential for local privilege escalation.
* **Accessibility:** An unprivileged user can trigger this by plugging in a crafted USB device (or many devices to induce an allocation issue) and racing to open the device node. This makes it a peripheral-triggered vulnerability, easily accessible to unprivileged users.
|
| 41/2 |
2026/05/18 14:01 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 42/2 |
2026/05/18 14:01 |
llm |
expert |
0m
Model:
Tokens:
input: 46329
output: 768
thoughts: 13
Thoughts: Okay, here's the summary, formatted as requested:
**Finalizing the Output**
Alright, the calculations are complete, the models have run, the data's been analyzed. It's time to put a bow on this. I've reviewed the output, cross-referenced everything, and I'm confident in the findings. No more iterations are needed at this stage. Now, the final response takes shape. I'm ready to present the culmination of this process. Let's make this concise and deliver the essential insights, keeping your expert understanding in mind.
|
| 43/1 |
2026/05/18 14:01 |
action |
format-explanation |
0m
Results: map[Explanation:**Analysis of the Bug**
The bug is a classic Use-After-Free (UAF) vulnerability in the error handling
path of the `hackrf` USB SDR driver (`drivers/media/usb/hackrf/hackrf.c`).
During the device initialization in `hackrf_probe()`, the driver attempts to
register two V4L2 video devices: a receiver (`rx_vdev`) and a transmitter
(`tx_vdev`). The registration is done sequentially:
1. `video_register_device(&dev->rx_vdev, ...)` is called. If successful, the
device node (e.g., `/dev/swradio0`) becomes immediately visible and accessible
to userspace.
2. `video_register_device(&dev->tx_vdev, ...)` is called next.
If the registration of the transmitter (`tx_vdev`) failsβfor example, due to
minor number exhaustion (which an attacker can trigger by plugging in multiple
SDR devices) or memory allocation failuresβthe driver jumps to the error
handling path.
The error path calls `video_unregister_device(&dev->rx_vdev)` and then directly
calls `kfree(dev)` to free the `struct hackrf_dev` object. However, if a
userspace process managed to open the `/dev/swradioX` node in the small race
window between its registration and unregistration, the V4L2 core will hold a
reference to the `video_device` (and transitively the `v4l2_device`).
Because `hackrf_probe()` bypasses the proper refcounting mechanism (it should
have called `v4l2_device_put()` instead of `kfree()`), the `hackrf_dev`
structure is freed prematurely while userspace still holds an open file
descriptor. When the userspace process subsequently closes the file descriptor
(or issues `ioctl`s), the kernel attempts to access the freed `hackrf_dev`
memory, resulting in a Use-After-Free.
**Security Impact**
* **Exploitable:** **Yes.** The freed `struct hackrf_dev` contains embedded
`struct video_device` objects, which in turn contain pointers to operations
structures (`vdev->fops`, `vdev->ioctl_ops`). An attacker can spray the kernel
heap to overwrite the freed object with controlled data. When the attacker
subsequently calls an `ioctl` or `close` on the open file descriptor, the kernel
will dereference the attacker-controlled function pointers, leading to arbitrary
code execution and privilege escalation.
* **Denial Of Service:** **Yes.** If the freed memory is not carefully groomed
by an attacker, the invalid memory accesses will cause a kernel panic, leading
to a denial of service.
* **Accessible From Unprivileged Processes:** **Yes.** By default (and via
standard `udev` rules like systemd's `70-uaccess.rules`), video and SDR device
nodes are accessible to the locally logged-in unprivileged user. The attacker's
unprivileged process can open the device node to trigger the UAF.
* **Peripheral Trigger:** **Yes.** The bug is in a USB device driver's probe
function. An attacker with physical access can trigger the vulnerability by
plugging in a malicious USB device (or multiple devices to exhaust the 64
available SDR minor numbers).
* **User Namespaces / VM / Remote / Filesystem:** **No.** The bug is strictly
tied to the local USB subsystem and character device node access. It cannot be
triggered remotely, via network packets, or by mounting filesystems. User
namespaces do not provide any additional access to physical USB devices.]
|