| 0/0 |
2026/10/04 00:00 |
flow |
moderation |
1h04m
Results: map[Actionable:true Explanation:The bug report is **actionable** and **self-consistent**.
### Analysis:
1. **Stack traces and object identification:**
- **All 3 required stack traces are present**: the invalid access stack, the
allocation stack, and the free stack.
- **Target object**: All 3 traces operate on the same object, `struct
rdma_id_private` (in the `kmalloc-2k` slab cache), located in the RDMA
subsystem (`drivers/infiniband/core/`).
- **Allocation**: The object was allocated in `__rdma_create_id()`
(`drivers/infiniband/core/cma.c:1016`) via `ucma_create_id()`.
- **Free**: The object was freed in `_destroy_id()` via `rdma_destroy_id()`
called from `ucma_close_id()` (`drivers/infiniband/core/ucma.c:188`).
- **Invalid access**: The use-after-free read occurred in
`debug_mutex_unlock()` (`kernel/locking/mutex-debug.c:74`), invoked by
`mutex_unlock(&id_priv->handler_mutex)` in `addr_handler()`
(`drivers/infiniband/core/cma.c:3555`), which was running as a work item in
`process_one_req()` (`drivers/infiniband/core/addr.c:624`).
2. **Offset and field matching:**
- The reported read is 8 bytes at offset 1048 (0x418) inside the freed
2048-byte region.
- In `struct rdma_id_private`, the `handler_mutex` field starts at offset 960
(0x3c0) bytes.
- In `struct mutex` (with `CONFIG_DEBUG_MUTEXES`), `lock->magic` is located
at offset 88 (0x58) bytes.
- `960 + 88 = 1048` bytes, which matches the exact byte offset accessed by
`DEBUG_LOCKS_WARN_ON(lock->magic != lock);` in `debug_mutex_unlock()`.
3. **Root cause and race condition:**
- An address resolution callback `addr_handler` was executing on a worker
thread. In `addr_handler()`, the state is transitioned from
`RDMA_CM_ADDR_QUERY` to `RDMA_CM_ADDR_RESOLVED` while holding
`id_priv->handler_mutex`.
- When `addr_handler()` unlocks `id_priv->handler_mutex`,
`__mutex_unlock_slowpath()` clears `lock->owner` via
`atomic_long_try_cmpxchg_release()`.
- Another thread in `ucma_close` / `rdma_destroy_id` was waiting on
`id_priv->handler_mutex`. As soon as ownership was cleared, it acquired the
mutex, set `id_priv->state = RDMA_CM_DESTROYING`, unlocked `handler_mutex`,
and proceeded to `_destroy_id()`.
- Because the state was already past `RDMA_CM_ADDR_QUERY`,
`cma_cancel_operation()` did not invoke `rdma_addr_cancel()` to synchronously
wait for the work item. Consequently, `_destroy_id()` finished and freed
`id_priv` with `kfree(id_priv)`.
- The unlocking worker thread in `addr_handler()` was still executing
`__mutex_unlock_slowpath()` and subsequently accessed `lock->magic` in
`debug_mutex_unlock()` on the already-freed `id_priv->handler_mutex`.]
|
| 1/1 |
2026/10/04 00:00 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/c3dc258e3b1e4a896822926edc54bc1638b0168c]
|
| 2/1 |
2026/10/04 00:01 |
action |
kernel-builder |
30m
Results: map[KernelObj:/app/workdir/cache/build/3d8998ac6f3e5f6a3661bbb8083562e9d3a8dc51]
|
| 3/1 |
2026/10/04 00:31 |
action |
codesearch-prepare |
21m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/10/04 00:53 |
agent |
expert |
12m
Model:
Results:
Instruction: You are an experienced Linux kernel developer tasked with determining if the given kernel bug
report is actionable or not. Actionable means that it contains enough info to root cause
the underlying bug, and that the report is self-consistent and makes sense, rather than
e.g. a one-off nonsensical crash induced by a previous memory corruption.
The bug report is about a use-after-free bug generated by KASAN tool.
It should contain 3 stack traces: the bad memory access stack, the heap block allocation stack,
and the heap block free stack. If the report does not contain 3 stacks, it's not actionable.
All 3 stack traces should be related to the same object type,
and usually be in the same kernel subsystem (at least leaf stack frames).
An example of an actionable and consistent report would be: first access stack relates
to an access to a field of struct Foo, allocation/free stacks relate to allocation/free
of the struct Foo.
In inconsistent/nonsensical reports an access may be to a struct Foo, but allocation
stack allocates a different structure in a different subsystem.
Look for other suspicious signals/inconsistencies that can make this report hard to
debug/understand.
In the final reply explain why you think the report is self-consistent and actionable,
or why it's inconsistent and/or not actionable.
Use the provided tools to confirm any assumptions, variables/fields being accessed, etc.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The bug report is:
==================================================================
BUG: KASAN: slab-use-after-free in debug_mutex_unlock+0x124/0x140 kernel/locking/mutex-debug.c:74
Read of size 8 at addr ffff888024e65418 by task kworker/u33:9/1164
CPU: 1 UID: 0 PID: 1164 Comm: kworker/u33:9 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: ib_addr process_one_req
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+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
debug_mutex_unlock+0x124/0x140 kernel/locking/mutex-debug.c:74
__mutex_unlock_slowpath+0x195/0x930 kernel/locking/mutex.c:1031
addr_handler+0x12d/0x4d0 drivers/infiniband/core/cma.c:3555
process_one_req+0x127/0x680 drivers/infiniband/core/addr.c:624
process_one_work+0xa23/0x1940 kernel/workqueue.c:3322
process_scheduled_works kernel/workqueue.c:3405 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3486
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Allocated by task 9271:
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
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2e5/0x6c0 mm/slub.c:5515
_kmalloc_noprof include/linux/slab.h:969 [inline]
_kzalloc_noprof include/linux/slab.h:1290 [inline]
__rdma_create_id+0x5b/0x8f0 drivers/infiniband/core/cma.c:1016
rdma_create_user_id+0x7d/0xe0 drivers/infiniband/core/cma.c:1074
ucma_create_id+0x189/0x380 drivers/infiniband/core/ucma.c:470
ucma_write+0x1fb/0x330 drivers/infiniband/core/ucma.c:1856
vfs_write+0x2aa/0x1050 fs/read_write.c:685
ksys_write+0x1f8/0x250 fs/read_write.c:739
do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
__do_fast_syscall_32+0xe7/0x970 arch/x86/entry/syscall_32.c:307
do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:332
entry_SYSENTER_compat_after_hwframe+0x84/0x8e
Freed by task 9270:
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:2705 [inline]
slab_free mm/slub.c:6405 [inline]
kfree+0x22b/0x6c0 mm/slub.c:6720
ucma_close_id drivers/infiniband/core/ucma.c:188 [inline]
ucma_destroy_private_ctx+0xb30/0xe90 drivers/infiniband/core/ucma.c:585
ucma_close+0x1aa/0x240 drivers/infiniband/core/ucma.c:1921
__fput+0x3ff/0xb50 fs/file_table.c:512
task_work_run+0x150/0x240 kernel/task_work.c:233
resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
__exit_to_user_mode_loop kernel/entry/common.c:70 [inline]
exit_to_user_mode_loop+0x1d8/0x6f0 kernel/entry/common.c:101
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline]
__do_fast_syscall_32+0x701/0x970 arch/x86/entry/syscall_32.c:310
do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:332
entry_SYSENTER_compat_after_hwframe+0x84/0x8e
The buggy address belongs to the object at ffff888024e65000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1048 bytes inside of
freed 2048-byte region [ffff888024e65000, ffff888024e65800)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x24e60
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 ffff88801bc42f00 dead000000000100 dead000000000122
raw: 0000000000000000 0000000800080008 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801bc42f00 dead000000000100 dead000000000122
head: 0000000000000000 0000000800080008 00000000f5000000 0000000000000000
head: 00fff00000000003 fffffffffffffe01 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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5143, tgid 5143 (klogd), ts 50831000983, free_ts 47183968045
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1859
prep_new_page mm/page_alloc.c:1867 [inline]
get_page_from_freelist+0xf48/0x3530 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x299/0x2dc0 mm/page_alloc.c:5304
alloc_slab_page mm/slub.c:3294 [inline]
allocate_slab mm/slub.c:3408 [inline]
new_slab+0xa2/0x650 mm/slub.c:3454
refill_objects+0xe3/0x410 mm/slub.c:7338
refill_sheaf mm/slub.c:2832 [inline]
__pcs_replace_empty_main+0x376/0x680 mm/slub.c:4703
alloc_from_pcs mm/slub.c:4801 [inline]
slab_alloc_node mm/slub.c:4933 [inline]
__kmalloc_cache_noprof+0x479/0x6c0 mm/slub.c:5511
_kmalloc_noprof include/linux/slab.h:969 [inline]
syslog_print+0xf8/0x620 kernel/printk/printk.c:1585
do_syslog+0x5bd/0x6d0 kernel/printk/printk.c:1763
__do_sys_syslog kernel/printk/printk.c:1855 [inline]
__se_sys_syslog kernel/printk/printk.c:1853 [inline]
__x64_sys_syslog+0x74/0xb0 kernel/printk/printk.c:1853
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x840 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 5656 tgid 5656 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1406 [inline]
__free_frozen_pages+0x79f/0x1090 mm/page_alloc.c:2950
__folio_put+0x3b4/0x5f0 mm/swap.c:112
folio_put include/linux/mm.h:2124 [inline]
put_page include/linux/mm.h:2193 [inline]
put_netmem include/net/netmem.h:394 [inline]
skb_page_unref include/linux/skbuff_ref.h:43 [inline]
__skb_frag_unref include/linux/skbuff_ref.h:56 [inline]
skb_release_data+0x649/0x8e0 net/core/skbuff.c:1110
skb_release_all net/core/skbuff.c:1191 [inline]
__napi_kfree_skb net/core/skbuff.c:1485 [inline]
kfree_skb_napi_cache net/core/skbuff.c:7286 [inline]
skb_attempt_defer_free+0x2ed/0x830 net/core/skbuff.c:7319
tcp_eat_recv_skb net/ipv4/tcp.c:1621 [inline]
tcp_recvmsg_locked+0x11ed/0x2a30 net/ipv4/tcp.c:2899
tcp_recvmsg+0x141/0x630 net/ipv4/tcp.c:2944
inet_recvmsg+0xd5/0x4c0 net/ipv4/af_inet.c:894
sock_recvmsg_nosec net/socket.c:1126 [inline]
sock_recvmsg+0x1b8/0x220 net/socket.c:1148
sock_read_iter+0x2b0/0x3a0 net/socket.c:1217
new_sync_read fs/read_write.c:493 [inline]
vfs_read+0x960/0xb40 fs/read_write.c:574
ksys_read+0x1f8/0x250 fs/read_write.c:716
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x840 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888024e65300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888024e65380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888024e65400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888024e65480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888024e65500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Reply: The bug report is **actionable** and **self-consistent**.
### Analysis:
1. **Stack traces and object identification:**
- **All 3 required stack traces are present**: the invalid access stack, the allocation stack, and the free stack.
- **Target object**: All 3 traces operate on the same object, `struct rdma_id_private` (in the `kmalloc-2k` slab cache), located in the RDMA subsystem (`drivers/infiniband/core/`).
- **Allocation**: The object was allocated in `__rdma_create_id()` (`drivers/infiniband/core/cma.c:1016`) via `ucma_create_id()`.
- **Free**: The object was freed in `_destroy_id()` via `rdma_destroy_id()` called from `ucma_close_id()` (`drivers/infiniband/core/ucma.c:188`).
- **Invalid access**: The use-after-free read occurred in `debug_mutex_unlock()` (`kernel/locking/mutex-debug.c:74`), invoked by `mutex_unlock(&id_priv->handler_mutex)` in `addr_handler()` (`drivers/infiniband/core/cma.c:3555`), which was running as a work item in `process_one_req()` (`drivers/infiniband/core/addr.c:624`).
2. **Offset and field matching:**
- The reported read is 8 bytes at offset 1048 (0x418) inside the freed 2048-byte region.
- In `struct rdma_id_private`, the `handler_mutex` field starts at offset 960 (0x3c0) bytes.
- In `struct mutex` (with `CONFIG_DEBUG_MUTEXES`), `lock->magic` is located at offset 88 (0x58) bytes.
- `960 + 88 = 1048` bytes, which matches the exact byte offset accessed by `DEBUG_LOCKS_WARN_ON(lock->magic != lock);` in `debug_mutex_unlock()`.
3. **Root cause and race condition:**
- An address resolution callback `addr_handler` was executing on a worker thread. In `addr_handler()`, the state is transitioned from `RDMA_CM_ADDR_QUERY` to `RDMA_CM_ADDR_RESOLVED` while holding `id_priv->handler_mutex`.
- When `addr_handler()` unlocks `id_priv->handler_mutex`, `__mutex_unlock_slowpath()` clears `lock->owner` via `atomic_long_try_cmpxchg_release()`.
- Another thread in `ucma_close` / `rdma_destroy_id` was waiting on `id_priv->handler_mutex`. As soon as ownership was cleared, it acquired the mutex, set `id_priv->state = RDMA_CM_DESTROYING`, unlocked `handler_mutex`, and proceeded to `_destroy_id()`.
- Because the state was already past `RDMA_CM_ADDR_QUERY`, `cma_cancel_operation()` did not invoke `rdma_addr_cancel()` to synchronously wait for the work item. Consequently, `_destroy_id()` finished and freed `id_priv` with `kfree(id_priv)`.
- The unlocking worker thread in `addr_handler()` was still executing `__mutex_unlock_slowpath()` and subsequently accessed `lock->magic` in `debug_mutex_unlock()` on the already-freed `id_priv->handler_mutex`.
|
| 5/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 8475
output: 166
thoughts: 1190
Thoughts: **Analyzing the Kernel Bug Report**
Alright, let's break this down. The task is to determine if this kernel bug report is actionable, meaning it provides enough information to pinpoint the root cause of the bug and, critically, makes sense. We're looking at a KASAN-detected use-after-free issue. To be considered actionable, it needs three specific stack traces: the bad memory access stack, the allocation stack, and the free stack. And, those stacks need to be consistent - they should all point to the same object type and, ideally, the same subsystem. The goal is to avoid getting lost in a mess of unrelated code paths.
Looking at the report, I see the three required stack traces, which is a good start.
The *access stack* shows a read of size 8 at address `ffff888024e65418`. This address falls within a `kmalloc-2k` cache object at `ffff888024e65000` of size 2048, and it's 1048 bytes inside a freed region. The access is happening in `debug_mutex_unlock` which is then calling `addr_handler`. That handler comes from `drivers/infiniband/core/cma.c`. A check for consistency needs to happen later.
The *allocation stack* indicates that the memory was allocated by task 9271, and that the allocation happens via `__rdma_create_id`, `rdma_create_user_id`, `ucma_create_id`, and finally `ucma_write` which also seems to be in `drivers/infiniband/core/`.
The *free stack* tells us that task 9270 freed the memory using `kfree`, with a call path that looks like: `ucma_close_id`, `ucma_destroy_private_ctx`, and `ucma_close`. Again, all in `drivers/infiniband/core/`.
So, the critical initial assessment here is that all three stacks *are* related to the `drivers/infiniband/core/` subsystem, which is a very strong positive signal. I need to make sure the object type is consistent, that the access relates to the allocation/free calls. This looks promising. The use of debug mutex and calls to the `addr_handler` implies this is some kind of locking bug. I'll need to dig into the source code to confirm the connection between `ucma`, `cma` and `mutex` usage.
I'm confident this is actionable, and now it's time to thoroughly examine the code using the provided tools to solidify my understanding and confirm my assumptions. I need to use `codesearch-*, git-*, grepper, etc` and then I'll be able to properly set the results.
|
| 6/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/cma.c FirstLine:1005 LineCount:40]
Results: map[Contents:1005: if (refcount_dec_and_test(&id_priv->refcount))
1006: complete(&id_priv->comp);
1007: }
1008:
1009: static struct rdma_id_private *
1010: __rdma_create_id(struct net *net, rdma_cm_event_handler event_handler,
1011: void *context, enum rdma_ucm_port_space ps,
1012: enum ib_qp_type qp_type, const struct rdma_id_private *parent)
1013: {
1014: struct rdma_id_private *id_priv;
1015:
1016: id_priv = kzalloc_obj(*id_priv);
1017: if (!id_priv)
1018: return ERR_PTR(-ENOMEM);
1019:
1020: id_priv->state = RDMA_CM_IDLE;
1021: id_priv->restricted_node_type = RDMA_NODE_UNSPECIFIED;
1022: id_priv->id.context = context;
1023: id_priv->id.event_handler = event_handler;
1024: id_priv->id.ps = ps;
1025: id_priv->id.qp_type = qp_type;
1026: id_priv->tos_set = false;
1027: id_priv->timeout_set = false;
1028: id_priv->min_rnr_timer_set = false;
1029: id_priv->gid_type = IB_GID_TYPE_IB;
1030: spin_lock_init(&id_priv->lock);
1031: mutex_init(&id_priv->qp_mutex);
1032: init_completion(&id_priv->comp);
1033: refcount_set(&id_priv->refcount, 1);
1034: mutex_init(&id_priv->handler_mutex);
1035: INIT_LIST_HEAD(&id_priv->device_item);
1036: INIT_LIST_HEAD(&id_priv->id_list_entry);
1037: INIT_LIST_HEAD(&id_priv->listen_list);
1038: INIT_LIST_HEAD(&id_priv->mc_list);
1039: get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num);
1040: id_priv->id.route.addr.dev_addr.net = get_net(net);
1041: id_priv->seq_num &= 0x00ffffff;
1042: INIT_WORK(&id_priv->id.net_work, cma_netevent_work_handler);
1043:
1044: rdma_restrack_new(&id_priv->res, RDMA_RESTRACK_CM_ID);
]
|
| 7/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/cma.c FirstLine:3540 LineCount:35]
Results: map[Contents:3540: memcpy(addr, &old_addr,
3541: rdma_addr_size((struct sockaddr *)&old_addr));
3542: if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
3543: RDMA_CM_ADDR_BOUND))
3544: goto out;
3545: event.event = RDMA_CM_EVENT_ADDR_ERROR;
3546: event.status = status;
3547: } else
3548: event.event = RDMA_CM_EVENT_ADDR_RESOLVED;
3549:
3550: if (cma_cm_event_handler(id_priv, &event)) {
3551: destroy_id_handler_unlock(id_priv);
3552: return;
3553: }
3554: out:
3555: mutex_unlock(&id_priv->handler_mutex);
3556: }
3557:
3558: static int cma_resolve_loopback(struct rdma_id_private *id_priv)
3559: {
3560: struct cma_work *work;
3561: union ib_gid gid;
3562: int ret;
3563:
3564: work = kzalloc_obj(*work);
3565: if (!work)
3566: return -ENOMEM;
3567:
3568: if (!id_priv->cma_dev) {
3569: ret = cma_bind_loopback(id_priv);
3570: if (ret)
3571: goto err;
3572: }
3573:
3574: rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid);
]
|
| 8/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/ucma.c FirstLine:180 LineCount:25]
Results: map[Contents: 180:
181: /* once all inflight tasks are finished, we close all underlying
182: * resources. The context is still alive till its explicit destryoing
183: * by its creator. This puts back the xarray's reference.
184: */
185: ucma_put_ctx(ctx);
186: wait_for_completion(&ctx->comp);
187: /* No new events will be generated after destroying the id. */
188: rdma_destroy_id(ctx->cm_id);
189:
190: /* Reading the cm_id without holding a positive ref is not allowed */
191: ctx->cm_id = NULL;
192: }
193:
194: static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
195: {
196: struct ucma_context *ctx;
197:
198: ctx = kzalloc_obj(*ctx);
199: if (!ctx)
200: return NULL;
201:
202: INIT_WORK(&ctx->close_work, ucma_close_id);
203: init_completion(&ctx->comp);
204: INIT_LIST_HEAD(&ctx->mc_list);
]
|
| 9/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/ucma.c FirstLine:575 LineCount:30]
Results: map[Contents: 575:
576: /*
577: * Destroy the underlying cm_id. New work queuing is prevented now by
578: * the removal from the xarray. Once the work is cancled ref will either
579: * be 0 because the work ran to completion and consumed the ref from the
580: * xarray, or it will be positive because we still have the ref from the
581: * xarray. This can also be 0 in cases where cm_id was never set
582: */
583: cancel_work_sync(&ctx->close_work);
584: if (refcount_read(&ctx->ref))
585: ucma_close_id(&ctx->close_work);
586:
587: events_reported = ucma_cleanup_ctx_events(ctx);
588: ucma_cleanup_multicast(ctx);
589:
590: WARN_ON(xa_cmpxchg(&ctx_table, ctx->id, XA_ZERO_ENTRY, NULL,
591: GFP_KERNEL) != NULL);
592: mutex_destroy(&ctx->mutex);
593: kfree(ctx);
594: return events_reported;
595: }
596:
597: static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf,
598: int in_len, int out_len)
599: {
600: struct rdma_ucm_destroy_id cmd;
601: struct rdma_ucm_destroy_id_resp resp;
602: struct ucma_context *ctx;
603: int ret = 0;
604:
]
|
| 10/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 12657
output: 43
thoughts: 95
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing RDMA ID Private Allocation**
Alright, that's interesting. I see a `kzalloc_obj` call within `__rdma_create_id`. Specifically, task 9271 is allocating a `struct rdma_id_private` here. My immediate thought is to check the details of this allocation. Given my familiarity with RDMA, I want to quickly ascertain the size of that structure. I also need to verify where in that struct the `handler_mutex` resides. Knowing the offset of the mutex is key for understanding synchronization within that context. I'm already anticipating the typical race conditions that might arise with `id_priv`!
|
| 11/2 |
2026/10/04 00:53 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_id_private]
Results: map[Fields:[map[Name:id OffsetBits:0 SizeBits:4416] map[Name:bind_list OffsetBits:4416 SizeBits:64] map[Name:node OffsetBits:4480 SizeBits:128] map[Name: OffsetBits:4608 SizeBits:128] map[Name: OffsetBits:4736 SizeBits:128] map[Name:id_list_entry OffsetBits:4864 SizeBits:128] map[Name:cma_dev OffsetBits:4992 SizeBits:64] map[Name:mc_list OffsetBits:5056 SizeBits:128] map[Name:internal_id OffsetBits:5184 SizeBits:32] map[Name:state OffsetBits:5216 SizeBits:32] map[Name:restricted_node_type OffsetBits:5248 SizeBits:8] map[Name:lock OffsetBits:5312 SizeBits:512] map[Name:qp_mutex OffsetBits:5824 SizeBits:1088] map[Name:comp OffsetBits:6912 SizeBits:704] map[Name:refcount OffsetBits:7616 SizeBits:32] map[Name:handler_mutex OffsetBits:7680 SizeBits:1088] map[Name:backlog OffsetBits:8768 SizeBits:32] map[Name:timeout_ms OffsetBits:8800 SizeBits:32] map[Name:query OffsetBits:8832 SizeBits:64] map[Name:query_id OffsetBits:8896 SizeBits:32] map[Name:cm_id OffsetBits:8960 SizeBits:64] map[Name:seq_num OffsetBits:9024 SizeBits:32] map[Name:qkey OffsetBits:9056 SizeBits:32] map[Name:qp_num OffsetBits:9088 SizeBits:32] map[Name:options OffsetBits:9120 SizeBits:32] map[Name:srq OffsetBits:9152 SizeBits:8] map[Name:tos OffsetBits:9160 SizeBits:8] map[Name:tos_set OffsetBits:9168 SizeBits:1] map[Name:timeout_set OffsetBits:9169 SizeBits:1] map[Name:min_rnr_timer_set OffsetBits:9170 SizeBits:1] map[Name:reuseaddr OffsetBits:9176 SizeBits:8] map[Name:afonly OffsetBits:9184 SizeBits:8] map[Name:timeout OffsetBits:9192 SizeBits:8] map[Name:min_rnr_timer OffsetBits:9200 SizeBits:8] map[Name:used_resolve_ip OffsetBits:9208 SizeBits:8] map[Name:gid_type OffsetBits:9216 SizeBits:32] map[Name:res OffsetBits:9280 SizeBits:1024] map[Name:ece OffsetBits:10304 SizeBits:64]]]
|
| 12/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 13786
output: 38
thoughts: 250
Thoughts: **Analyzing a Suspected Mutex Corruption**
Okay, let's break this down. First, I'm looking at `handler_mutex` and see its `OffsetBits` is 7680, which translates to 960 bytes (0x3c0). Then, I see this critical piece of information: the buggy address is 1048 bytes (0x418) into a freed 2048-byte region. My initial thought is, "Wait, what's at that offset?".
Now, let's cross-reference. I know `handler_mutex`'s offset. Time to confirm the layout of `struct mutex`. I've confirmed `handler_mutex` is indeed at 960 bytes, and its size is 136 bytes (1088 bits). Adding those up, 960 + 136 equals 1096 bytes.
Aha! 1048 bytes *is* within the `handler_mutex`'s address range, specifically between 960 and 1096 bytes. I've got a match. Calculating the precise offset, 1048 - 960 is 88 bytes *into* the `handler_mutex` structure. The error is probably a data corruption, a read or write at an offset within that mutex. Time to dive deeper into the `struct mutex` layout itself to pin down which specific member is likely corrupted.
|
| 13/2 |
2026/10/04 00:53 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:mutex]
Results: map[Fields:[map[Name:owner OffsetBits:0 SizeBits:64] map[Name:wait_lock OffsetBits:64 SizeBits:512] map[Name:osq OffsetBits:576 SizeBits:32] map[Name:first_waiter OffsetBits:640 SizeBits:64] map[Name:magic OffsetBits:704 SizeBits:64] map[Name:dep_map OffsetBits:768 SizeBits:320]]]
|
| 14/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 14528
output: 36
thoughts: 172
Thoughts: Okay, let's break this down.
**Analyzing a Kernel Crash and Potential Memory Corruption**
Right, so the system threw a `slab-use-after-free` error, and the crash points to `debug_mutex_unlock` in `kernel/locking/mutex-debug.c`. That's a good starting point. The crucial part, though, is the memory address, `ffff888024e65418`. We are told `magic` is at offset 704 bits = 88 bytes, and that's likely related. 704/8 is indeed 88. And by adding that to a starting offset of 960, we arrive at 1048 bytes (or 0x418 hex). Is there a connection? That crash address, `0x418` looks suspicious, so this bears investigation. Time to dive into that mutex code and see what's happening around line 74. Something funky is going on with that memory address.
|
| 15/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:kernel/locking/mutex-debug.c FirstLine:60 LineCount:25]
Results: map[Contents: 60: struct task_struct *task)
61: {
62: struct mutex *blocked_on = get_task_blocked_on(task);
63:
64: DEBUG_LOCKS_WARN_ON(waiter->task != task);
65: DEBUG_LOCKS_WARN_ON(blocked_on && blocked_on != lock);
66:
67: INIT_LIST_HEAD(&waiter->list);
68: waiter->task = NULL;
69: }
70:
71: void debug_mutex_unlock(struct mutex *lock)
72: {
73: if (likely(debug_locks)) {
74: DEBUG_LOCKS_WARN_ON(lock->magic != lock);
75: }
76: }
77:
78: void debug_mutex_init(struct mutex *lock)
79: {
80: lock->magic = lock;
81: }
82:
83: static void devm_mutex_release(void *res)
84: {
]
|
| 16/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 15274
output: 43
thoughts: 326
Thoughts: **Debugging a Subtle Memory Corruption Issue**
Okay, here's what's running through my head. Line 74! That `DEBUG_LOCKS_WARN_ON` macro is triggering a warning: `lock->magic != lock`. I know exactly what this means β it's a classic sign of memory corruption related to a lock! The really intriguing part is the precision of this read. `lock->magic` is a read of size 8, exactly at offset 88 within a `struct mutex`, and that mutex, `id_priv->handler_mutex`, resides at offset 1048 (0x418) of a `struct rdma_id_private`. This level of detail is critical, and it's pointing us to a very specific location in memory. I have to remember that offset when I look at the freeing logic.
Alright, time to examine the stack trace of the `kfree` call. It looks like task 9270 is freeing something and it's happening through `ucma_close_id`, then a cascade of calls: `ucma_destroy_private_ctx`, then `ucma_close` and finally `__fput`. Now, let's look at `ucma_close_id`.
I see it! `rdma_destroy_id(ctx->cm_id);` This is very likely the source of the trouble.
|
| 17/2 |
2026/10/04 00:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_destroy_id]
Results: map[SourceCode:2119: void rdma_destroy_id(struct rdma_cm_id *id)
2120: {
2121: struct rdma_id_private *id_priv =
2122: container_of(id, struct rdma_id_private, id);
2123:
2124: mutex_lock(&id_priv->handler_mutex);
2125: destroy_id_handler_unlock(id_priv);
2126: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 18/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 16109
output: 44
thoughts: 14
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the `destroy_id_handler_unlock` Function**
Alright, let's dive into this `destroy_id_handler_unlock` function. My initial thought is to immediately consider its context. What's the surrounding code? Where is this being called? I'm assuming, given the name, it's dealing with some sort of resource cleanup or management, specifically tied to an ID or handle, and importantly, is related to locking. The use of "unlock" in the name suggests a critical section or shared resource is involved.
My mind immediately starts ticking through the potential implications: thread safety is paramount here. Is this an RAII pattern? Is it managing a mutex, a semaphore, or something more complex? I need to understand the locking primitive used, and the scope of its protection. What happens if the `unlock` fails? Is there any error handling? Deadlocks are an obvious concern β how is this function designed to prevent them?
The `destroy` part of the name leads me to think this is the end of the line for some managed object, a release of a potentially precious resource. What cleanup operations are happening in this function? Memory deallocation? Resource closure (files, sockets, etc.)? Are we following proper exception safety practices here? Is this operation atomic, or does it require a transaction-like approach?
I need to quickly assess the potential for race conditions. If multiple threads are vying for this ID, how are we absolutely guaranteeing that the lock is held *before* the destruction and unlock is initiated, and then released in the correct order to protect the data/state? Also, the 'ID' itself is of interest. How is the identifier managed? Does it have a global scope? Is it part of a table? Are there any potential memory leaks or vulnerabilities in the ID management system?
|
| 19/2 |
2026/10/04 00:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:destroy_id_handler_unlock]
Results: map[SourceCode:2092: /*
2093: * destroy an ID from within the handler_mutex. This ensures that no other
2094: * handlers can start running concurrently.
2095: */
2096: static void destroy_id_handler_unlock(struct rdma_id_private *id_priv)
2097: __releases(&idprv->handler_mutex)
2098: {
2099: enum rdma_cm_state state;
2100: unsigned long flags;
2101:
2102: trace_cm_id_destroy(id_priv);
2103:
2104: /*
2105: * Setting the state to destroyed under the handler mutex provides a
2106: * fence against calling handler callbacks. If this is invoked due to
2107: * the failure of a handler callback then it guarentees that no future
2108: * handlers will be called.
2109: */
2110: lockdep_assert_held(&id_priv->handler_mutex);
2111: spin_lock_irqsave(&id_priv->lock, flags);
2112: state = id_priv->state;
2113: id_priv->state = RDMA_CM_DESTROYING;
2114: spin_unlock_irqrestore(&id_priv->lock, flags);
2115: mutex_unlock(&id_priv->handler_mutex);
2116: _destroy_id(id_priv, state);
2117: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 20/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 17016
output: 41
thoughts: 13
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:
**Analyzing the `_destroy_id` Function**
Alright, I need to get a handle on this `_destroy_id` function. What's its purpose? My initial thought is it's likely a function to remove some kind of identifier, likely associated with a resource or data structure. The name suggests it's designed to *destroy* something, specifically targeting an ID. I need to understand what that ID represents in the broader context of this system. Is it a database key? A unique token? A pointer? Is it merely marking something for deletion, or immediately removing it? Knowing this is vital to understanding the function's implications, and its interactions with other components. Is there any cascading effect? Any error handling? I better trace it back to its origin and see how it fits into the overall architecture.
|
| 21/2 |
2026/10/04 00:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:_destroy_id]
Results: map[SourceCode:2057: static void _destroy_id(struct rdma_id_private *id_priv,
2058: enum rdma_cm_state state)
2059: {
2060: cma_cancel_operation(id_priv, state);
2061:
2062: rdma_restrack_del(&id_priv->res);
2063: cma_remove_id_from_tree(id_priv);
2064: if (id_priv->cma_dev) {
2065: if (rdma_cap_ib_cm(id_priv->id.device, 1)) {
2066: if (id_priv->cm_id.ib)
2067: ib_destroy_cm_id(id_priv->cm_id.ib);
2068: } else if (rdma_cap_iw_cm(id_priv->id.device, 1)) {
2069: if (id_priv->cm_id.iw)
2070: iw_destroy_cm_id(id_priv->cm_id.iw);
2071: }
2072: cma_leave_mc_groups(id_priv);
2073: cma_release_dev(id_priv);
2074: }
2075:
2076: cma_release_port(id_priv);
2077: cma_id_put(id_priv);
2078: wait_for_completion(&id_priv->comp);
2079:
2080: if (id_priv->internal_id)
2081: cma_id_put(id_priv->id.context);
2082:
2083: kfree(id_priv->id.route.path_rec);
2084: kfree(id_priv->id.route.path_rec_inbound);
2085: kfree(id_priv->id.route.path_rec_outbound);
2086: kfree(id_priv->id.route.service_recs);
2087:
2088: put_net(id_priv->id.route.addr.dev_addr.net);
2089: kfree(id_priv);
2090: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 22/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 17913
output: 42
thoughts: 466
Thoughts: **Analyzing a Potential Memory Management Issue**
Okay, here's what's running through my head. I'm looking at a kernel memory dump, specifically focusing on a `kfree` call at line 2089, which is freeing `id_priv`. My initial thought is that this should be okay, but I need to trace this back to understand its context. I see that `rdma_destroy_id` was inlined into `ucma_close_id`, then `destroy_id_handler_unlock` into `rdma_destroy_id`, and finally `_destroy_id` was inlined. So now I can see clearly that the `kfree(id_priv)` is being directly called from `ucma_close_id` at line 188.
Now, I'm examining the call trace leading up to this `kfree` call. I can see that this `kfree` is called by task 9270. I need to understand *how* it got there. From the call trace provided, I'm seeing `debug_mutex_unlock`, which then calls `__mutex_unlock_slowpath`, which in turn leads to `addr_handler`, and then to `process_one_req`, and finally to `process_one_work`.
I'm making a mental note to zoom in on `addr_handler` and `process_one_req`. These functions are important because they are where the flow of execution seems to originate. They might be the entry points that are causing the `id_priv` to be freed. I need to understand what's happening within those functions to make sure there's no double-free or incorrect locking involved. This trace looks like it's pointing me towards a potential issue related to the UCMA library's handling of RDMA IDs within an address handling context. My next steps are clearly to dive deeper into `addr_handler` and `process_one_req` to see how the RDMA ID is being managed and to assess the locking/unlocking behavior.
|
| 23/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/cma.c FirstLine:3500 LineCount:60]
Results: map[Contents:3500: cma_attach_to_dev(id_priv, cma_dev);
3501: rdma_restrack_add(&id_priv->res);
3502: cma_set_loopback(cma_src_addr(id_priv));
3503: out:
3504: mutex_unlock(&lock);
3505: return ret;
3506: }
3507:
3508: static void addr_handler(int status, struct sockaddr *src_addr,
3509: struct rdma_dev_addr *dev_addr, void *context)
3510: {
3511: struct rdma_id_private *id_priv = context;
3512: struct rdma_cm_event event = {};
3513: struct sockaddr *addr;
3514: struct sockaddr_storage old_addr;
3515:
3516: mutex_lock(&id_priv->handler_mutex);
3517: if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
3518: RDMA_CM_ADDR_RESOLVED))
3519: goto out;
3520:
3521: /*
3522: * Store the previous src address, so that if we fail to acquire
3523: * matching rdma device, old address can be restored back, which helps
3524: * to cancel the cma listen operation correctly.
3525: */
3526: addr = cma_src_addr(id_priv);
3527: memcpy(&old_addr, addr, rdma_addr_size(addr));
3528: memcpy(addr, src_addr, rdma_addr_size(src_addr));
3529: if (!status && !id_priv->cma_dev) {
3530: status = cma_acquire_dev_by_src_ip(id_priv);
3531: if (status)
3532: pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n",
3533: status);
3534: rdma_restrack_add(&id_priv->res);
3535: } else if (status) {
3536: pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to resolve IP. status %d\n", status);
3537: }
3538:
3539: if (status) {
3540: memcpy(addr, &old_addr,
3541: rdma_addr_size((struct sockaddr *)&old_addr));
3542: if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
3543: RDMA_CM_ADDR_BOUND))
3544: goto out;
3545: event.event = RDMA_CM_EVENT_ADDR_ERROR;
3546: event.status = status;
3547: } else
3548: event.event = RDMA_CM_EVENT_ADDR_RESOLVED;
3549:
3550: if (cma_cm_event_handler(id_priv, &event)) {
3551: destroy_id_handler_unlock(id_priv);
3552: return;
3553: }
3554: out:
3555: mutex_unlock(&id_priv->handler_mutex);
3556: }
3557:
3558: static int cma_resolve_loopback(struct rdma_id_private *id_priv)
3559: {
]
|
| 24/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 19863
output: 40
thoughts: 135
Thoughts: Here's my analysis of the provided code snippet and the surrounding context:
**Analyzing the RDMA Connection Manager Address Handling**
Okay, so I'm looking at `addr_handler` here, specifically the locking and state transition logic. First, the code acquires a mutex, `id_priv->handler_mutex`, ensuring exclusive access, which is the expected pattern. Good, standard practice. Now, I see this `cma_comp_exch` call. It looks like it's performing a compare-and-exchange operation on the connection manager state. Let's see... it's checking if the current state is `RDMA_CM_ADDR_QUERY` and, if so, atomically transitioning it to `RDMA_CM_ADDR_RESOLVED`. This is crucial for avoiding race conditions during the address resolution phase. If the compare-and-exchange fails, meaning the state isn't what we expect, it jumps to `out` after a failure. Then the mutex gets unlocked. Standard locking pattern, again. I'd expect that the mutex is unlocked in all cases to avoid deadlocks. This is a crucial section.
Hold on a second, I need to zoom out a bit. It seems like the state transition is part of this address resolution process in the context of the RDMA Connection Manager. It's critical to look at the surrounding code to grasp the whole picture. I really need to understand why this address resolution is happening and what could possibly cause the exchange to fail.
Okay, let's see. Let me quickly jump over to `drivers/infiniband/core/addr.c:624`. Hopefully I can find `process_one_req` around there. This will give me a better understanding of the whole control flow.
|
| 25/2 |
2026/10/04 00:53 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/addr.c FirstLine:605 LineCount:40]
Results: map[Contents: 605:
606: if (req->status == -ENODATA) {
607: src_in = (struct sockaddr *)&req->src_addr;
608: dst_in = (struct sockaddr *)&req->dst_addr;
609: req->status = addr_resolve(src_in, dst_in, req->addr,
610: true, req->resolve_by_gid_attr,
611: req->seq);
612: if (req->status && time_after_eq(jiffies, req->timeout)) {
613: req->status = -ETIMEDOUT;
614: } else if (req->status == -ENODATA) {
615: /* requeue the work for retrying again */
616: spin_lock_bh(&lock);
617: if (!list_empty(&req->list))
618: set_timeout(req, req->timeout);
619: spin_unlock_bh(&lock);
620: return;
621: }
622: }
623:
624: req->callback(req->status, (struct sockaddr *)&req->src_addr,
625: req->addr, req->context);
626: req->callback = NULL;
627:
628: spin_lock_bh(&lock);
629: /*
630: * Although the work will normally have been canceled by the workqueue,
631: * it can still be requeued as long as it is on the req_list.
632: */
633: cancel_delayed_work(&req->work);
634: if (!list_empty(&req->list)) {
635: list_del_init(&req->list);
636: kfree(req);
637: }
638: spin_unlock_bh(&lock);
639: }
640:
641: int rdma_resolve_ip(struct sockaddr *src_addr, const struct sockaddr *dst_addr,
642: struct rdma_dev_addr *addr, unsigned long timeout_ms,
643: void (*callback)(int status, struct sockaddr *src_addr,
644: struct rdma_dev_addr *addr, void *context),
]
|
| 26/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 21068
output: 43
thoughts: 85
Thoughts: Here's my thought process, as it went down:
**A Troubling Callback Sequence**
Okay, so `req->callback` was triggered, and it pointed to `addr_handler`. Fine, that's what I expected. But the `req->context`... it's `id_priv`! And then, a red flag immediately pops up in my head. Hold on a second, something is seriously wrong here. How could `id_priv`, this crucial piece of context, possibly be freed while `addr_handler` is still executing, or before it's even completed its task? That just screams race condition and potential use-after-free vulnerability! I need to dig deeper. Let's see how `cma_cancel_operation` handles this over in `drivers/infiniband/core/cma.c`. That's where the cleanup logic likely lies. I need to understand the cancellation path to see how they're handling, or *failing* to handle, the lifecycle of this `id_priv` context in relation to `addr_handler`'s execution.
|
| 27/2 |
2026/10/04 00:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:cma_cancel_operation]
Results: map[SourceCode:1963: static void cma_cancel_operation(struct rdma_id_private *id_priv,
1964: enum rdma_cm_state state)
1965: {
1966: switch (state) {
1967: case RDMA_CM_ADDR_QUERY:
1968: /*
1969: * We can avoid doing the rdma_addr_cancel() based on state,
1970: * only RDMA_CM_ADDR_QUERY has a work that could still execute.
1971: * Notice that the addr_handler work could still be exiting
1972: * outside this state, however due to the interaction with the
1973: * handler_mutex the work is guaranteed not to touch id_priv
1974: * during exit.
1975: */
1976: rdma_addr_cancel(&id_priv->id.route.addr.dev_addr);
1977: break;
1978: case RDMA_CM_ROUTE_QUERY:
1979: cma_cancel_route(id_priv);
1980: break;
1981: case RDMA_CM_LISTEN:
1982: if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev)
1983: cma_cancel_listens(id_priv);
1984: break;
1985: default:
1986: break;
1987: }
1988: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 28/2 |
2026/10/04 00:53 |
llm |
expert |
0m
Model:
Tokens:
input: 21879
output: 43
thoughts: 667
Thoughts: **Analyzing a Potential Race Condition in RDMA Connection Management**
Okay, let's break this down. First, I'm examining this `cma_cancel_operation` function and that comment in there about `RDMA_CM_ADDR_QUERY`. The code says we can avoid `rdma_addr_cancel()` based on the state, but specifically, it seems like `RDMA_CM_ADDR_QUERY` is the one where a work item *could* still be running. The comment mentions that although `addr_handler` might be exiting outside this state, the interaction with `handler_mutex` guarantees the work won't touch `id_priv` during exit. But wait, is that really true?
I'm now cross-referencing this with how `destroy_id_handler_unlock` handles the destruction process, especially in relation to `addr_handler`. In `destroy_id_handler_unlock`, we see a critical sequence: grab `handler_mutex`, lock an internal spinlock, read `id_priv->state`, set `id_priv->state` to `RDMA_CM_DESTROYING`, release the spinlock, then release the `handler_mutex`. Crucially, `_destroy_id` is called *after* this and is passed the old state value.
This is where the concern arises. What if `addr_handler` is queued or is about to run, right? Let's trace this through. We know `addr_handler` locks the `handler_mutex` and checks the state with `cma_comp_exch`. Let's say `addr_handler` *was* queued. Now `rdma_destroy_id` gets called and it also grabs `handler_mutex`. If the state, when `rdma_destroy_id` gets called, is still `RDMA_CM_ADDR_QUERY`, then inside `rdma_destroy_id` we have: grab `handler_mutex`, read the state as `RDMA_CM_ADDR_QUERY`, then set `id_priv->state` to `RDMA_CM_DESTROYING` and release the mutex. Afterwards, `_destroy_id` is called with the original state, which is `RDMA_CM_ADDR_QUERY`. Now `cma_cancel_operation` is called and, because the state is `RDMA_CM_ADDR_QUERY`, `rdma_addr_cancel` is called.
Here's the problem: is there a race condition? I need to know if `rdma_addr_cancel` waits for the work to finish. I'm going to have to dive into the implementation of `rdma_addr_cancel` to confirm if it waits for any work to complete before freeing resources. It's the only way to be sure there isn't a race here.
|
| 29/2 |
2026/10/04 00:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_addr_cancel]
Results: map[SourceCode: 741: /**
742: * rdma_addr_cancel - Cancel resolve ip request
743: * @addr: Pointer to address structure given previously
744: * during rdma_resolve_ip().
745: * rdma_addr_cancel() is synchronous function which cancels any pending
746: * request if there is any.
747: */
748: void rdma_addr_cancel(struct rdma_dev_addr *addr)
749: {
750: struct addr_req *req, *temp_req;
751: struct addr_req *found = NULL;
752:
753: spin_lock_bh(&lock);
754: list_for_each_entry_safe(req, temp_req, &req_list, list) {
755: if (req->addr == addr) {
756: /*
757: * Removing from the list means we take ownership of
758: * the req
759: */
760: list_del_init(&req->list);
761: found = req;
762: break;
763: }
764: }
765: spin_unlock_bh(&lock);
766:
767: if (!found)
768: return;
769:
770: /*
771: * sync canceling the work after removing it from the req_list
772: * guarentees no work is running and none will be started.
773: */
774: cancel_delayed_work_sync(&found->work);
775: kfree(found);
776: }
SourceFile:drivers/infiniband/core/addr.c]
|
| 30/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 23712
output: 36
thoughts: 1048
Thoughts: **Race Condition Discovered in RDMA Connection Management**
Okay, let's break this down. I've been digging into the RDMA connection management code, specifically focusing on address handling and ID destruction. I've noticed a potential race condition and I need to document this.
The core of the issue seems to stem from how requests are handled and how the connection ID (`id_priv`) is managed. Looking at `rdma_addr_cancel` and `process_one_req`, I see a clear path where a callback function (`addr_handler` in this case) is invoked *while* the request structure (`req`) is still on a shared list (`req_list`).
Specifically, `process_one_req` calls `req->callback`, which turns out to be `addr_handler`. Importantly, the `req` isn't removed from the list *before* this callback is executed. Inside `addr_handler`, the code acquires a mutex (`id_priv->handler_mutex`), and depending on the state of `id_priv` it can call `cma_comp_exch` and change state, and may then generate events, or an error could occur.
Here's where the problem arises: What if `rdma_destroy_id` is called *concurrently*? `rdma_destroy_id` also tries to acquire the *same* `handler_mutex`! This means `rdma_destroy_id` could be blocked waiting for `addr_handler` to release the mutex.
Now, consider what happens *after* `addr_handler` has potentially changed states of the connection ID. `addr_handler` then unlocks the `handler_mutex`, and this is where it's happening!
The crash dump (`debug_mutex_unlock`) provides a crucial clue. It points directly to `addr_handler` calling `__mutex_unlock_slowpath` and then to the debug function. This is unusual and likely indicates a double unlock or a corruption of the mutex state. The backtrace shows `addr_handler` at line 3555 calling `mutex_unlock(&id_priv->handler_mutex)`.
This is where it gets scary. The debugger is telling me that someone, specifically `rdma_destroy_id`, must have freed `id_priv` *before* `addr_handler` could unlock the mutex. We have a classic use-after-free scenario. This is because the request wasn't removed from the shared `req_list` prior to calling the callback.
So, the likely sequence is:
1. `addr_handler` acquires `id_priv->handler_mutex`.
2. `rdma_destroy_id` attempts to acquire the *same* `handler_mutex` and blocks.
3. `addr_handler` does some work.
4. `addr_handler` unlocks `handler_mutex`. This access to `id_priv` is potentially corrupt at this point.
The root cause? The lack of proper synchronization between the request list processing and the connection ID destruction. `rdma_addr_cancel` does not *guarantee* that the request is removed from the `req_list` before `process_one_req` runs. The `req` is still on `req_list` at the point of `callback`.
I need to investigate the list management and synchronization to ensure that `req` is removed from `req_list` and any operations on the connection ID are properly protected, or that the lifetime of the request is extended while `addr_handler` is running. This looks like a nasty one that could lead to intermittent and hard-to-reproduce crashes.
|
| 31/2 |
2026/10/04 00:54 |
tool |
read-file |
0m
Args: map[File:kernel/locking/mutex.c FirstLine:1015 LineCount:40]
Results: map[Contents:1015: break;
1016: }
1017:
1018: if (owner & MUTEX_FLAG_HANDOFF)
1019: break;
1020:
1021: if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, __owner_flags(owner))) {
1022: if (owner & MUTEX_FLAG_WAITERS)
1023: break;
1024:
1025: return;
1026: }
1027: }
1028:
1029: raw_spin_lock_irqsave(&lock->wait_lock, flags);
1030: raw_spin_lock(¤t->blocked_lock);
1031: debug_mutex_unlock(lock);
1032:
1033: if (sched_proxy_exec()) {
1034: /*
1035: * If we have a task boosting current, and that task was boosting
1036: * current through this lock, hand the lock to that task, as that
1037: * is the highest waiter, as selected by the scheduling function.
1038: */
1039: donor = current->blocked_donor;
1040: if (donor) {
1041: struct mutex *next_lock;
1042:
1043: raw_spin_lock_nested(&donor->blocked_lock, SINGLE_DEPTH_NESTING);
1044: next_lock = __get_task_blocked_on(donor);
1045: if (next_lock == lock) {
1046: next = get_task_struct(donor);
1047: __clear_task_blocked_on(next, lock);
1048: current->blocked_donor = NULL;
1049: }
1050: raw_spin_unlock(&donor->blocked_lock);
1051: }
1052: }
1053:
1054: /*
]
|
| 32/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 26140
output: 53
thoughts: 1671
Thoughts: **A Deep Dive into a Potential Race Condition**
Okay, so I'm looking at this unlock path in `__mutex_unlock_slowpath`, and something's bugging me. Specifically, in the scenario where `atomic_long_try_cmpxchg_release` succeeds, which means the lock is immediately released. I have to think through the execution path. If the waiter is in `rdma_destroy_id`, it should see the lock cleared or acquire it immediately.
Then I'm considering the edge case when the `MUTEX_FLAG_WAITERS` flag is set. That takes the flow to the `wait_lock` spinlock, which I think is a good thing.
Now, let's zoom in on `addr_handler`. It's locking `handler_mutex`. If `destroy_id_handler_unlock` has already run, let's see where that goes... Oh, wow. `destroy_id_handler_unlock` does the following: it holds `handler_mutex`, sets `id_priv->state` to `RDMA_CM_DESTROYING`, *then* unlocks `handler_mutex` *before* calling `_destroy_id`. Inside `_destroy_id`, it calls `cma_cancel_operation` and then it *frees* `id_priv`!
If `addr_handler` was waiting for `handler_mutex`, it will now wake up, acquire the lock, and then, because `id_priv->state` is now `RDMA_CM_DESTROYING`, `cma_comp_exch` will fail, leading to an immediate unlock.
Meanwhile, `destroy_id_handler_unlock` is proceeding with `_destroy_id`. If `state` was `RDMA_CM_ADDR_QUERY` before `destroy_id_handler_unlock` changed it, `cma_cancel_operation` will call `rdma_addr_cancel`.
Now, if `rdma_addr_cancel` is called, it can call `cancel_delayed_work_sync(&found->work)`. Now here we have a workqueue function (`found->work`), that can potentially be running concurrently. Let's look at `process_one_req`. In here, `cancel_delayed_work(&req->work)` will be called and potentially race with the execution path. This looks like a race condition and a good candidate for debugging.
Let's check where the `req->work` is queued in `addr.c`.
|
| 33/2 |
2026/10/04 00:54 |
tool |
grepper |
0m
Args: map[Expression:INIT_DELAYED_WORK.*process_one_req|queue_delayed_work.*addr PathPrefixes:[drivers/infiniband/core/addr.c]]
Results: map[Output:drivers/infiniband/core/addr.c=641=int rdma_resolve_ip(struct sockaddr *src_addr, const struct sockaddr *dst_addr,
--
drivers/infiniband/core/addr.c-673- req->resolve_by_gid_attr = resolve_by_gid_attr;
drivers/infiniband/core/addr.c:674: INIT_DELAYED_WORK(&req->work, process_one_req);
drivers/infiniband/core/addr.c-675- req->seq = (u32)atomic_inc_return(&ib_nl_addr_request_seq);
]
|
| 34/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 28575
output: 40
thoughts: 29
Thoughts: Okay, let's dive into this. Here's my take on those lines of code:
**Analyzing the Infiniband Address Handling in `addr.c`**
Alright, time to focus. I need to get a handle on what's happening specifically within lines 640-740 of `drivers/infiniband/core/addr.c`. This section likely deals with how the InfiniBand address resolution and manipulation functions operate, and I have a feeling the devil's in the details here. Given the scope of that range, I'm anticipating this is a critical chunk of code that handles address translation, perhaps dealing with LIDs (Local IDs), GIDs (Global IDs), or routing logic. I'll need to pay close attention to the data structures involved, the specific functions being called within this segment, and any potential error handling or boundary conditions that are addressed. Is this where they are managing the cache, or the hash, for quickly looking up the IB info? I'll probably be looking at how the address formats are parsed, validated, and translated, and I want to identify the circumstances that trigger different address resolution strategies. I'm also betting it deals with the interaction of these internal addresses with the physical network. Now, let's dig into the code and see what surprises it has in store for me!
|
| 35/2 |
2026/10/04 00:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/addr.c FirstLine:660 LineCount:80]
Results: map[Contents: 660: ret = -EINVAL;
661: goto err;
662: }
663:
664: memcpy(src_in, src_addr, rdma_addr_size(src_addr));
665: } else {
666: src_in->sa_family = dst_addr->sa_family;
667: }
668:
669: memcpy(dst_in, dst_addr, rdma_addr_size(dst_addr));
670: req->addr = addr;
671: req->callback = callback;
672: req->context = context;
673: req->resolve_by_gid_attr = resolve_by_gid_attr;
674: INIT_DELAYED_WORK(&req->work, process_one_req);
675: req->seq = (u32)atomic_inc_return(&ib_nl_addr_request_seq);
676:
677: req->status = addr_resolve(src_in, dst_in, addr, true,
678: req->resolve_by_gid_attr, req->seq);
679: switch (req->status) {
680: case 0:
681: req->timeout = jiffies;
682: queue_req(req);
683: break;
684: case -ENODATA:
685: req->timeout = msecs_to_jiffies(timeout_ms) + jiffies;
686: queue_req(req);
687: break;
688: default:
689: ret = req->status;
690: goto err;
691: }
692: return ret;
693: err:
694: kfree(req);
695: return ret;
696: }
697: EXPORT_SYMBOL(rdma_resolve_ip);
698:
699: int roce_resolve_route_from_path(struct sa_path_rec *rec,
700: const struct ib_gid_attr *attr)
701: {
702: union {
703: struct sockaddr _sockaddr;
704: struct sockaddr_in _sockaddr_in;
705: struct sockaddr_in6 _sockaddr_in6;
706: } sgid, dgid;
707: struct rdma_dev_addr dev_addr = {};
708: int ret;
709:
710: might_sleep();
711:
712: if (rec->roce.route_resolved)
713: return 0;
714:
715: rdma_gid2ip((struct sockaddr *)&sgid, &rec->sgid);
716: rdma_gid2ip((struct sockaddr *)&dgid, &rec->dgid);
717:
718: if (sgid._sockaddr.sa_family != dgid._sockaddr.sa_family)
719: return -EINVAL;
720:
721: if (!attr || !attr->ndev)
722: return -EINVAL;
723:
724: dev_addr.net = &init_net;
725: dev_addr.sgid_attr = attr;
726:
727: ret = addr_resolve((struct sockaddr *)&sgid, (struct sockaddr *)&dgid,
728: &dev_addr, false, true, 0);
729: if (ret)
730: return ret;
731:
732: if ((dev_addr.network == RDMA_NETWORK_IPV4 ||
733: dev_addr.network == RDMA_NETWORK_IPV6) &&
734: rec->rec_type != SA_PATH_REC_TYPE_ROCE_V2)
735: return -EINVAL;
736:
737: rec->roce.route_resolved = true;
738: return 0;
739: }
]
|
| 36/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 30103
output: 39
thoughts: 24
Thoughts: Okay, let's dive into this. Here's my thought process on this snippet:
**Diving into `queue_req(req)`**
Wait a minute! Before I make any assumptions or jump to conclusions, I need to understand the function `queue_req(req)`. It's the lynchpin, the crucial element here. I need to know exactly what it does, how it interacts with other components, and what its side effects are. I can't proceed without a concrete understanding of this function's behavior. Time to investigate what's actually happening within `queue_req`. I have to confirm the details.
|
| 37/2 |
2026/10/04 00:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/addr.c Name:queue_req]
Results: map[SourceCode: 295: static void queue_req(struct addr_req *req)
296: {
297: spin_lock_bh(&lock);
298: list_add_tail(&req->list, &req_list);
299: set_timeout(req, req->timeout);
300: spin_unlock_bh(&lock);
301: }
SourceFile:drivers/infiniband/core/addr.c]
|
| 38/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 30441
output: 39
thoughts: 7
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Deep Dive into `set_timeout`**
Alright, let's dissect this `set_timeout` function. I'm immediately drawn to the inherent asynchronicity it implies. My brain's already firing on questions: How does the underlying scheduler manage this? Is it thread-based, event-driven, or a hybrid? What's the context switching overhead, and how does it compare to other async primitives? I need to understand its precision β is it guaranteed to execute *at least* after the specified time, or is there some inherent jitter? And more importantly, what kind of guarantees does it make regarding the execution of the callback within the current environment?
Is it susceptible to blocking within the callback? If so, what mechanisms are in place to mitigate that, such as separate threads for a computationally intensive task? I'm also curious about error handling. What happens if the callback throws an exception? Does it get propagated, or is it silently swallowed? Knowing how error propagation works is critical to building reliable asynchronous systems.
Then, there's the question of cancellation. Can I reliably cancel a `set_timeout` call before it fires? And if so, what are the implications on any resources that the callback might have been holding? Is there a cleanup mechanism?
I also want to know how this interacts with any existing concurrency primitives, such as mutexes or condition variables. Does it offer any inherent thread safety or synchronization, or is that left entirely to the developer to manage? Furthermore, how does it interact with the event loop in an environment where it's relevant, and if it's there, is it cooperative or preemptive?
|
| 39/2 |
2026/10/04 00:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/addr.c Name:set_timeout]
Results: map[SourceCode: 284: static void set_timeout(struct addr_req *req, unsigned long time)
285: {
286: unsigned long delay;
287:
288: delay = time - jiffies;
289: if ((long)delay < 0)
290: delay = 0;
291:
292: mod_delayed_work(addr_wq, &req->work, delay);
293: }
SourceFile:drivers/infiniband/core/addr.c]
|
| 40/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 31022
output: 43
thoughts: 557
Thoughts: **Analyzing a Potential Race Condition in RDMA Connection Management**
Okay, hold on a second. This doesn't seem right. Why would `_destroy_id` attempt to free `id_priv` while `addr_handler` is potentially still running, specifically while it's in a state where it could be using `id_priv`? That seems like a classic race condition waiting to happen.
Wait! I should look at `cma_cancel_operation`. Specifically, I need to understand when it's called and what it does in relation to these state transitions:
```c
static void cma_cancel_operation(struct rdma_id_private *id_priv,
enum rdma_cm_state state)
{
switch (state) {
case RDMA_CM_ADDR_QUERY:
rdma_addr_cancel(&id_priv->id.route.addr.dev_addr);
break;
case RDMA_CM_ROUTE_QUERY:
...
```
Ah-ha! A crucial point. What if, *when* `destroy_id_handler_unlock(id_priv)` is called, the current `state` of `id_priv` is *not* `RDMA_CM_ADDR_QUERY`? The potential for problems here is obvious. This is a critical factor I need to keep in mind.
Now, when is `id_priv->state` actually set? I should check `addr_handler` to find out how `id_priv->state` is changed.
```c
static void addr_handler(int status, struct sockaddr *src_addr,
struct rdma_dev_addr *dev_addr, void *context)
{
struct rdma_id_private *id_priv = context;
struct rdma_cm_event event = {};
struct sockaddr *addr;
struct sockaddr_storage old_addr;
mutex_lock(&id_priv->handler_mutex);
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
RDMA_CM_ADDR_RESOLVED))
goto out;
```
Ah! What if `addr_handler` has *already* executed that `cma_comp_exch` function with the state transitions `RDMA_CM_ADDR_QUERY` to `RDMA_CM_ADDR_RESOLVED`? That means the state is now `RDMA_CM_ADDR_RESOLVED`.
So, what happens if `cma_cm_event_handler(id_priv, &event)` is called after that? I need to analyze the implications of that state transition.
Now, in `addr_handler`:
```c
if (cma_cm_event_handler(id_priv, &event)) {
destroy_id_handler_unlock(id_priv);
return;
}
out:
mutex_unlock(&id_priv->handler_mutex);
```
Okay, so what if `cma_cm_event_handler` *doesn't* return non-zero? In other words, if it returns 0 (e.g., if we have a user CM ID ucma event handler)? I need to understand what `ucma_event_handler` *actually* does. That is the next step to find the potential issue!
|
| 41/2 |
2026/10/04 00:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/ucma.c Name:ucma_event_handler]
Results: map[SourceCode: 339: static int ucma_event_handler(struct rdma_cm_id *cm_id,
340: struct rdma_cm_event *event)
341: {
342: struct ucma_event *uevent;
343: struct ucma_context *ctx = cm_id->context;
344:
345: if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST)
346: return ucma_connect_event_handler(cm_id, event);
347:
348: /*
349: * We ignore events for new connections until userspace has set their
350: * context. This can only happen if an error occurs on a new connection
351: * before the user accepts it. This is okay, since the accept will just
352: * fail later. However, we do need to release the underlying HW
353: * resources in case of a device removal event.
354: */
355: if (ctx->uid) {
356: uevent = ucma_create_uevent(ctx, event);
357: if (!uevent)
358: return 0;
359:
360: mutex_lock(&ctx->file->mut);
361: list_add_tail(&uevent->list, &ctx->file->event_list);
362: mutex_unlock(&ctx->file->mut);
363: wake_up_interruptible(&ctx->file->poll_wait);
364: }
365:
366: if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) {
367: xa_lock(&ctx_table);
368: if (xa_load(&ctx_table, ctx->id) == ctx)
369: queue_work(system_dfl_wq, &ctx->close_work);
370: xa_unlock(&ctx_table);
371: }
372: return 0;
373: }
SourceFile:drivers/infiniband/core/ucma.c]
|
| 42/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 32969
output: 35
thoughts: 515
Thoughts: **Analyzing a Potential Race Condition in RDMA Connection Management**
Okay, so `ucma_event_handler` returned 0, meaning something went as expected, but now I need to dive deeper into the `addr_handler` function. Specifically, I see that `cma_cm_event_handler` also returned 0 within `addr_handler`, which is a good initial sign. The execution path then reached line 3554, where the `id_priv->handler_mutex` is unlocked. Now I need to consider a potential race condition.
Could another thread have called `ucma_close` *before* or *during* the execution of `addr_handler`, *before* the mutex is unlocked? If that's the case, and `addr_handler` is holding `id_priv->handler_mutex`, a call to `rdma_destroy_id(ctx->cm_id)` would get blocked at the `mutex_lock(&id_priv->handler_mutex)` call within `rdma_destroy_id`.
Then, if `addr_handler` completes and calls `mutex_unlock(&id_priv->handler_mutex)`, it effectively releases the lock that `rdma_destroy_id` is waiting on. The crucial part now is that `addr_handler` is calling `mutex_unlock`. I need to understand what's happening within `mutex_unlock`, so, I need to check `__mutex_unlock_slowpath` in `kernel/locking/mutex.c`. I need to inspect lines 990-1040 to see what exactly happens within `__mutex_unlock_slowpath` to see what could be happening here.
|
| 43/2 |
2026/10/04 00:54 |
tool |
read-file |
0m
Args: map[File:kernel/locking/mutex.c FirstLine:990 LineCount:50]
Results: map[Contents: 990: __release(lock);
991:
992: /*
993: * Ensures the proxy donor stack is stable across unlock and handoff.
994: * Specifically, it avoids the case where current->blocked_donor is
995: * NULL when it is inspected while doing the unlock, but a preemption
996: * before taking the wake_lock would make it set and a hand-off is
997: * missed.
998: */
999: guard(preempt)();
1000: /*
1001: * Release the lock before (potentially) taking the spinlock such that
1002: * other contenders can get on with things ASAP.
1003: *
1004: * Except when HANDOFF, in that case we must not clear the owner field,
1005: * but instead set it to the top waiter.
1006: */
1007: owner = atomic_long_read(&lock->owner);
1008: for (;;) {
1009: MUTEX_WARN_ON(__owner_task(owner) != current);
1010: MUTEX_WARN_ON(owner & MUTEX_FLAG_PICKUP);
1011:
1012: if (sched_proxy_exec() && current->blocked_donor) {
1013: /* force handoff if we have a blocked_donor */
1014: owner = MUTEX_FLAG_HANDOFF;
1015: break;
1016: }
1017:
1018: if (owner & MUTEX_FLAG_HANDOFF)
1019: break;
1020:
1021: if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, __owner_flags(owner))) {
1022: if (owner & MUTEX_FLAG_WAITERS)
1023: break;
1024:
1025: return;
1026: }
1027: }
1028:
1029: raw_spin_lock_irqsave(&lock->wait_lock, flags);
1030: raw_spin_lock(¤t->blocked_lock);
1031: debug_mutex_unlock(lock);
1032:
1033: if (sched_proxy_exec()) {
1034: /*
1035: * If we have a task boosting current, and that task was boosting
1036: * current through this lock, hand the lock to that task, as that
1037: * is the highest waiter, as selected by the scheduling function.
1038: */
1039: donor = current->blocked_donor;
]
|
| 44/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 34623
output: 40
thoughts: 1662
Thoughts: **Analyzing a Potential Race Condition in RDMA Connection Management**
Okay, here's what's running through my head. I'm looking at this code, specifically lines 1001-1002 and 1021 in the RDMA connection manager (cma) code, and I see a potential race condition. The code attempts to release a lock before potentially taking a spinlock to avoid blocking other contenders. However, under the `HANDOFF` condition, it *should not* clear the `owner` field but set it to the top waiter.
Line 1021 is where things get interesting. `atomic_long_try_cmpxchg_release` *clears* `lock->owner`. My thought is that if another task (e.g., task 9270 waiting for `handler_mutex` in `rdma_destroy_id`) is waiting, and the condition `owner & MUTEX_FLAG_WAITERS` is true, the code breaks out of the loop. Now, the waiter (task 9270) wakes up because `lock->owner` is cleared and it *acquires* `handler_mutex`. This all makes sense so far.
Task 9270 then runs `destroy_id_handler_unlock(id_priv)`. It sets `id_priv->state = RDMA_CM_DESTROYING`, calls `mutex_unlock(&id_priv->handler_mutex)`, then calls `_destroy_id(id_priv, ...)` and finally it runs `kfree(id_priv)`. So, task 9270 frees `id_priv`! While all of this is happening, another task (Task 1164, the unlocker) might still be preempted or at line 1029: `raw_spin_lock_irqsave(&lock->wait_lock, flags);`. The problem is that the unlocker might then call `debug_mutex_unlock(lock)` that reads `lock->magic` which is inside `id_priv->handler_mutex` WHICH HAS ALREADY BEEN FREED by Task 9270!
So, the question is: is this the intended behavior or is the mutex *not* supposed to be freed while being unlocked? Or is it that `rdma_destroy_id` should wait for `addr_handler` to finish?
Let's check if `rdma_destroy_id` actually *does* wait for `addr_handler`. I need to dive into `_destroy_id` to figure out what's going on.
Okay, here's `_destroy_id`:
```c
static void _destroy_id(struct rdma_id_private *id_priv,
enum rdma_cm_state state)
{
cma_cancel_operation(id_priv, state);
rdma_restrack_del(&id_priv->res);
cma_remove_id_from_tree(id_priv);
if (id_priv->cma_dev) {
...
}
cma_release_port(id_priv);
cma_id_put(id_priv);
wait_for_completion(&id_priv->comp);
...
kfree(id_priv);
}
```
Wait a second! Look at `cma_cancel_operation(id_priv, state);`
What `state` was passed to `_destroy_id`? Let's look at `destroy_id_handler_unlock`:
```c
lockdep_assert_held(&id_priv->handler_mutex);
spin_lock_irqsave(&id_priv->lock, flags);
state = id_priv->state;
id_priv->state = RDMA_CM_DESTROYING;
spin_unlock_irqrestore(&id_priv->lock, flags);
mutex_unlock(&id_priv->handler_mutex);
_destroy_id(id_priv, state);
```
Okay, when `rdma_destroy_id` ran, what *was* `id_priv->state`? Remember `addr_handler` ran:
```c
mutex_lock(&id_priv->handler_mutex);
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
RDMA_CM_ADDR_RESOLVED))
goto out;
```
Aha! `cma_comp_exch` changed `id_priv->state` from `RDMA_CM_ADDR_
|
| 45/2 |
2026/10/04 00:54 |
tool |
grepper |
0m
Args: map[Expression:rdma_resolve_ip PathPrefixes:[drivers/infiniband/core/cma.c]]
Results: map[Output:drivers/infiniband/core/cma.c=4137=int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
--
drivers/infiniband/core/cma.c-4155- * The FSM can return back to RDMA_CM_ADDR_BOUND after
drivers/infiniband/core/cma.c:4156: * rdma_resolve_ip() is called, eg through the error
drivers/infiniband/core/cma.c-4157- * path in addr_handler(). If this happens the existing
--
drivers/infiniband/core/cma.c-4162- * state since this is the only cancel as it is
drivers/infiniband/core/cma.c:4163: * immediately before rdma_resolve_ip().
drivers/infiniband/core/cma.c-4164- */
--
drivers/infiniband/core/cma.c-4168- id_priv->used_resolve_ip = 1;
drivers/infiniband/core/cma.c:4169: ret = rdma_resolve_ip(cma_src_addr(id_priv), dst_addr,
drivers/infiniband/core/cma.c-4170- &id->route.addr.dev_addr,
]
|
| 46/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 37717
output: 42
thoughts: 33
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Diving into `cma.c` - Potential Issue in Sight?**
Alright, I'm thinking we need to drill down into `drivers/infiniband/core/cma.c`. Specifically, my internal radar is pinging around lines 4137 to 4185. I'm guessing something in that chunk of code β likely related to connection management agent (CMA) operations β has caught my eye. Perhaps a recent bug report, a performance anomaly, or a hunch based on recent changes has led me to this specific location. I want to zero in on that section and see what's going on. This could be anything from a subtle race condition to an inefficient resource allocation, or maybe just a sanity check needed. Time to put on the detective hat and start digging.
|
| 47/2 |
2026/10/04 00:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/cma.c FirstLine:4137 LineCount:50]
Results: map[Contents:4137: int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
4138: const struct sockaddr *dst_addr, unsigned long timeout_ms)
4139: {
4140: struct rdma_id_private *id_priv =
4141: container_of(id, struct rdma_id_private, id);
4142: int ret;
4143:
4144: ret = resolve_prepare_src(id_priv, src_addr, dst_addr);
4145: if (ret)
4146: return ret;
4147:
4148: if (cma_any_addr(dst_addr)) {
4149: ret = cma_resolve_loopback(id_priv);
4150: } else {
4151: if (dst_addr->sa_family == AF_IB) {
4152: ret = cma_resolve_ib_addr(id_priv);
4153: } else {
4154: /*
4155: * The FSM can return back to RDMA_CM_ADDR_BOUND after
4156: * rdma_resolve_ip() is called, eg through the error
4157: * path in addr_handler(). If this happens the existing
4158: * request must be canceled before issuing a new one.
4159: * Since canceling a request is a bit slow and this
4160: * oddball path is rare, keep track once a request has
4161: * been issued. The track turns out to be a permanent
4162: * state since this is the only cancel as it is
4163: * immediately before rdma_resolve_ip().
4164: */
4165: if (id_priv->used_resolve_ip)
4166: rdma_addr_cancel(&id->route.addr.dev_addr);
4167: else
4168: id_priv->used_resolve_ip = 1;
4169: ret = rdma_resolve_ip(cma_src_addr(id_priv), dst_addr,
4170: &id->route.addr.dev_addr,
4171: timeout_ms, addr_handler,
4172: false, id_priv);
4173: }
4174: }
4175: if (ret)
4176: goto err;
4177:
4178: return 0;
4179: err:
4180: cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, RDMA_CM_ADDR_BOUND);
4181: return ret;
4182: }
4183: EXPORT_SYMBOL(rdma_resolve_addr);
4184:
4185: int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type)
4186: {
]
|
| 48/2 |
2026/10/04 00:54 |
llm |
expert |
0m
Model:
Tokens:
input: 38810
output: 33
thoughts: 74
Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing as an expert in this area:
**Unpacking a Potential RDMA Vulnerability**
Alright, this jumps out at me immediately. We're calling `rdma_resolve_ip()` with `id_priv` but *without* bumping its refcount. That's a classic recipe for a use-after-free situation, or at least a race condition, depending on how `id_priv` is managed elsewhere. This could be exploitable! Let me jot that down as a critical point to investigate.
Now, where do we go from here? We need to understand the lifecycle of `id_priv` and see what might be happening with its lifetime as it relates to this call. Let's see if we can find other relevant usages of that parameter.
Let me dig into the git log. I need to search for a few key things that might be in the commit messages or code changes. I'm going to look specifically for any commits related to `cma_cancel_operation` or anything touching the `addr_handler` itself. Also, `rdma_addr_cancel` is worth looking at as well. And, to be extra thorough, `used_resolve_ip` will show how this code is being utilized. These terms are all very important for identifying the possible locations where the reference counting is or isn't being handled correctly. That search should quickly reveal any related fixes, regressions, or, hopefully, existing defenses in place. The devil, as always, is in the details, so let's see what the log reveals!
|
| 49/2 |
2026/10/04 00:54 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:only RDMA_CM_ADDR_QUERY has a work Count:5]
Results:
|
| 50/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 39295
output: 52
thoughts: 28
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Adding Context to the InfiniBand CMA Investigation**
Alright, I'm thinking, "Let's refine this git log search, let's zero in a little more." The broader searches are turning up too much noise, so I need to be more precise. It's time to focus this investigation on the Connection Manager (CMA) within the InfiniBand core driver, particularly the `cma.c` file. Including `PathPrefix="drivers/infiniband/core/cma.c"` in the `git log` command will significantly narrow the scope. This will ensure that I'm only looking at commits directly impacting the CMA functionality β which is where I suspect the problem lies. With this path restriction, the log will only return relevant results concerning changes to that particular component, effectively filtering out anything that wouldn't directly impact the Connection Manager. It's a targeted approach to isolate the code modifications that could be influencing the current behavior.
|
| 51/2 |
2026/10/04 01:05 |
tool |
git-log |
0m
Args: map[CodeRegexp:only RDMA_CM_ADDR_QUERY has a work Count:5 PathPrefix:drivers/infiniband/core/cma.c]
Results: map[Output:305d568b72f1 RDMA/cma: Ensure rdma_addr_cancel() happens before issuing more requests
]
|
| 52/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 39647
output: 27
thoughts: 21
Thoughts: Okay, here's my interpretation of that prompt, and my response:
**Examining Commit 305d568b72f1**
Alright, let's dive into commit `305d568b72f1`. I need to understand what changed here. Given my expertise, I'm already formulating hypotheses about the likely modifications based on the context of the codebase and recent activity. Is this a bug fix? Feature implementation? Refactoring? Optimization? The commit message should give some clues, but I'm not going to rely on that solely; I'll need to look at the diff. I'm preparing myself to filter out the noise β comments, whitespace changes, minor style adjustments β and zero in on the core logic alterations. What are the key lines, the critical changes that really matter? Iβm looking for any patterns β are we seeing the addition of new data structures, alterations to existing algorithms, changes in control flow? Are dependencies introduced or removed? I'll probably start with the most likely files to have been modified and build up from there, keeping in mind how it impacts the other code. I'm ready to evaluate its impact on performance, code maintainability and overall stability. Let's see what we've got.
|
| 53/2 |
2026/10/04 01:05 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 305d568b72f17f674155a2a8275f865f207b3808
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date: Thu Sep 16 15:34:46 2021 -0300
RDMA/cma: Ensure rdma_addr_cancel() happens before issuing more requests
The FSM can run in a circle allowing rdma_resolve_ip() to be called twice
on the same id_priv. While this cannot happen without going through the
work, it violates the invariant that the same address resolution
background request cannot be active twice.
CPU 1 CPU 2
rdma_resolve_addr():
RDMA_CM_IDLE -> RDMA_CM_ADDR_QUERY
rdma_resolve_ip(addr_handler) #1
process_one_req(): for #1
addr_handler():
RDMA_CM_ADDR_QUERY -> RDMA_CM_ADDR_BOUND
mutex_unlock(&id_priv->handler_mutex);
[.. handler still running ..]
rdma_resolve_addr():
RDMA_CM_ADDR_BOUND -> RDMA_CM_ADDR_QUERY
rdma_resolve_ip(addr_handler)
!! two requests are now on the req_list
rdma_destroy_id():
destroy_id_handler_unlock():
_destroy_id():
cma_cancel_operation():
rdma_addr_cancel()
// process_one_req() self removes it
spin_lock_bh(&lock);
cancel_delayed_work(&req->work);
if (!list_empty(&req->list)) == true
! rdma_addr_cancel() returns after process_on_req #1 is done
kfree(id_priv)
process_one_req(): for #2
addr_handler():
mutex_lock(&id_priv->handler_mutex);
!! Use after free on id_priv
rdma_addr_cancel() expects there to be one req on the list and only
cancels the first one. The self-removal behavior of the work only happens
after the handler has returned. This yields a situations where the
req_list can have two reqs for the same "handle" but rdma_addr_cancel()
only cancels the first one.
The second req remains active beyond rdma_destroy_id() and will
use-after-free id_priv once it inevitably triggers.
Fix this by remembering if the id_priv has called rdma_resolve_ip() and
always cancel before calling it again. This ensures the req_list never
gets more than one item in it and doesn't cost anything in the normal flow
that never uses this strange error path.
Link: https://lore.kernel.org/r/0-v1-3bc675b8006d+22-syz_cancel_uaf_jgg@nvidia.com
Cc: stable@vger.kernel.org
Fixes: e51060f08a61 ("IB: IP address based RDMA connection manager")
Reported-by: syzbot+dc3dfba010d7671e05f5@syzkaller.appspotmail.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 8862b0e572f0..704ce595542c 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1783,6 +1783,14 @@ static void cma_cancel_operation(struct rdma_id_private *id_priv,
{
switch (state) {
case RDMA_CM_ADDR_QUERY:
+ /*
+ * We can avoid doing the rdma_addr_cancel() based on state,
+ * only RDMA_CM_ADDR_QUERY has a work that could still execute.
+ * Notice that the addr_handler work could still be exiting
+ * outside this state, however due to the interaction with the
+ * handler_mutex the work is guaranteed not to touch id_priv
+ * during exit.
+ */
rdma_addr_cancel(&id_priv->id.route.addr.dev_addr);
break;
case RDMA_CM_ROUTE_QUERY:
@@ -3425,6 +3433,21 @@ int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
if (dst_addr->sa_family == AF_IB) {
ret = cma_resolve_ib_addr(id_priv);
} else {
+ /*
+ * The FSM can return back to RDMA_CM_ADDR_BOUND after
+ * rdma_resolve_ip() is called, eg through the error
+ * path in addr_handler(). If this happens the existing
+ * request must be canceled before issuing a new one.
+ * Since canceling a request is a bit slow and this
+ * oddball path is rare, keep track once a request has
+ * been issued. The track turns out to be a permanent
+ * state since this is the only cancel as it is
+ * immediately before rdma_resolve_ip().
+ */
+ if (id_priv->used_resolve_ip)
+ rdma_addr_cancel(&id->route.addr.dev_addr);
+ else
+ id_priv->used_resolve_ip = 1;
ret = rdma_resolve_ip(cma_src_addr(id_priv), dst_addr,
&id->route.addr.dev_addr,
timeout_ms, addr_handler,
diff --git a/drivers/infiniband/core/cma_priv.h b/drivers/infiniband/core/cma_priv.h
index 5c463da99845..f92f101ea981 100644
--- a/drivers/infiniband/core/cma_priv.h
+++ b/drivers/infiniband/core/cma_priv.h
@@ -91,6 +91,7 @@ struct rdma_id_private {
u8 afonly;
u8 timeout;
u8 min_rnr_timer;
+ u8 used_resolve_ip;
enum ib_gid_type gid_type;
/*
]
|
| 54/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 41669
output: 44
thoughts: 1627
Thoughts: **Race Condition Detected: Use-After-Free in RDMA Core**
Okay, so I've been digging into this, and I'm seeing a nasty race condition in the RDMA core. Jason Gunthorpe's explanation implied that the interaction with `handler_mutex` in `addr_handler` guarantees protection against use-after-free during exit. But, as we all know, assumptions are dangerous. Let me walk you through what's happening.
Basically, `addr_handler` is running and changes its state. It then tries to exit by calling `mutex_unlock(&id_priv->handler_mutex)`. Meanwhile, another task, let's say task 9270, calls `rdma_destroy_id`, which then calls `mutex_lock(&id_priv->handler_mutex)`. `rdma_destroy_id` is now waiting on the mutex.
Here's where it gets interesting: When `addr_handler` unlocks the mutex, it hits the slowpath because there's a waiter. This is where the race really starts. Before `addr_handler` can finish its unlocking process (specifically, before `__mutex_unlock_slowpath` fully completes), `rdma_destroy_id` *immediately* grabs the lock. Since `rdma_destroy_id` now has the lock, it goes on to call `destroy_id_handler_unlock`. In this function, it checks the state of the handler, sets it to `RDMA_CM_DESTROYING`, unlocks the mutex, and then, crucially, *calls `_destroy_id`*. Then, `kfree(id_priv)` gets called, freeing the `id_priv` structure.
But hold on! `addr_handler` is *still* inside `__mutex_unlock_slowpath`! It's still trying to access fields in `&id_priv->handler_mutex`, and this is where it crashes: it's trying to access the mutex structure (`lock->wait_lock` or `lock->magic`) *that has already been freed*! This is a textbook use-after-free detected by KASAN in `debug_mutex_unlock`.
I've double-checked all aspects of this. This bug report is definitely actionable: we've got three stack traces (allocation, free, and bad access). They all point to the same object type: `struct rdma_id_private`. The memory is allocated by `__rdma_create_id`, freed through a chain of calls from `ucma_close_id`, and accessed in `addr_handler`. The offset of the access exactly matches the location of the `handler_mutex.magic` field within the freed object. The leaf frames of the stacks are where we expect them to be (kernel locking code and RDMA core). The whole thing makes perfect sense and explains the race perfectly. The assumption about the `handler_mutex` guaranteeing protection during exit is fundamentally flawed. Specifically, we are accessing the mutex struct while it is about to be free'd by the waiter that just got unblocked. I should check the git log for other mentions of this issue, but I'm pretty certain we've got a solid fix candidate here.
|
| 55/2 |
2026/10/04 01:05 |
tool |
git-log |
0m
Args: map[CodeRegexp:handler_mutex Count:10 PathPrefix:drivers/infiniband/core/cma.c]
Results: map[Output:879424832d24 RDMA/core: let rdma_connect_locked() call lockdep_assert_held(&id_priv->handler_mutex)
925d046e7e52 RDMA/core: Add a netevent notifier to cma
305d568b72f1 RDMA/cma: Ensure rdma_addr_cancel() happens before issuing more requests
fe454dc31e84 RDMA/ucma: Fix use-after-free bug in ucma_create_uevent
071ba4cc559d RDMA: Add rdma_connect_locked()
7e85bcda8bfe RDMA/cma: Combine cma_ndev_work with cma_work
2a7cec538169 RDMA/cma: Fix locking for the RDMA_CM_CONNECT state
d114c6feedfe RDMA/cma: Add missing locking to rdma_accept()
f6a9d47ae685 RDMA/cma: Execute rdma_cm destruction from a handler properly
3647a28de1ad RDMA/cma: Using the standard locking pattern when delivering the removal event
]
|
| 56/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 44329
output: 30
thoughts: 34
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating a Code Context**
Okay, so I'm taking a look at this `destroy_id_handler_unlock` function. I remember seeing it mentioned in some recent discussions around locking mechanisms, and the commit `f6a9d47ae685` seems like a good place to start. I'm not diving in blindly, but I want to refresh my memory on the surrounding code, the reasoning behind that particular change, and how it relates to potential race conditions or synchronization issues. A quick check of that commit will give me the relevant code's immediate neighbors to inform my deeper analysis, and help me quickly grasp the scope of the change. This helps me avoid any surprises later.
|
| 57/2 |
2026/10/04 01:05 |
tool |
git-show |
0m
Args: map[Commit:f6a9d47ae685 Stat:true]
Results: map[Output:commit f6a9d47ae6854980fc4b1676f1fe9f9fa45ea4e2
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date: Thu Jul 23 10:07:07 2020 +0300
RDMA/cma: Execute rdma_cm destruction from a handler properly
When a rdma_cm_id needs to be destroyed after a handler callback fails,
part of the destruction pattern is open coded into each call site.
Unfortunately the blind assignment to state discards important information
needed to do cma_cancel_operation(). This results in active operations
being left running after rdma_destroy_id() completes, and the
use-after-free bugs from KASAN.
Consolidate this entire pattern into destroy_id_handler_unlock() and
manage the locking correctly. The state should be set to
RDMA_CM_DESTROYING under the handler_lock to atomically ensure no futher
handlers are called.
Link: https://lore.kernel.org/r/20200723070707.1771101-5-leon@kernel.org
Reported-by: syzbot+08092148130652a6faae@syzkaller.appspotmail.com
Reported-by: syzbot+a929647172775e335941@syzkaller.appspotmail.com
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/cma.c | 174 ++++++++++++++++++++----------------------
1 file changed, 84 insertions(+), 90 deletions(-)
]
|
| 58/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 45034
output: 15
thoughts: 35
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Seamless Integration & Actionable Insight**
Alright, this is exactly what I was hoping to see. The report is airtight; every piece fits perfectly. There are no gaps in the logic, and the conclusions follow directly from the evidence presented. This level of clarity and completeness is, frankly, impressive. Given the self-consistent nature of the results, it's a no-brainer. We have a clear path forward. I'm going to initiate the next phase immediately. Let's call `set-results` and set `Actionable: true`. No need to hesitate here; the data speaks for itself.
|
| 59/2 |
2026/10/04 01:05 |
tool |
set-results |
0m
Args:
Results:
|
| 60/2 |
2026/10/04 01:05 |
llm |
expert |
0m
Model:
Tokens:
input: 45242
output: 830
thoughts: 592
Thoughts: **Bug Report Analysis: UAF Read in RDMA Driver**
Okay, let's break this down. The bug report is fantastic; it's got *all* the necessary ingredients: a memory access (UAF read), an allocation, and a free. And they're all linked to the same kernel object: `struct rdma_id_private`. This is the core of the issue.
The allocation happens in `kmalloc-2k`, courtesy of `__rdma_create_id` which is itself called via `ucma_create_id`. Got it. Now for the crucial parts. The free is triggered by task 9270 calling `ucma_close`, which leads down the rabbit hole to `kfree(id_priv)`. Clear.
The UAF *read* is coming from worker thread 1164, specifically within `process_one_req`, when `addr_handler` calls `mutex_unlock(&id_priv->handler_mutex)`. This then moves into `__mutex_unlock_slowpath` and finally lands in `debug_mutex_unlock`. We have the call stack. Perfect.
Now, for the juicy details: the exact offset and address. The UAF read is an 8-byte access at offset 1048 (0x418) within a 2048-byte object. Looking at the `struct rdma_id_private`, the `handler_mutex` starts at offset 960 (0x3c0). And in a `struct mutex` (with `CONFIG_DEBUG_MUTEXES` enabled), the `magic` field is at offset 88. Aha! 960 + 88 = 1048. It *precisely* matches the `lock->magic` check in `debug_mutex_unlock()`. This confirms the read targets a field of the mutex within the structure.
So, how does the race work? While `addr_handler` is releasing `id_priv->handler_mutex` in `mutex_unlock()`, `__mutex_unlock_slowpath` is busy clearing the mutex owner. This clearing is using `atomic_long_try_cmpxchg_release`. This is the window. This allows the waiting task in `rdma_destroy_id` to grab the `handler_mutex`, proceed to `_destroy_id`, and `kfree(id_priv)`. The timing is critical.
Because `addr_handler` had updated the state before releasing the mutex, `cma_cancel_operation` did not call `rdma_addr_cancel` or wait for `process_one_req`. This adds to the race condition.
Thus, the unlocker (thread 1164) continues executing in `__mutex_unlock_slowpath` and attempts to access `lock->magic` in `debug_mutex_unlock()`, *after* `id_priv` has been freed. The report checks out completely. This is a classic UAF scenario caused by a race condition during mutex release. Itβs consistent, complete, and very actionable. I have all the information I need to proceed.
|
| 61/1 |
2026/10/04 01:05 |
action |
format-explanation |
0m
Results: map[Explanation:The bug report is **actionable** and **self-consistent**.
### Analysis:
1. **Stack traces and object identification:**
- **All 3 required stack traces are present**: the invalid access stack, the
allocation stack, and the free stack.
- **Target object**: All 3 traces operate on the same object, `struct
rdma_id_private` (in the `kmalloc-2k` slab cache), located in the RDMA
subsystem (`drivers/infiniband/core/`).
- **Allocation**: The object was allocated in `__rdma_create_id()`
(`drivers/infiniband/core/cma.c:1016`) via `ucma_create_id()`.
- **Free**: The object was freed in `_destroy_id()` via `rdma_destroy_id()`
called from `ucma_close_id()` (`drivers/infiniband/core/ucma.c:188`).
- **Invalid access**: The use-after-free read occurred in
`debug_mutex_unlock()` (`kernel/locking/mutex-debug.c:74`), invoked by
`mutex_unlock(&id_priv->handler_mutex)` in `addr_handler()`
(`drivers/infiniband/core/cma.c:3555`), which was running as a work item in
`process_one_req()` (`drivers/infiniband/core/addr.c:624`).
2. **Offset and field matching:**
- The reported read is 8 bytes at offset 1048 (0x418) inside the freed
2048-byte region.
- In `struct rdma_id_private`, the `handler_mutex` field starts at offset 960
(0x3c0) bytes.
- In `struct mutex` (with `CONFIG_DEBUG_MUTEXES`), `lock->magic` is located
at offset 88 (0x58) bytes.
- `960 + 88 = 1048` bytes, which matches the exact byte offset accessed by
`DEBUG_LOCKS_WARN_ON(lock->magic != lock);` in `debug_mutex_unlock()`.
3. **Root cause and race condition:**
- An address resolution callback `addr_handler` was executing on a worker
thread. In `addr_handler()`, the state is transitioned from
`RDMA_CM_ADDR_QUERY` to `RDMA_CM_ADDR_RESOLVED` while holding
`id_priv->handler_mutex`.
- When `addr_handler()` unlocks `id_priv->handler_mutex`,
`__mutex_unlock_slowpath()` clears `lock->owner` via
`atomic_long_try_cmpxchg_release()`.
- Another thread in `ucma_close` / `rdma_destroy_id` was waiting on
`id_priv->handler_mutex`. As soon as ownership was cleared, it acquired the
mutex, set `id_priv->state = RDMA_CM_DESTROYING`, unlocked `handler_mutex`,
and proceeded to `_destroy_id()`.
- Because the state was already past `RDMA_CM_ADDR_QUERY`,
`cma_cancel_operation()` did not invoke `rdma_addr_cancel()` to synchronously
wait for the work item. Consequently, `_destroy_id()` finished and freed
`id_priv` with `kfree(id_priv)`.
- The unlocking worker thread in `addr_handler()` was still executing
`__mutex_unlock_slowpath()` and subsequently accessed `lock->magic` in
`debug_mutex_unlock()` on the already-freed `id_priv->handler_mutex`.]
|