| 0/0 |
2026/10/17 00:56 |
flow |
assessment-security |
53m
Results: map[DenialOfService:true Explanation:### Root Cause Analysis
The bug is a race condition leading to a slab use-after-free on `struct
TCP_Server_Info` (`server`, allocated in `kmalloc-4k`) between
`cifs_put_tcp_session()` and `cifs_demultiplex_thread()`.
In `cifs_put_tcp_session()` (`fs/smb/client/connect.c`):
```c
spin_lock(&server->srv_lock);
server->tcpStatus = CifsExiting;
spin_unlock(&server->srv_lock);
cifs_crypto_secmech_release(server);
kfree_sensitive(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
task = xchg(&server->tsk, NULL);
if (task)
send_sig(SIGKILL, task, 1);
```
Meanwhile, `cifs_demultiplex_thread()` loops while `server->tcpStatus !=
CifsExiting`:
```c
while (server->tcpStatus != CifsExiting) {
...
}
...
task_to_wake = xchg(&server->tsk, NULL);
clean_demultiplex_info(server);
```
Inside `clean_demultiplex_info(server)`, `kfree_sensitive(server)` is called to
free the `struct TCP_Server_Info` object.
Because `cifs_put_tcp_session()` sets `server->tcpStatus = CifsExiting` *before*
releasing `server->secmech`, freeing `server->session_key.response`, and
performing `xchg(&server->tsk, NULL)`, if the task running
`cifs_put_tcp_session()` is preempted or delayed after setting `CifsExiting`,
`cifs_demultiplex_thread()` can observe `server->tcpStatus == CifsExiting`, exit
its main loop, and call `clean_demultiplex_info(server)` to free `server`. When
`cifs_put_tcp_session()` resumes, it performs UAF reads and writes on the freed
`server` structure:
1. `cifs_crypto_secmech_release(server)` reads `server->secmech.enc` and
`server->secmech.dec`, passing them to `crypto_free_aead()` if non-NULL and
writing `NULL` to those fields.
2. `kfree_sensitive(server->session_key.response)` reads
`server->session_key.response` and frees it, followed by writing `NULL` and `0`
to `server->session_key.response` and `server->session_key.len`.
3. `task = xchg(&server->tsk, NULL)` atomically exchanges `server->tsk` with
`NULL` and passes any non-NULL pointer to `send_sig(SIGKILL, task, 1)`.
### Security Impact Assessment
- **Exploitable (`true`) & Denial of Service (`true`)**: The bug is a
Use-After-Free on a `kmalloc-4k` object involving both UAF writes (zeroing
fields and atomic `xchg`) and UAF pointer reads passed directly to
`crypto_free_aead()`, `kfree_sensitive()`, and `send_sig()`. If the `kmalloc-4k`
slot is reallocated prior to `cifs_put_tcp_session()` resuming, this causes
arbitrary kernel memory free/corruption and kernel panic.
- **Accessible From Unprivileged Processes (`false`) & User Namespaces
(`false`)**: Reaching `cifs_mount()` / `cifs_put_tcp_session()` requires
mounting a `cifs` or `smb3` filesystem. Neither `cifs_fs_type` nor
`smb3_fs_type` sets `FS_USERNS_MOUNT` in `.fs_flags`, so `mount_capable()`
requires `capable(CAP_SYS_ADMIN)` in the initial user namespace.
- **Network / Remote / Filesystem / VM / Peripheral Triggers (`false`)**:
Triggering the bug requires a privileged local mount operation (`CAP_SYS_ADMIN`)
of a CIFS/SMB3 network share rather than parsing a disk filesystem image or
handling unsolicited ingress network/peripheral traffic. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/10/17 00:56 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/10/17 00:56 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/903fa56bfd5a2dda1795deaeecd1dbdb6fb235f7]
|
| 3/1 |
2026/10/17 00:56 |
action |
kernel-builder |
29m
Results: map[KernelObj:/app/workdir/cache/build/9e6d221531cf0cb8b0f30b2d21e8503d79fff705]
|
| 4/1 |
2026/10/17 01:26 |
action |
codesearch-prepare |
19m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/10/17 01:46 |
agent |
expert |
3m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
CIFS: VFS: \\172.20.20.170 Error -512 sending data on socket to server
==================================================================
BUG: KASAN: slab-use-after-free in cifs_crypto_secmech_release+0xed/0x120 fs/smb/client/cifsencrypt.c:512
Read of size 8 at addr ffff8880526ec490 by task syz.3.92/6393
CPU: 1 UID: 0 PID: 6393 Comm: syz.3.92 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/05/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
cifs_crypto_secmech_release+0xed/0x120 fs/smb/client/cifsencrypt.c:512
cifs_put_tcp_session+0x240/0x3e0 fs/smb/client/connect.c:1740
cifs_mount_put_conns+0x2b3/0x340 fs/smb/client/connect.c:3554
cifs_mount+0x4ac/0xdb0 fs/smb/client/connect.c:3912
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f35d7b9e559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f35d5de0028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f35d7e26180 RCX: 00007f35d7b9e559
RDX: 0000200000000300 RSI: 0000200000000100 RDI: 0000200000000200
RBP: 00007f35d7c358b0 R08: 0000200000000400 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f35d7e26218 R14: 00007f35d7e26180 R15: 00007ffce1bc0ac8
</TASK>
Allocated by task 6393:
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:409 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:426
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2f8/0x6d0 mm/slub.c:5563
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6394:
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:264 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:296
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2748 [inline]
slab_free mm/slub.c:6509 [inline]
kfree+0x22b/0x6d0 mm/slub.c:6802
clean_demultiplex_info+0x997/0xe90 fs/smb/client/connect.c:1153
cifs_demultiplex_thread+0x5b5/0x2ea0 fs/smb/client/connect.c:1446
kthread+0x373/0x450 kernel/kthread.c:436
ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff8880526ec000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1168 bytes inside of
freed 4096-byte region [ffff8880526ec000, ffff8880526ed000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x526e8
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 ffff88801d035140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801d035140 dead000000000100 dead000000000122
head: 0000000000000000 0000000000040004 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 6393, tgid 6385 (syz.3.92), ts 190011878541
set_page_owner include/linux/page_owner.h:33 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1871
prep_new_page mm/page_alloc.c:1879 [inline]
get_page_from_freelist+0x110d/0x35d0 mm/page_alloc.c:3943
__alloc_frozen_pages_noprof+0x2eb/0x3300 mm/page_alloc.c:5436
alloc_slab_page mm/slub.c:3347 [inline]
allocate_slab mm/slub.c:3462 [inline]
new_slab+0xa9/0x6e0 mm/slub.c:3513
refill_objects+0xe3/0x410 mm/slub.c:7418
refill_sheaf mm/slub.c:2885 [inline]
__pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774
alloc_from_pcs mm/slub.c:4850 [inline]
slab_alloc_node mm/slub.c:4984 [inline]
__kmalloc_cache_noprof+0x4f4/0x6d0 mm/slub.c:5559
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
page last free pid 6391 tgid 6385 ts 189990448004 stack trace:
reset_page_owner include/linux/page_owner.h:26 [inline]
__free_pages_prepare mm/page_alloc.c:1418 [inline]
__free_frozen_pages+0x79f/0x10f0 mm/page_alloc.c:2962
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:361
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4683 [inline]
kmem_cache_alloc_bulk_noprof+0x352/0x890 mm/slub.c:7543
__io_alloc_req_refill+0x9e/0x330 io_uring/io_uring.c:981
io_alloc_req io_uring/io_uring.h:537 [inline]
io_submit_sqes.cold+0xf6/0x301 io_uring/io_uring.c:2039
__do_sys_io_uring_enter+0xa88/0x1b10 io_uring/io_uring.c:2640
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880526ec380: fb fb fb fb fb fb fb f
ffff8880526ec380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880526ec480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880526ec500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
==================================================================
BUG: KASAN: slab-use-after-free in cifs_crypto_secmech_release+0xfa/0x120 fs/smb/client/cifsencrypt.c:516
Read of size 8 at addr ffff8880526ec498 by task syz.3.92/6393
CPU: 1 UID: 0 PID: 6393 Comm: syz.3.92 Tainted: G B syzkaller #0 PREEMPT(full)
Tainted: [B]=BAD_PAGE
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/05/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
cifs_crypto_secmech_release+0xfa/0x120 fs/smb/client/cifsencrypt.c:516
cifs_put_tcp_session+0x240/0x3e0 fs/smb/client/connect.c:1740
cifs_mount_put_conns+0x2b3/0x340 fs/smb/client/connect.c:3554
cifs_mount+0x4ac/0xdb0 fs/smb/client/connect.c:3912
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f35d7b9e559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f35d5de0028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f35d7e26180 RCX: 00007f35d7b9e559
RDX: 0000200000000300 RSI: 0000200000000100 RDI: 0000200000000200
RBP: 00007f35d7c358b0 R08: 0000200000000400 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f35d7e26218 R14: 00007f35d7e26180 R15: 00007ffce1bc0ac8
</TASK>
Allocated by task 6393:
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:409 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:426
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2f8/0x6d0 mm/slub.c:5563
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6394:
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:264 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:296
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2748 [inline]
slab_free mm/slub.c:6509 [inline]
kfree+0x22b/0x6d0 mm/slub.c:6802
clean_demultiplex_info+0x997/0xe90 fs/smb/client/connect.c:1153
cifs_demultiplex_thread+0x5b5/0x2ea0 fs/smb/client/connect.c:1446
kthread+0x373/0x450 kernel/kthread.c:436
ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff8880526ec000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1176 bytes inside of
freed 4096-byte region [ffff8880526ec000, ffff8880526ed000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x526e8
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 ffff88801d035140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801d035140 dead000000000100 dead000000000122
head: 0000000000000000 0000000000040004 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 6393, tgid 6385 (syz.3.92), ts 190011878541
set_page_owner include/linux/page_owner.h:33 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1871
prep_new_page mm/page_alloc.c:1879 [inline]
get_page_from_freelist+0x110d/0x35d0 mm/page_alloc.c:3943
__alloc_frozen_pages_noprof+0x2eb/0x3300 mm/page_alloc.c:5436
alloc_slab_page mm/slub.c:3347 [inline]
allocate_slab mm/slub.c:3462 [inline]
new_slab+0xa9/0x6e0 mm/slub.c:3513
refill_objects+0xe3/0x410 mm/slub.c:7418
refill_sheaf mm/slub.c:2885 [inline]
__pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774
alloc_from_pcs mm/slub.c:4850 [inline]
slab_alloc_node mm/slub.c:4984 [inline]
__kmalloc_cache_noprof+0x4f4/0x6d0 mm/slub.c:5559
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
page last free pid 6391 tgid 6385 ts 189990448004 stack trace:
reset_page_owner include/linux/page_owner.h:26 [inline]
__free_pages_prepare mm/page_alloc.c:1418 [inline]
__free_frozen_pages+0x79f/0x10f0 mm/page_alloc.c:2962
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:361
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4683 [inline]
kmem_cache_alloc_bulk_noprof+0x352/0x890 mm/slub.c:7543
__io_alloc_req_refill+0x9e/0x330 io_uring/io_uring.c:981
io_alloc_req io_uring/io_uring.h:537 [inline]
io_submit_sqes.cold+0xf6/0x301 io_uring/io_uring.c:2039
__do_sys_io_uring_enter+0xa88/0x1b10 io_uring/io_uring.c:2640
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880526ec380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880526ec480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880526ec500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
==================================================================
BUG: KASAN: slab-use-after-free in cifs_put_tcp_session+0x374/0x3e0 fs/smb/client/connect.c:1742
Read of size 8 at addr ffff8880526ec470 by task syz.3.92/6393
CPU: 1 UID: 0 PID: 6393 Comm: syz.3.92 Tainted: G B syzkaller #0 PREEMPT(full)
Tainted: [B]=BAD_PAGE
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/05/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
cifs_put_tcp_session+0x374/0x3e0 fs/smb/client/connect.c:1742
cifs_mount_put_conns+0x2b3/0x340 fs/smb/client/connect.c:3554
cifs_mount+0x4ac/0xdb0 fs/smb/client/connect.c:3912
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f35d7b9e559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f35d5de0028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f35d7e26180 RCX: 00007f35d7b9e559
RDX: 0000200000000300 RSI: 0000200000000100 RDI: 0000200000000200
RBP: 00007f35d7c358b0 R08: 0000200000000400 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f35d7e26218 R14: 00007f35d7e26180 R15: 00007ffce1bc0ac8
</TASK>
Allocated by task 6393:
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:409 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:426
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2f8/0x6d0 mm/slub.c:5563
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6394:
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:264 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:296
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2748 [inline]
slab_free mm/slub.c:6509 [inline]
kfree+0x22b/0x6d0 mm/slub.c:6802
clean_demultiplex_info+0x997/0xe90 fs/smb/client/connect.c:1153
cifs_demultiplex_thread+0x5b5/0x2ea0 fs/smb/client/connect.c:1446
kthread+0x373/0x450 kernel/kthread.c:436
ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff8880526ec000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1136 bytes inside of
freed 4096-byte region [ffff8880526ec000, ffff8880526ed000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x526e8
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 ffff88801d035140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801d035140 dead000000000100 dead000000000122
head: 0000000000000000 0000000000040004 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 6393, tgid 6385 (syz.3.92), ts 190011878541
set_page_owner include/linux/page_owner.h:33 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1871
prep_new_page mm/page_alloc.c:1879 [inline]
get_page_from_freelist+0x110d/0x35d0 mm/page_alloc.c:3943
__alloc_frozen_pages_noprof+0x2eb/0x3300 mm/page_alloc.c:5436
alloc_slab_page mm/slub.c:3347 [inline]
allocate_slab mm/slub.c:3462 [inline]
new_slab+0xa9/0x6e0 mm/slub.c:3513
refill_objects+0xe3/0x410 mm/slub.c:7418
refill_sheaf mm/slub.c:2885 [inline]
__pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774
alloc_from_pcs mm/slub.c:4850 [inline]
slab_alloc_node mm/slub.c:4984 [inline]
__kmalloc_cache_noprof+0x4f4/0x6d0 mm/slub.c:5559
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
page last free pid 6391 tgid 6385 ts 189990448004 stack trace:
reset_page_owner include/linux/page_owner.h:26 [inline]
__free_pages_prepare mm/page_alloc.c:1418 [inline]
__free_frozen_pages+0x79f/0x10f0 mm/page_alloc.c:2962
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:361
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4683 [inline]
kmem_cache_alloc_bulk_noprof+0x352/0x890 mm/slub.c:7543
__io_alloc_req_refill+0x9e/0x330 io_uring/io_uring.c:981
io_alloc_req io_uring/io_uring.h:537 [inline]
io_submit_sqes.cold+0xf6/0x301 io_uring/io_uring.c:2039
__do_sys_io_uring_enter+0xa88/0x1b10 io_uring/io_uring.c:2640
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880526ec300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880526ec400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880526ec480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
==================================================================
BUG: KASAN: slab-use-after-free in cifs_put_tcp_session+0x381/0x3e0 fs/smb/client/connect.c:1743
Write of size 8 at addr ffff8880526ec470 by task syz.3.92/6393
CPU: 1 UID: 0 PID: 6393 Comm: syz.3.92 Tainted: G B syzkaller #0 PREEMPT(full)
Tainted: [B]=BAD_PAGE
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/05/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
cifs_put_tcp_session+0x381/0x3e0 fs/smb/client/connect.c:1743
cifs_mount_put_conns+0x2b3/0x340 fs/smb/client/connect.c:3554
cifs_mount+0x4ac/0xdb0 fs/smb/client/connect.c:3912
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f35d7b9e559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f35d5de0028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f35d7e26180 RCX: 00007f35d7b9e559
RDX: 0000200000000300 RSI: 0000200000000100 RDI: 0000200000000200
RBP: 00007f35d7c358b0 R08: 0000200000000400 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f35d7e26218 R14: 00007f35d7e26180 R15: 00007ffce1bc0ac8
</TASK>
Allocated by task 6393:
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:409 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:426
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2f8/0x6d0 mm/slub.c:5563
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6394:
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:264 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:296
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2748 [inline]
slab_free mm/slub.c:6509 [inline]
kfree+0x22b/0x6d0 mm/slub.c:6802
clean_demultiplex_info+0x997/0xe90 fs/smb/client/connect.c:1153
cifs_demultiplex_thread+0x5b5/0x2ea0 fs/smb/client/connect.c:1446
kthread+0x373/0x450 kernel/kthread.c:436
ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff8880526ec000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1136 bytes inside of
freed 4096-byte region [ffff8880526ec000, ffff8880526ed000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x526e8
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 ffff88801d035140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801d035140 dead000000000100 dead000000000122
head: 0000000000000000 0000000000040004 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 6393, tgid 6385 (syz.3.92), ts 190011878541
set_page_owner include/linux/page_owner.h:33 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1871
prep_new_page mm/page_alloc.c:1879 [inline]
get_page_from_freelist+0x110d/0x35d0 mm/page_alloc.c:3943
__alloc_frozen_pages_noprof+0x2eb/0x3300 mm/page_alloc.c:5436
alloc_slab_page mm/slub.c:3347 [inline]
allocate_slab mm/slub.c:3462 [inline]
new_slab+0xa9/0x6e0 mm/slub.c:3513
refill_objects+0xe3/0x410 mm/slub.c:7418
refill_sheaf mm/slub.c:2885 [inline]
__pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774
alloc_from_pcs mm/slub.c:4850 [inline]
slab_alloc_node mm/slub.c:4984 [inline]
__kmalloc_cache_noprof+0x4f4/0x6d0 mm/slub.c:5559
_kmalloc_noprof include/linux/slab.h:991 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
cifs_get_tcp_session+0x144/0x1f80 fs/smb/client/connect.c:1765
cifs_mount_get_session+0xc9/0x460 fs/smb/client/connect.c:3579
get_session fs/smb/client/dfs.c:65 [inline]
dfs_mount_share+0x200/0x1e20 fs/smb/client/dfs.c:275
cifs_mount+0xc4/0xdb0 fs/smb/client/connect.c:3869
cifs_smb3_do_mount+0x2c0/0x1b10 fs/smb/client/cifsfs.c:1026
smb3_get_tree_common fs/smb/client/fs_context.c:897 [inline]
smb3_get_tree fs/smb/client/fs_context.c:917 [inline]
smb3_get_tree+0x1fd/0x440 fs/smb/client/fs_context.c:909
vfs_get_tree+0x92/0x320 fs/super.c:1932
fc_mount fs/namespace.c:1278 [inline]
do_new_mount_fc fs/namespace.c:3885 [inline]
do_new_mount fs/namespace.c:3961 [inline]
path_mount+0x7d0/0x2850 fs/namespace.c:4312
do_mount fs/namespace.c:4325 [inline]
__do_sys_mount fs/namespace.c:4543 [inline]
__se_sys_mount fs/namespace.c:4520 [inline]
__x64_sys_mount+0x293/0x310 fs/namespace.c:4520
page last free pid 6391 tgid 6385 ts 189990448004 stack trace:
reset_page_owner include/linux/page_owner.h:26 [inline]
__free_pages_prepare mm/page_alloc.c:1418 [inline]
__free_frozen_pages+0x79f/0x10f0 mm/page_alloc.c:2962
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:361
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4683 [inline]
kmem_cache_alloc_bulk_noprof+0x352/0x890 mm/slub.c:7543
__io_alloc_req_refill+0x9e/0x330 io_uring/io_uring.c:981
io_alloc_req io_uring/io_uring.h:537 [inline]
io_submit_sqes.cold+0xf6/0x301 io_uring/io_uring.c:2039
__do_sys_io_uring_enter+0xa88/0x1b10 io_uring/io_uring.c:2640
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880526ec300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880526ec400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880526ec480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880526ec500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Reply: ### Root Cause Analysis
The bug is a race condition leading to a slab use-after-free on `struct TCP_Server_Info` (`server`, allocated in `kmalloc-4k`) between `cifs_put_tcp_session()` and `cifs_demultiplex_thread()`.
In `cifs_put_tcp_session()` (`fs/smb/client/connect.c`):
```c
spin_lock(&server->srv_lock);
server->tcpStatus = CifsExiting;
spin_unlock(&server->srv_lock);
cifs_crypto_secmech_release(server);
kfree_sensitive(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
task = xchg(&server->tsk, NULL);
if (task)
send_sig(SIGKILL, task, 1);
```
Meanwhile, `cifs_demultiplex_thread()` loops while `server->tcpStatus != CifsExiting`:
```c
while (server->tcpStatus != CifsExiting) {
...
}
...
task_to_wake = xchg(&server->tsk, NULL);
clean_demultiplex_info(server);
```
Inside `clean_demultiplex_info(server)`, `kfree_sensitive(server)` is called to free the `struct TCP_Server_Info` object.
Because `cifs_put_tcp_session()` sets `server->tcpStatus = CifsExiting` *before* releasing `server->secmech`, freeing `server->session_key.response`, and performing `xchg(&server->tsk, NULL)`, if the task running `cifs_put_tcp_session()` is preempted or delayed after setting `CifsExiting`, `cifs_demultiplex_thread()` can observe `server->tcpStatus == CifsExiting`, exit its main loop, and call `clean_demultiplex_info(server)` to free `server`. When `cifs_put_tcp_session()` resumes, it performs UAF reads and writes on the freed `server` structure:
1. `cifs_crypto_secmech_release(server)` reads `server->secmech.enc` and `server->secmech.dec`, passing them to `crypto_free_aead()` if non-NULL and writing `NULL` to those fields.
2. `kfree_sensitive(server->session_key.response)` reads `server->session_key.response` and frees it, followed by writing `NULL` and `0` to `server->session_key.response` and `server->session_key.len`.
3. `task = xchg(&server->tsk, NULL)` atomically exchanges `server->tsk` with `NULL` and passes any non-NULL pointer to `send_sig(SIGKILL, task, 1)`.
### Security Impact Assessment
- **Exploitable (`true`) & Denial of Service (`true`)**: The bug is a Use-After-Free on a `kmalloc-4k` object involving both UAF writes (zeroing fields and atomic `xchg`) and UAF pointer reads passed directly to `crypto_free_aead()`, `kfree_sensitive()`, and `send_sig()`. If the `kmalloc-4k` slot is reallocated prior to `cifs_put_tcp_session()` resuming, this causes arbitrary kernel memory free/corruption and kernel panic.
- **Accessible From Unprivileged Processes (`false`) & User Namespaces (`false`)**: Reaching `cifs_mount()` / `cifs_put_tcp_session()` requires mounting a `cifs` or `smb3` filesystem. Neither `cifs_fs_type` nor `smb3_fs_type` sets `FS_USERNS_MOUNT` in `.fs_flags`, so `mount_capable()` requires `capable(CAP_SYS_ADMIN)` in the initial user namespace.
- **Network / Remote / Filesystem / VM / Peripheral Triggers (`false`)**: Triggering the bug requires a privileged local mount operation (`CAP_SYS_ADMIN`) of a CIFS/SMB3 network share rather than parsing a disk filesystem image or handling unsolicited ingress network/peripheral traffic.
|
| 6/2 |
2026/10/17 01:46 |
llm |
expert |
0m
Model:
Tokens:
input: 25338
output: 263
thoughts: 365
Thoughts: **Analyzing a CIFS KASAN Slab Use-After-Free Bug**
My immediate focus upon encountering this KASAN bug report, specifically `BUG: KASAN: slab-use-after-free in cifs_crypto_secmech_release+0xed/0x120 fs/smb/client/cifsencrypt.c:512`, is to meticulously dissect the reported crash and its subsequent memory corruption. The traceback indicates a use-after-free (UAF) event originating within `cifs_crypto_secmech_release`, followed by further UAF reads/writes occurring in `cifs_put_tcp_session` at lines 1742 and 1743. This suggests a race condition or a logic error where a data structure, likely related to cryptographic security mechanisms, is being freed but then accessed again.
To gain a deep understanding of the failure, I need to thoroughly examine the source code of the functions implicated. My plan involves inspecting the following key components:
1. **`cifs_crypto_secmech_release` in `fs/smb/client/cifsencrypt.c`**: This is the primary function where the UAF is reported. I'll need to understand how it manages the lifetime of security mechanism structures, what triggers their release, and what holds references to them.
2. **`cifs_put_tcp_session` in `fs/smb/client/connect.c`**: This function is showing subsequent UAF accesses, which implies it's trying to operate on a TCP session structure that has already been deallocated, possibly due to the problematic release in `cifs_crypto_secmech_release`. I'll need to trace how `cifs_put_tcp_session` is called and what its dependencies are.
3. **`cifs_get_tcp_session` in `fs/smb/client/connect.c`**: Understanding how TCP sessions are established and managed is crucial. This function will help me see the lifecycle of these session structures and how they are potentially shared or referenced.
4. **`clean_demultiplex_info` and `cifs_demultiplex_thread` in `fs/smb/client/connect.c`**: Demultiplexing threads are often involved in managing concurrent connections or operations. I suspect they might be involved in the race condition leading to the UAF, perhaps by releasing resources prematurely while other threads still hold pointers.
5. **`cifs_mount` and `cifs_mount_put_conns` in `fs/smb/client/connect.c`**: These functions deal with the mounting process and the eventual cleanup of connections. I'll look for any interactions with the crypto or session management that might lead to premature freeing of resources during mount/unmount or connection teardown.
6. **`smb3_init_fs_context` / `cifs_fs_type` in `fs/smb/client/cifsfs.c` and `fs/smb/client/fs_context.c`**: This is where I need to investigate the mounting context and potential security implications. Specifically, I want to check the `fs_flags`, particularly if `FS_USERNS_MOUNT` is set. If it is, or if mounting CIFS typically requires `CAP_SYS_ADMIN` in the initial user namespace (`init_user_ns`), this could indicate a privilege escalation vector or a specific interaction within unprivileged user namespaces that exacerbates the UAF.
To efficiently gather information on these functions and their interdependencies, I plan to execute a batch of `codesearch-definition-source` or `read-file` commands. This will allow me to systematically pull the relevant code snippets and function definitions, which I can then analyze to trace the data flow and identify the precise point of failure and the underlying cause of the use-after-free condition. My goal is to pinpoint the exact sequence of events that leads to the double-free or the premature release of memory that is still in use.
|
| 7/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/cifsencrypt.c Name:cifs_crypto_secmech_release]
Results: map[SourceCode: 509: void
510: cifs_crypto_secmech_release(struct TCP_Server_Info *server)
511: {
512: if (server->secmech.enc) {
513: crypto_free_aead(server->secmech.enc);
514: server->secmech.enc = NULL;
515: }
516: if (server->secmech.dec) {
517: crypto_free_aead(server->secmech.dec);
518: server->secmech.dec = NULL;
519: }
520: }
SourceFile:fs/smb/client/cifsencrypt.c]
|
| 8/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_put_tcp_session]
Results: map[SourceCode:1702: void
1703: cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
1704: {
1705: struct task_struct *task;
1706:
1707: spin_lock(&cifs_tcp_ses_lock);
1708: if (--server->srv_count > 0) {
1709: spin_unlock(&cifs_tcp_ses_lock);
1710: return;
1711: }
1712:
1713: /* srv_count can never go negative */
1714: WARN_ON(server->srv_count < 0);
1715:
1716: list_del_init(&server->tcp_ses_list);
1717: spin_unlock(&cifs_tcp_ses_lock);
1718:
1719: cancel_delayed_work_sync(&server->echo);
1720:
1721: if (from_reconnect)
1722: /*
1723: * Avoid deadlock here: reconnect work calls
1724: * cifs_put_tcp_session() at its end. Need to be sure
1725: * that reconnect work does nothing with server pointer after
1726: * that step.
1727: */
1728: cancel_delayed_work(&server->reconnect);
1729: else
1730: cancel_delayed_work_sync(&server->reconnect);
1731:
1732: /* For secondary channels, we pick up ref-count on the primary server */
1733: if (SERVER_IS_CHAN(server))
1734: cifs_put_tcp_session(server->primary_server, from_reconnect);
1735:
1736: spin_lock(&server->srv_lock);
1737: server->tcpStatus = CifsExiting;
1738: spin_unlock(&server->srv_lock);
1739:
1740: cifs_crypto_secmech_release(server);
1741:
1742: kfree_sensitive(server->session_key.response);
1743: server->session_key.response = NULL;
1744: server->session_key.len = 0;
1745:
1746: task = xchg(&server->tsk, NULL);
1747: if (task)
1748: send_sig(SIGKILL, task, 1);
1749: }
SourceFile:fs/smb/client/connect.c]
|
| 9/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:clean_demultiplex_info]
Results: map[SourceCode:1065: static noinline_for_stack void
1066: clean_demultiplex_info(struct TCP_Server_Info *server)
1067: {
1068: int length;
1069:
1070: /* take it off the list, if it's not already */
1071: spin_lock(&server->srv_lock);
1072: list_del_init(&server->tcp_ses_list);
1073: spin_unlock(&server->srv_lock);
1074:
1075: cancel_delayed_work_sync(&server->echo);
1076: cancel_delayed_work_sync(&server->reconnect);
1077:
1078: spin_lock(&server->srv_lock);
1079: server->tcpStatus = CifsExiting;
1080: spin_unlock(&server->srv_lock);
1081: wake_up_all(&server->response_q);
1082:
1083: /* check if we have blocked requests that need to free */
1084: spin_lock(&server->req_lock);
1085: if (server->credits <= 0)
1086: server->credits = 1;
1087: spin_unlock(&server->req_lock);
1088: /*
1089: * Although there should not be any requests blocked on this queue it
1090: * can not hurt to be paranoid and try to wake up requests that may
1091: * haven been blocked when more than 50 at time were on the wire to the
1092: * same server - they now will see the session is in exit state and get
1093: * out of SendReceive.
1094: */
1095: wake_up_all(&server->request_q);
1096: /* give those requests time to exit */
1097: msleep(125);
1098: if (cifs_rdma_enabled(server))
1099: smbd_destroy(server);
1100: if (server->ssocket) {
1101: sock_release(server->ssocket);
1102: server->ssocket = NULL;
1103: }
1104:
1105: if (!list_empty(&server->pending_mid_q)) {
1106: struct mid_q_entry *mid_entry;
1107: struct list_head *tmp, *tmp2;
1108: LIST_HEAD(dispose_list);
1109:
1110: spin_lock(&server->mid_queue_lock);
1111: list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
1112: mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
1113: cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid);
1114: smb_get_mid(mid_entry);
1115: mid_entry->mid_state = MID_SHUTDOWN;
1116: list_move(&mid_entry->qhead, &dispose_list);
1117: mid_entry->deleted_from_q = true;
1118: }
1119: spin_unlock(&server->mid_queue_lock);
1120:
1121: /* now walk dispose list and issue callbacks */
1122: list_for_each_safe(tmp, tmp2, &dispose_list) {
1123: mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
1124: cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid);
1125: list_del_init(&mid_entry->qhead);
1126: mid_execute_callback(server, mid_entry);
1127: release_mid(server, mid_entry);
1128: }
1129: /* 1/8th of sec is more than enough time for them to exit */
1130: msleep(125);
1131: }
1132:
1133: if (!list_empty(&server->pending_mid_q)) {
1134: /*
1135: * mpx threads have not exited yet give them at least the smb
1136: * send timeout time for long ops.
1137: *
1138: * Due to delays on oplock break requests, we need to wait at
1139: * least 45 seconds before giving up on a request getting a
1140: * response and going ahead and killing cifsd.
1141: */
1142: cifs_dbg(FYI, "Wait for exit from demultiplex thread\n");
1143: msleep(46000);
1144: /*
1145: * If threads still have not exited they are probably never
1146: * coming home not much else we can do but free the memory.
1147: */
1148: }
1149:
1150: put_net(cifs_net_ns(server));
1151: kfree(server->leaf_fullpath);
1152: kfree(server->hostname);
1153: kfree_sensitive(server);
1154:
1155: length = atomic_dec_return(&tcpSesAllocCount);
1156: if (length > 0)
1157: mempool_resize(cifs_req_poolp, length + cifs_min_rcv);
1158: }
SourceFile:fs/smb/client/connect.c]
|
| 10/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_get_tcp_session]
Results: map[SourceCode:1751: struct TCP_Server_Info *
1752: cifs_get_tcp_session(struct smb3_fs_context *ctx,
1753: struct TCP_Server_Info *primary_server)
1754: {
1755: struct TCP_Server_Info *tcp_ses = NULL;
1756: int rc;
1757:
1758: cifs_dbg(FYI, "UNC: %s\n", ctx->UNC);
1759:
1760: /* see if we already have a matching tcp_ses */
1761: tcp_ses = cifs_find_tcp_session(ctx);
1762: if (tcp_ses)
1763: return tcp_ses;
1764:
1765: tcp_ses = kzalloc_obj(struct TCP_Server_Info);
1766: if (!tcp_ses) {
1767: rc = -ENOMEM;
1768: goto out_err;
1769: }
1770:
1771: tcp_ses->hostname = kstrdup(ctx->server_hostname, GFP_KERNEL);
1772: if (!tcp_ses->hostname) {
1773: rc = -ENOMEM;
1774: goto out_err;
1775: }
1776:
1777: if (ctx->leaf_fullpath) {
1778: tcp_ses->leaf_fullpath = kstrdup(ctx->leaf_fullpath, GFP_KERNEL);
1779: if (!tcp_ses->leaf_fullpath) {
1780: rc = -ENOMEM;
1781: goto out_err;
1782: }
1783: }
1784: if (ctx->dns_dom)
1785: strscpy(tcp_ses->dns_dom, ctx->dns_dom);
1786:
1787: if (ctx->nosharesock)
1788: tcp_ses->nosharesock = true;
1789: tcp_ses->dfs_conn = ctx->dfs_conn;
1790:
1791: tcp_ses->ops = ctx->ops;
1792: tcp_ses->vals = ctx->vals;
1793: cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
1794:
1795: tcp_ses->sign = ctx->sign;
1796: tcp_ses->conn_id = atomic_inc_return(&tcpSesNextId);
1797: tcp_ses->noblockcnt = ctx->rootfs;
1798: tcp_ses->noblocksnd = ctx->noblocksnd || ctx->rootfs;
1799: tcp_ses->noautotune = ctx->noautotune;
1800: tcp_ses->tcp_nodelay = ctx->sockopt_tcp_nodelay;
1801: tcp_ses->rdma = ctx->rdma;
1802: tcp_ses->in_flight = 0;
1803: tcp_ses->max_in_flight = 0;
1804: tcp_ses->credits = 1;
1805: if (primary_server) {
1806: spin_lock(&cifs_tcp_ses_lock);
1807: ++primary_server->srv_count;
1808: spin_unlock(&cifs_tcp_ses_lock);
1809: tcp_ses->primary_server = primary_server;
1810: }
1811: init_waitqueue_head(&tcp_ses->response_q);
1812: init_waitqueue_head(&tcp_ses->request_q);
1813: INIT_LIST_HEAD(&tcp_ses->pending_mid_q);
1814: mutex_init(&tcp_ses->_srv_mutex);
1815: memcpy(tcp_ses->workstation_RFC1001_name,
1816: ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);
1817: memcpy(tcp_ses->server_RFC1001_name,
1818: ctx->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);
1819: tcp_ses->rfc1001_sessinit = ctx->rfc1001_sessinit;
1820: tcp_ses->with_rfc1001 = false;
1821: tcp_ses->session_estab = false;
1822: tcp_ses->sequence_number = 0;
1823: tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */
1824: tcp_ses->reconnect_instance = 1;
1825: tcp_ses->lstrp = jiffies;
1826: tcp_ses->compression.requested = ctx->compress;
1827: spin_lock_init(&tcp_ses->req_lock);
1828: spin_lock_init(&tcp_ses->srv_lock);
1829: spin_lock_init(&tcp_ses->mid_queue_lock);
1830: spin_lock_init(&tcp_ses->mid_counter_lock);
1831: INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
1832: INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
1833: INIT_LIST_HEAD(&tcp_ses->rlist);
1834: INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
1835: INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server);
1836: mutex_init(&tcp_ses->reconnect_mutex);
1837: memcpy(&tcp_ses->srcaddr, &ctx->srcaddr,
1838: sizeof(tcp_ses->srcaddr));
1839: memcpy(&tcp_ses->dstaddr, &ctx->dstaddr,
1840: sizeof(tcp_ses->dstaddr));
1841: if (ctx->use_client_guid)
1842: memcpy(tcp_ses->client_guid, ctx->client_guid,
1843: SMB2_CLIENT_GUID_SIZE);
1844: else
1845: generate_random_uuid(tcp_ses->client_guid);
1846: /*
1847: * at this point we are the only ones with the pointer
1848: * to the struct since the kernel thread not created yet
1849: * no need to spinlock this init of tcpStatus or srv_count
1850: */
1851: tcp_ses->tcpStatus = CifsNew;
1852: ++tcp_ses->srv_count;
1853: tcp_ses->echo_interval = ctx->echo_interval * HZ;
1854:
1855: if (tcp_ses->rdma) {
1856: #ifndef CONFIG_CIFS_SMB_DIRECT
1857: cifs_dbg(VFS, "CONFIG_CIFS_SMB_DIRECT is not enabled\n");
1858: rc = -ENOENT;
1859: goto out_err_crypto_release;
1860: #endif
1861: tcp_ses->smbd_conn = smbd_get_connection(
1862: tcp_ses, (struct sockaddr *)&ctx->dstaddr);
1863: if (tcp_ses->smbd_conn) {
1864: cifs_dbg(VFS, "RDMA transport established\n");
1865: rc = 0;
1866: goto smbd_connected;
1867: } else {
1868: rc = -ENOENT;
1869: goto out_err_crypto_release;
1870: }
1871: }
1872: rc = ip_connect(tcp_ses);
1873: if (rc < 0) {
1874: cifs_dbg(VFS, "Error connecting to socket. Aborting operation.\n");
1875: goto out_err_crypto_release;
1876: }
1877: smbd_connected:
1878: /*
1879: * since we're in a cifs function already, we know that
1880: * this will succeed. No need for try_module_get().
1881: */
1882: __module_get(THIS_MODULE);
1883: tcp_ses->min_offload = ctx->min_offload;
1884: tcp_ses->retrans = ctx->retrans;
1885: /*
1886: * at this point we are the only ones with the pointer
1887: * to the struct since the kernel thread not created yet
1888: * no need to spinlock this update of tcpStatus
1889: */
1890: tcp_ses->tcpStatus = CifsNeedNegotiate;
1891:
1892: if ((ctx->max_credits < 20) || (ctx->max_credits > 60000))
1893: tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE;
1894: else
1895: tcp_ses->max_credits = ctx->max_credits;
1896:
1897: tcp_ses->nr_targets = 1;
1898: tcp_ses->ignore_signature = ctx->ignore_signature;
1899:
1900: tcp_ses->tsk = kthread_create(cifs_demultiplex_thread,
1901: tcp_ses, "cifsd");
1902: if (IS_ERR(tcp_ses->tsk)) {
1903: rc = PTR_ERR(tcp_ses->tsk);
1904: cifs_dbg(VFS, "error %d create cifsd thread\n", rc);
1905: module_put(THIS_MODULE);
1906: goto out_err_crypto_release;
1907: }
1908: /* thread created, put it on the list */
1909: spin_lock(&cifs_tcp_ses_lock);
1910: list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list);
1911: spin_unlock(&cifs_tcp_ses_lock);
1912:
1913: /* queue echo request delayed work */
1914: queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval);
1915:
1916: /*
1917: * Use split create/wake logic to ensure that tcp_ses is fully populated
1918: * and tcp_ses->tsk is valid
1919: */
1920: wake_up_process(tcp_ses->tsk);
1921:
1922: return tcp_ses;
1923:
1924: out_err_crypto_release:
1925: cifs_crypto_secmech_release(tcp_ses);
1926:
1927: put_net(cifs_net_ns(tcp_ses));
1928:
1929: out_err:
1930: if (tcp_ses) {
1931: if (SERVER_IS_CHAN(tcp_ses))
1932: cifs_put_tcp_session(tcp_ses->primary_server, false);
1933: kfree(tcp_ses->hostname);
1934: kfree(tcp_ses->leaf_fullpath);
1935: if (tcp_ses->ssocket)
1936: sock_release(tcp_ses->ssocket);
1937: smbd_destroy(tcp_ses);
1938: kfree(tcp_ses);
1939: }
1940: return ERR_PTR(rc);
1941: }
SourceFile:fs/smb/client/connect.c]
|
| 11/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/cifsfs.c Name:cifs_fs_type]
Results: map[SourceCode:1172: struct file_system_type cifs_fs_type = {
1173: .owner = THIS_MODULE,
1174: .name = "cifs",
1175: .init_fs_context = smb3_init_fs_context,
1176: .parameters = smb3_fs_parameters,
1177: .kill_sb = cifs_kill_sb,
1178: .fs_flags = FS_RENAME_DOES_D_MOVE,
1179: };
SourceFile:fs/smb/client/cifsfs.c]
|
| 12/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/cifsfs.c Name:smb3_fs_type]
Results: map[SourceCode:1182: struct file_system_type smb3_fs_type = {
1183: .owner = THIS_MODULE,
1184: .name = "smb3",
1185: .init_fs_context = smb3_init_fs_context,
1186: .parameters = smb3_fs_parameters,
1187: .kill_sb = cifs_kill_sb,
1188: .fs_flags = FS_RENAME_DOES_D_MOVE,
1189: };
SourceFile:fs/smb/client/cifsfs.c]
|
| 13/2 |
2026/10/17 01:46 |
llm |
expert |
0m
Model:
Tokens:
input: 32099
output: 46
thoughts: 60
Thoughts: **My Thought Process on CIFS Demultiplexing and Session Management**
Alright, I'm diving into the guts of the CIFS client, and my attention is immediately drawn to the interplay between `cifs_demultiplex_thread`, `clean_demultiplex_info`, and `cifs_put_tcp_session`. This feels like a critical area for managing network traffic and resources efficiently. My primary focus right now is to understand the lifecycle and responsibilities of the demultiplexing thread.
I'm going to start by scrutinizing the `cifs_demultiplex_thread` function, which I anticipate will be located in `fs/smb/client/connect.c`. My immediate goal is to map out its core logic: what triggers it, what operations it performs, and how it interacts with other components. I'll be looking for:
* **Its main loop:** What is this thread continuously doing? Is it waiting for incoming data, processing requests, or managing state?
* **The `clean_demultiplex_info` connection:** How and when is `clean_demultiplex_info` invoked? I suspect it's a cleanup routine. What specific information does it clean up, and under what conditions (e.g., errors, connection termination, idle timeouts)? Does it involve freeing resources or resetting state?
* **The `cifs_put_tcp_session` interaction:** This function name suggests releasing or decrementing the reference count on a TCP session. How does the demultiplexing thread use `cifs_put_tcp_session`? Is it called when the thread is exiting, when a specific session is no longer needed, or as part of error handling? I need to understand the reference counting mechanics for TCP sessions and how the demultiplexing thread contributes to this.
* **Demultiplexing logic:** What is the actual "demultiplexing" that this thread is performing? Is it sorting incoming SMB packets by their associated connection or session? Is it handling multiple outstanding requests over a single TCP connection?
* **Error handling and termination:** How does `cifs_demultiplex_thread` react to errors on the network or within the SMB protocol itself? What mechanisms are in place for graceful termination of the thread, and what cleanup ensues when it does terminate?
By tracing the execution flow within `cifs_demultiplex_thread` and understanding its relationship with these other functions, I aim to build a comprehensive mental model of how the CIFS client manages its network connections and ensures that incoming data is correctly routed and processed while gracefully releasing resources when they are no longer required. This is foundational to understanding the robustness and performance of the CIFS client.
|
| 14/2 |
2026/10/17 01:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_demultiplex_thread]
Results: map[SourceCode:1261: static int
1262: cifs_demultiplex_thread(void *p)
1263: {
1264: int i, num_mids, length;
1265: struct TCP_Server_Info *server = p;
1266: unsigned int pdu_length;
1267: unsigned int next_offset;
1268: char *buf = NULL;
1269: struct task_struct *task_to_wake = NULL;
1270: struct mid_q_entry *mids[MAX_COMPOUND];
1271: char *bufs[MAX_COMPOUND];
1272: unsigned int noreclaim_flag, num_io_timeout = 0;
1273: bool pending_reconnect = false;
1274:
1275: noreclaim_flag = memalloc_noreclaim_save();
1276: cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current));
1277:
1278: length = atomic_inc_return(&tcpSesAllocCount);
1279: if (length > 1)
1280: mempool_resize(cifs_req_poolp, length + cifs_min_rcv);
1281:
1282: set_freezable();
1283: allow_kernel_signal(SIGKILL);
1284: while (server->tcpStatus != CifsExiting) {
1285: if (try_to_freeze())
1286: continue;
1287:
1288: if (!allocate_buffers(server))
1289: continue;
1290:
1291: server->large_buf = false;
1292: buf = server->smallbuf;
1293: pdu_length = 4; /* enough to get RFC1001 header */
1294:
1295: length = cifs_read_from_socket(server, buf, pdu_length);
1296: if (length < 0)
1297: continue;
1298:
1299: server->total_read = 0;
1300:
1301: /*
1302: * The right amount was read from socket - 4 bytes,
1303: * so we can now interpret the length field.
1304: */
1305: pdu_length = be32_to_cpup(((__be32 *)buf)) & 0xffffff;
1306:
1307: cifs_dbg(FYI, "RFC1002 header 0x%x\n", pdu_length);
1308: if (!is_smb_response(server, buf[0]))
1309: continue;
1310:
1311: pending_reconnect = false;
1312: next_pdu:
1313: server->pdu_size = pdu_length;
1314:
1315: /* make sure we have enough to get to the MID */
1316: if (server->pdu_size < MID_HEADER_SIZE(server)) {
1317: cifs_server_dbg(VFS, "SMB response too short (%u bytes)\n",
1318: server->pdu_size);
1319: cifs_reconnect(server, true);
1320: continue;
1321: }
1322:
1323: /* read down to the MID */
1324: length = cifs_read_from_socket(server, buf,
1325: MID_HEADER_SIZE(server));
1326: if (length < 0)
1327: continue;
1328: server->total_read += length;
1329:
1330: if (server->ops->next_header) {
1331: if (server->ops->next_header(server, buf, &next_offset)) {
1332: cifs_dbg(VFS, "%s: malformed response (next_offset=%u)\n",
1333: __func__, next_offset);
1334: cifs_reconnect(server, true);
1335: continue;
1336: }
1337: if (next_offset)
1338: server->pdu_size = next_offset;
1339: }
1340:
1341: memset(mids, 0, sizeof(mids));
1342: memset(bufs, 0, sizeof(bufs));
1343: num_mids = 0;
1344:
1345: if (server->ops->is_transform_hdr &&
1346: server->ops->receive_transform &&
1347: server->ops->is_transform_hdr(buf)) {
1348: length = server->ops->receive_transform(server,
1349: mids,
1350: bufs,
1351: &num_mids);
1352: } else {
1353: mids[0] = server->ops->find_mid(server, buf);
1354: bufs[0] = buf;
1355: num_mids = 1;
1356:
1357: if (mids[0])
1358: mids[0]->response_pdu_len = pdu_length;
1359: if (!mids[0] || !mids[0]->receive)
1360: length = standard_receive3(server, mids[0]);
1361: else
1362: length = mids[0]->receive(server, mids[0]);
1363: }
1364:
1365: if (length < 0) {
1366: for (i = 0; i < num_mids; i++)
1367: if (mids[i])
1368: release_mid(server, mids[i]);
1369: continue;
1370: }
1371:
1372: if (server->ops->is_status_io_timeout &&
1373: server->ops->is_status_io_timeout(buf)) {
1374: num_io_timeout++;
1375: if (num_io_timeout > MAX_STATUS_IO_TIMEOUT) {
1376: cifs_server_dbg(VFS,
1377: "Number of request timeouts exceeded %d. Reconnecting",
1378: MAX_STATUS_IO_TIMEOUT);
1379:
1380: pending_reconnect = true;
1381: num_io_timeout = 0;
1382: }
1383: }
1384:
1385: server->lstrp = jiffies;
1386:
1387: for (i = 0; i < num_mids; i++) {
1388: if (mids[i] != NULL) {
1389: mids[i]->resp_buf_size = server->pdu_size;
1390:
1391: if (bufs[i] != NULL) {
1392: if (server->ops->is_network_name_deleted &&
1393: server->ops->is_network_name_deleted(bufs[i],
1394: server)) {
1395: cifs_server_dbg(FYI,
1396: "Share deleted. Reconnect needed");
1397: }
1398: }
1399:
1400: if (!mids[i]->multiRsp || mids[i]->multiEnd)
1401: mid_execute_callback(server, mids[i]);
1402:
1403: release_mid(server, mids[i]);
1404: } else if (server->ops->is_oplock_break &&
1405: server->ops->is_oplock_break(bufs[i],
1406: server)) {
1407: smb2_add_credits_from_hdr(bufs[i], server);
1408: cifs_dbg(FYI, "Received oplock break\n");
1409: } else {
1410: cifs_server_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n",
1411: atomic_read(&mid_count));
1412: cifs_dump_mem("Received Data is: ", bufs[i],
1413: HEADER_SIZE(server));
1414: smb2_add_credits_from_hdr(bufs[i], server);
1415: #ifdef CONFIG_CIFS_DEBUG2
1416: if (server->ops->dump_detail)
1417: server->ops->dump_detail(bufs[i], pdu_length,
1418: server);
1419: cifs_dump_mids(server);
1420: #endif /* CIFS_DEBUG2 */
1421: }
1422: }
1423:
1424: if (pdu_length > server->pdu_size) {
1425: if (!allocate_buffers(server))
1426: continue;
1427: pdu_length -= server->pdu_size;
1428: server->total_read = 0;
1429: server->large_buf = false;
1430: buf = server->smallbuf;
1431: goto next_pdu;
1432: }
1433:
1434: /* do this reconnect at the very end after processing all MIDs */
1435: if (pending_reconnect)
1436: cifs_reconnect(server, true);
1437:
1438: } /* end while !EXITING */
1439:
1440: /* buffer usually freed in free_mid - need to free it here on exit */
1441: cifs_buf_release(server->bigbuf);
1442: if (server->smallbuf) /* no sense logging a debug message if NULL */
1443: cifs_small_buf_release(server->smallbuf);
1444:
1445: task_to_wake = xchg(&server->tsk, NULL);
1446: clean_demultiplex_info(server);
1447:
1448: /* if server->tsk was NULL then wait for a signal before exiting */
1449: if (!task_to_wake) {
1450: set_current_state(TASK_INTERRUPTIBLE);
1451: while (!signal_pending(current)) {
1452: schedule();
1453: set_current_state(TASK_INTERRUPTIBLE);
1454: }
1455: set_current_state(TASK_RUNNING);
1456: }
1457:
1458: memalloc_noreclaim_restore(noreclaim_flag);
1459: module_put_and_kthread_exit(0);
1460: }
SourceFile:fs/smb/client/connect.c]
|
| 15/2 |
2026/10/17 01:46 |
llm |
expert |
0m
Model:
Tokens:
input: 35266
output: 35
thoughts: 1096
Thoughts: **A Critical Race Condition in CIFS Session Management**
I've just spotted something deeply concerning regarding the handling of TCP sessions in the CIFS client implementation, specifically when it comes to tearing down a `server` structure. The interaction between `cifs_put_tcp_session` and `cifs_demultiplex_thread` appears to be a textbook example of a race condition that could lead to a use-after-free vulnerability.
Here's my thought process:
My attention was immediately drawn to the sequence of operations within `cifs_put_tcp_session`, particularly around line 1737 where `server->tcpStatus` is set to `CifsExiting`. This is a crucial state change, intended to signal to other threads that the server session is being shut down.
Concurrently, I'm looking at `cifs_demultiplex_thread`, which operates within a `while (server->tcpStatus != CifsExiting)` loop. This structure implies that once `server->tcpStatus` becomes `CifsExiting`, the loop should terminate, and cleanup should commence.
The problem arises when `cifs_demultiplex_thread` *does* exit its loop because `server->tcpStatus` is `CifsExiting`. At line 1446, it calls `clean_demultiplex_info(server)`. Now, within `clean_demultiplex_info`, I see a critical line: `kfree_sensitive(server)`. This effectively deallocates the memory pointed to by `server`.
The real issue is the timing. `cifs_put_tcp_session` continues its execution *after* setting `server->tcpStatus = CifsExiting`. It proceeds to call `cifs_crypto_secmech_release(server)`, `kfree_sensitive(server->session_key.response)`, and most importantly, `xchg(&server->tsk, NULL)`. If `cifs_demultiplex_thread` has already entered `clean_demultiplex_info` and freed `server`, then these subsequent operations within `cifs_put_tcp_session` will be accessing freed memory, leading to a use-after-free scenario.
It's even more precarious when I examine lines 1445-1456 in `cifs_demultiplex_thread`. The `xchg(&server->tsk, NULL)` here is likely an attempt to synchronize with `cifs_put_tcp_session` by ensuring the `task` pointer is cleared before the thread potentially waits. However, if `cifs_put_tcp_session` sets `CifsExiting` *before* this `xchg` or if `cifs_demultiplex_thread` observes `CifsExiting` and proceeds to free `server` (via `clean_demultiplex_info`), then `cifs_put_tcp_session` is still attempting to dereference `server` at lines 1740-1746.
The core of the problem is that `cifs_put_tcp_session` sets the exit condition (`CifsExiting`) and then proceeds with cleanup operations that assume `server` is still valid. Meanwhile, the `cifs_demultiplex_thread`, upon observing this exit condition, immediately calls `clean_demultiplex_info`, which deallocates `server` *before* `cifs_put_tcp_session` has finished its work.
This suggests that the synchronization mechanism, specifically the state transition to `CifsExiting` and its subsequent cleanup, isn't robust enough to prevent the deallocation of `server` while it's still being actively used by another concurrent thread. I need to investigate if any other part of the code can set `CifsExiting` and if the order of operations within `cifs_put_tcp_session` and `cifs_demultiplex_thread` can lead to this unfortunate state. My next step is to thoroughly `grep` for all occurrences of `CifsExiting` across `fs/smb/client/` to understand the full scope of how this state is managed and potentially triggered.
|
| 16/2 |
2026/10/17 01:47 |
tool |
grepper |
0m
Args: map[Expression:CifsExiting PathPrefixes:[fs/smb/client/]]
Results: map[Output:fs/smb/client/cifsglob.h=120=enum statusEnum {
--
fs/smb/client/cifsglob.h-122- CifsGood,
fs/smb/client/cifsglob.h:123: CifsExiting,
fs/smb/client/cifsglob.h-124- CifsNeedReconnect,
--
fs/smb/client/cifssmb.c=72=cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
--
fs/smb/client/cifssmb.c-122- switch (server->tcpStatus) {
fs/smb/client/cifssmb.c:123: case CifsExiting:
fs/smb/client/cifssmb.c-124- spin_unlock(&server->srv_lock);
--
fs/smb/client/connect.c=131=do { \
fs/smb/client/connect.c-132- spin_lock(&server->srv_lock); \
fs/smb/client/connect.c:133: if (server->tcpStatus != CifsExiting) \
fs/smb/client/connect.c-134- server->tcpStatus = CifsNeedReconnect; \
--
fs/smb/client/connect.c=354=static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num_targets)
--
fs/smb/client/connect.c-357- server->nr_targets = num_targets;
fs/smb/client/connect.c:358: if (server->tcpStatus == CifsExiting) {
fs/smb/client/connect.c-359- /* the demux thread will exit normally next time through the loop */
--
fs/smb/client/connect.c=387=static int __cifs_reconnect(struct TCP_Server_Info *server,
--
fs/smb/client/connect.c-431- spin_lock(&server->srv_lock);
fs/smb/client/connect.c:432: if (server->tcpStatus != CifsExiting)
fs/smb/client/connect.c-433- server->tcpStatus = CifsNeedNegotiate;
--
fs/smb/client/connect.c=518=static int reconnect_dfs_server(struct TCP_Server_Info *server)
--
fs/smb/client/connect.c-570- spin_lock(&server->srv_lock);
fs/smb/client/connect.c:571: if (server->tcpStatus != CifsExiting)
fs/smb/client/connect.c-572- server->tcpStatus = CifsNeedNegotiate;
--
fs/smb/client/connect.c=620=cifs_echo_request(struct work_struct *work)
--
fs/smb/client/connect.c-631- if (server->tcpStatus == CifsNeedReconnect ||
fs/smb/client/connect.c:632: server->tcpStatus == CifsExiting ||
fs/smb/client/connect.c-633- server->tcpStatus == CifsNew ||
--
fs/smb/client/connect.c=739=cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
--
fs/smb/client/connect.c-760- spin_lock(&server->srv_lock);
fs/smb/client/connect.c:761: if (server->tcpStatus == CifsExiting) {
fs/smb/client/connect.c-762- spin_unlock(&server->srv_lock);
--
fs/smb/client/connect.c=1066=clean_demultiplex_info(struct TCP_Server_Info *server)
--
fs/smb/client/connect.c-1078- spin_lock(&server->srv_lock);
fs/smb/client/connect.c:1079: server->tcpStatus = CifsExiting;
fs/smb/client/connect.c-1080- spin_unlock(&server->srv_lock);
--
fs/smb/client/connect.c=1262=cifs_demultiplex_thread(void *p)
--
fs/smb/client/connect.c-1283- allow_kernel_signal(SIGKILL);
fs/smb/client/connect.c:1284: while (server->tcpStatus != CifsExiting) {
fs/smb/client/connect.c-1285- if (try_to_freeze())
--
fs/smb/client/connect.c=1703=cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
--
fs/smb/client/connect.c-1736- spin_lock(&server->srv_lock);
fs/smb/client/connect.c:1737: server->tcpStatus = CifsExiting;
fs/smb/client/connect.c-1738- spin_unlock(&server->srv_lock);
--
fs/smb/client/smb2ops.c=69=smb2_add_credits(struct TCP_Server_Info *server,
--
fs/smb/client/smb2ops.c-165- if (server->tcpStatus == CifsNeedReconnect
fs/smb/client/smb2ops.c:166: || server->tcpStatus == CifsExiting) {
fs/smb/client/smb2ops.c-167- spin_unlock(&server->srv_lock);
--
fs/smb/client/smb2ops.c=246=smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
--
fs/smb/client/smb2ops.c-256- spin_lock(&server->srv_lock);
fs/smb/client/smb2ops.c:257: if (server->tcpStatus == CifsExiting) {
fs/smb/client/smb2ops.c-258- spin_unlock(&server->srv_lock);
--
fs/smb/client/smb2pdu.c=250=smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
--
fs/smb/client/smb2pdu.c-341- switch (server->tcpStatus) {
fs/smb/client/smb2pdu.c:342: case CifsExiting:
fs/smb/client/smb2pdu.c-343- spin_unlock(&server->srv_lock);
--
fs/smb/client/smb2transport.c=654=smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
--
fs/smb/client/smb2transport.c-657- switch (READ_ONCE(server->tcpStatus)) {
fs/smb/client/smb2transport.c:658: case CifsExiting:
fs/smb/client/smb2transport.c-659- return -ENOENT;
--
fs/smb/client/transport.c=423=wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
--
fs/smb/client/transport.c-470- spin_lock(&server->srv_lock);
fs/smb/client/transport.c:471: if (server->tcpStatus == CifsExiting) {
fs/smb/client/transport.c-472- spin_unlock(&server->srv_lock);
--
fs/smb/client/transport.c=874=compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
--
fs/smb/client/transport.c-899- spin_lock(&server->srv_lock);
fs/smb/client/transport.c:900: if (server->tcpStatus == CifsExiting) {
fs/smb/client/transport.c-901- spin_unlock(&server->srv_lock);
]
|
| 17/2 |
2026/10/17 01:47 |
llm |
expert |
0m
Model:
Tokens:
input: 38416
output: 124
thoughts: 37
Thoughts: **My Thought Process Regarding CIFS Session Management and Demultiplexing**
My immediate instinct is to delve into the nitty-gritty of how CIFS handles its network sessions and the underlying mechanisms for demultiplexing. To do this effectively, I want to examine the specific functions responsible for cleaning up TCP sessions and managing the demultiplexing threads.
Specifically, I'm going to run `git blame` on three key functions:
1. `cifs_put_tcp_session`: I need to understand who last modified this function, and importantly, *why*. This function is crucial for releasing resources associated with a CIFS TCP session. Any recent changes here could indicate a fix for a memory leak, a change in connection pooling behavior, or a modification to how session state is managed upon disconnection. I want to trace the evolution of this code to see if there have been any performance optimizations or bug fixes related to session cleanup.
2. `cifs_demultiplex_thread`: This function likely represents the core of the demultiplexing logic. I'm interested in seeing who introduced or altered the way incoming network packets are routed to the appropriate CIFS request/response pairs. Understanding the history of this function will reveal how the design has evolved, how it handles concurrency, and if there have been any attempts to improve its efficiency or robustness in dealing with multiple simultaneous connections or large numbers of outstanding requests.
3. `clean_demultiplex_info`: This function sounds like a cleanup utility for the data structures used by the demultiplexing process. I want to see its lineage to understand how it interacts with the demultiplexing thread and session management. Are there any potential race conditions or resource leaks that this cleanup function aims to prevent? Knowing who last touched this and what problems they were trying to solve will be invaluable in assessing the current state of the code.
By examining the commit history associated with these functions, I'll gain a deep understanding of their development, the rationale behind any changes, and the potential implications for the overall stability and performance of the CIFS client. This granular approach is essential for identifying subtle bugs or areas for optimization in complex network protocols.
|
| 18/2 |
2026/10/17 01:47 |
tool |
git-blame |
0m
Args: map[End:1750 File:fs/smb/client/connect.c Start:1700]
Results: map[Output:^1da177e4c3f4 fs/cifs/connect.c 1700) }
1b20d672188bf fs/cifs/connect.c 1701)
53e0e11efe928 fs/cifs/connect.c 1702) void
53e0e11efe928 fs/cifs/connect.c 1703) cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
^1da177e4c3f4 fs/cifs/connect.c 1704) {
a5c3e1c725af9 fs/cifs/connect.c 1705) struct task_struct *task;
a5c3e1c725af9 fs/cifs/connect.c 1706)
3f9bcca7820a6 fs/cifs/connect.c 1707) spin_lock(&cifs_tcp_ses_lock);
e7ddee9037e7d fs/cifs/connect.c 1708) if (--server->srv_count > 0) {
3f9bcca7820a6 fs/cifs/connect.c 1709) spin_unlock(&cifs_tcp_ses_lock);
e7ddee9037e7d fs/cifs/connect.c 1710) return;
^1da177e4c3f4 fs/cifs/connect.c 1711) }
1b20d672188bf fs/cifs/connect.c 1712)
16dd9b8c31aee fs/cifs/connect.c 1713) /* srv_count can never go negative */
16dd9b8c31aee fs/cifs/connect.c 1714) WARN_ON(server->srv_count < 0);
16dd9b8c31aee fs/cifs/connect.c 1715)
e7ddee9037e7d fs/cifs/connect.c 1716) list_del_init(&server->tcp_ses_list);
3f9bcca7820a6 fs/cifs/connect.c 1717) spin_unlock(&cifs_tcp_ses_lock);
dea570e08a69b fs/cifs/connect.c 1718)
c74093b694998 fs/cifs/connect.c 1719) cancel_delayed_work_sync(&server->echo);
c74093b694998 fs/cifs/connect.c 1720)
8233425248681 fs/smb/client/connect.c 1721) if (from_reconnect)
53e0e11efe928 fs/cifs/connect.c 1722) /*
53e0e11efe928 fs/cifs/connect.c 1723) * Avoid deadlock here: reconnect work calls
53e0e11efe928 fs/cifs/connect.c 1724) * cifs_put_tcp_session() at its end. Need to be sure
53e0e11efe928 fs/cifs/connect.c 1725) * that reconnect work does nothing with server pointer after
53e0e11efe928 fs/cifs/connect.c 1726) * that step.
53e0e11efe928 fs/cifs/connect.c 1727) */
8233425248681 fs/smb/client/connect.c 1728) cancel_delayed_work(&server->reconnect);
8233425248681 fs/smb/client/connect.c 1729) else
8233425248681 fs/smb/client/connect.c 1730) cancel_delayed_work_sync(&server->reconnect);
53e0e11efe928 fs/cifs/connect.c 1731)
04909192ada32 fs/smb/client/connect.c 1732) /* For secondary channels, we pick up ref-count on the primary server */
04909192ada32 fs/smb/client/connect.c 1733) if (SERVER_IS_CHAN(server))
04909192ada32 fs/smb/client/connect.c 1734) cifs_put_tcp_session(server->primary_server, from_reconnect);
04909192ada32 fs/smb/client/connect.c 1735)
d7d7a66aacd6f fs/cifs/connect.c 1736) spin_lock(&server->srv_lock);
e7ddee9037e7d fs/cifs/connect.c 1737) server->tcpStatus = CifsExiting;
d7d7a66aacd6f fs/cifs/connect.c 1738) spin_unlock(&server->srv_lock);
dea570e08a69b fs/cifs/connect.c 1739)
026e93dc0a3ee fs/cifs/connect.c 1740) cifs_crypto_secmech_release(server);
46bb1b9484aea fs/cifs/connect.c 1741)
a4e430c8c8ba9 fs/cifs/connect.c 1742) kfree_sensitive(server->session_key.response);
21e733930be64 fs/cifs/connect.c 1743) server->session_key.response = NULL;
21e733930be64 fs/cifs/connect.c 1744) server->session_key.len = 0;
a5c3e1c725af9 fs/cifs/connect.c 1745)
a5c3e1c725af9 fs/cifs/connect.c 1746) task = xchg(&server->tsk, NULL);
a5c3e1c725af9 fs/cifs/connect.c 1747) if (task)
72abe3bcf0911 fs/cifs/connect.c 1748) send_sig(SIGKILL, task, 1);
^1da177e4c3f4 fs/cifs/connect.c 1749) }
^1da177e4c3f4 fs/cifs/connect.c 1750)
]
|
| 19/2 |
2026/10/17 01:47 |
tool |
git-blame |
0m
Args: map[End:1460 File:fs/smb/client/connect.c Start:1438]
Results: map[Output:e4eb295d38b57 fs/cifs/connect.c 1438) } /* end while !EXITING */
e4eb295d38b57 fs/cifs/connect.c 1439)
fd62cb7e7411f fs/cifs/connect.c 1440) /* buffer usually freed in free_mid - need to free it here on exit */
2a37ef94bb153 fs/cifs/connect.c 1441) cifs_buf_release(server->bigbuf);
2a37ef94bb153 fs/cifs/connect.c 1442) if (server->smallbuf) /* no sense logging a debug message if NULL */
2a37ef94bb153 fs/cifs/connect.c 1443) cifs_small_buf_release(server->smallbuf);
^1da177e4c3f4 fs/cifs/connect.c 1444)
a5c3e1c725af9 fs/cifs/connect.c 1445) task_to_wake = xchg(&server->tsk, NULL);
762dfd1057360 fs/cifs/connect.c 1446) clean_demultiplex_info(server);
a5c3e1c725af9 fs/cifs/connect.c 1447)
a5c3e1c725af9 fs/cifs/connect.c 1448) /* if server->tsk was NULL then wait for a signal before exiting */
a5c3e1c725af9 fs/cifs/connect.c 1449) if (!task_to_wake) {
a5c3e1c725af9 fs/cifs/connect.c 1450) set_current_state(TASK_INTERRUPTIBLE);
a5c3e1c725af9 fs/cifs/connect.c 1451) while (!signal_pending(current)) {
a5c3e1c725af9 fs/cifs/connect.c 1452) schedule();
a5c3e1c725af9 fs/cifs/connect.c 1453) set_current_state(TASK_INTERRUPTIBLE);
a5c3e1c725af9 fs/cifs/connect.c 1454) }
a5c3e1c725af9 fs/cifs/connect.c 1455) set_current_state(TASK_RUNNING);
a5c3e1c725af9 fs/cifs/connect.c 1456) }
a5c3e1c725af9 fs/cifs/connect.c 1457)
dc920277f1e59 fs/cifs/connect.c 1458) memalloc_noreclaim_restore(noreclaim_flag);
ca3574bd653ab fs/cifs/connect.c 1459) module_put_and_kthread_exit(0);
^1da177e4c3f4 fs/cifs/connect.c 1460) }
]
|
| 20/2 |
2026/10/17 01:47 |
tool |
git-blame |
0m
Args: map[End:1158 File:fs/smb/client/connect.c Start:1066]
Results: map[Output:946ad1b8b18dd fs/smb/client/connect.c 1066) clean_demultiplex_info(struct TCP_Server_Info *server)
762dfd1057360 fs/cifs/connect.c 1067) {
762dfd1057360 fs/cifs/connect.c 1068) int length;
762dfd1057360 fs/cifs/connect.c 1069)
762dfd1057360 fs/cifs/connect.c 1070) /* take it off the list, if it's not already */
d7d7a66aacd6f fs/cifs/connect.c 1071) spin_lock(&server->srv_lock);
762dfd1057360 fs/cifs/connect.c 1072) list_del_init(&server->tcp_ses_list);
d7d7a66aacd6f fs/cifs/connect.c 1073) spin_unlock(&server->srv_lock);
762dfd1057360 fs/cifs/connect.c 1074)
212253367dc7b fs/cifs/connect.c 1075) cancel_delayed_work_sync(&server->echo);
c65eae6f61d17 fs/smb/client/connect.c 1076) cancel_delayed_work_sync(&server->reconnect);
212253367dc7b fs/cifs/connect.c 1077)
d7d7a66aacd6f fs/cifs/connect.c 1078) spin_lock(&server->srv_lock);
762dfd1057360 fs/cifs/connect.c 1079) server->tcpStatus = CifsExiting;
d7d7a66aacd6f fs/cifs/connect.c 1080) spin_unlock(&server->srv_lock);
762dfd1057360 fs/cifs/connect.c 1081) wake_up_all(&server->response_q);
762dfd1057360 fs/cifs/connect.c 1082)
2d86dbc97094e fs/cifs/connect.c 1083) /* check if we have blocked requests that need to free */
fc40f9cf82890 fs/cifs/connect.c 1084) spin_lock(&server->req_lock);
2d86dbc97094e fs/cifs/connect.c 1085) if (server->credits <= 0)
2d86dbc97094e fs/cifs/connect.c 1086) server->credits = 1;
fc40f9cf82890 fs/cifs/connect.c 1087) spin_unlock(&server->req_lock);
762dfd1057360 fs/cifs/connect.c 1088) /*
762dfd1057360 fs/cifs/connect.c 1089) * Although there should not be any requests blocked on this queue it
762dfd1057360 fs/cifs/connect.c 1090) * can not hurt to be paranoid and try to wake up requests that may
762dfd1057360 fs/cifs/connect.c 1091) * haven been blocked when more than 50 at time were on the wire to the
762dfd1057360 fs/cifs/connect.c 1092) * same server - they now will see the session is in exit state and get
762dfd1057360 fs/cifs/connect.c 1093) * out of SendReceive.
762dfd1057360 fs/cifs/connect.c 1094) */
762dfd1057360 fs/cifs/connect.c 1095) wake_up_all(&server->request_q);
762dfd1057360 fs/cifs/connect.c 1096) /* give those requests time to exit */
762dfd1057360 fs/cifs/connect.c 1097) msleep(125);
050b8c374019c fs/cifs/connect.c 1098) if (cifs_rdma_enabled(server))
050b8c374019c fs/cifs/connect.c 1099) smbd_destroy(server);
762dfd1057360 fs/cifs/connect.c 1100) if (server->ssocket) {
762dfd1057360 fs/cifs/connect.c 1101) sock_release(server->ssocket);
762dfd1057360 fs/cifs/connect.c 1102) server->ssocket = NULL;
762dfd1057360 fs/cifs/connect.c 1103) }
762dfd1057360 fs/cifs/connect.c 1104)
762dfd1057360 fs/cifs/connect.c 1105) if (!list_empty(&server->pending_mid_q)) {
762dfd1057360 fs/cifs/connect.c 1106) struct mid_q_entry *mid_entry;
762dfd1057360 fs/cifs/connect.c 1107) struct list_head *tmp, *tmp2;
21dcbc17eba3c fs/smb/client/connect.c 1108) LIST_HEAD(dispose_list);
762dfd1057360 fs/cifs/connect.c 1109)
f3ba7c9b0421e fs/smb/client/connect.c 1110) spin_lock(&server->mid_queue_lock);
762dfd1057360 fs/cifs/connect.c 1111) list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
762dfd1057360 fs/cifs/connect.c 1112) mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
bf1bc694b6b0c fs/cifs/connect.c 1113) cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid);
87fba18abbb84 fs/smb/client/connect.c 1114) smb_get_mid(mid_entry);
7c9421e1a9ce8 fs/cifs/connect.c 1115) mid_entry->mid_state = MID_SHUTDOWN;
762dfd1057360 fs/cifs/connect.c 1116) list_move(&mid_entry->qhead, &dispose_list);
3fd8ec2fc93b0 fs/smb/client/connect.c 1117) mid_entry->deleted_from_q = true;
762dfd1057360 fs/cifs/connect.c 1118) }
f3ba7c9b0421e fs/smb/client/connect.c 1119) spin_unlock(&server->mid_queue_lock);
762dfd1057360 fs/cifs/connect.c 1120)
762dfd1057360 fs/cifs/connect.c 1121) /* now walk dispose list and issue callbacks */
762dfd1057360 fs/cifs/connect.c 1122) list_for_each_safe(tmp, tmp2, &dispose_list) {
762dfd1057360 fs/cifs/connect.c 1123) mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
bf1bc694b6b0c fs/cifs/connect.c 1124) cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid);
762dfd1057360 fs/cifs/connect.c 1125) list_del_init(&mid_entry->qhead);
87fba18abbb84 fs/smb/client/connect.c 1126) mid_execute_callback(server, mid_entry);
87fba18abbb84 fs/smb/client/connect.c 1127) release_mid(server, mid_entry);
762dfd1057360 fs/cifs/connect.c 1128) }
762dfd1057360 fs/cifs/connect.c 1129) /* 1/8th of sec is more than enough time for them to exit */
762dfd1057360 fs/cifs/connect.c 1130) msleep(125);
762dfd1057360 fs/cifs/connect.c 1131) }
762dfd1057360 fs/cifs/connect.c 1132)
762dfd1057360 fs/cifs/connect.c 1133) if (!list_empty(&server->pending_mid_q)) {
762dfd1057360 fs/cifs/connect.c 1134) /*
762dfd1057360 fs/cifs/connect.c 1135) * mpx threads have not exited yet give them at least the smb
762dfd1057360 fs/cifs/connect.c 1136) * send timeout time for long ops.
762dfd1057360 fs/cifs/connect.c 1137) *
762dfd1057360 fs/cifs/connect.c 1138) * Due to delays on oplock break requests, we need to wait at
762dfd1057360 fs/cifs/connect.c 1139) * least 45 seconds before giving up on a request getting a
762dfd1057360 fs/cifs/connect.c 1140) * response and going ahead and killing cifsd.
762dfd1057360 fs/cifs/connect.c 1141) */
f96637be08114 fs/cifs/connect.c 1142) cifs_dbg(FYI, "Wait for exit from demultiplex thread\n");
762dfd1057360 fs/cifs/connect.c 1143) msleep(46000);
762dfd1057360 fs/cifs/connect.c 1144) /*
762dfd1057360 fs/cifs/connect.c 1145) * If threads still have not exited they are probably never
762dfd1057360 fs/cifs/connect.c 1146) * coming home not much else we can do but free the memory.
762dfd1057360 fs/cifs/connect.c 1147) */
762dfd1057360 fs/cifs/connect.c 1148) }
762dfd1057360 fs/cifs/connect.c 1149)
ef7134c7fc48e fs/smb/client/connect.c 1150) put_net(cifs_net_ns(server));
c88f7dcd6d642 fs/cifs/connect.c 1151) kfree(server->leaf_fullpath);
fa2f9906a7b33 fs/smb/client/connect.c 1152) kfree(server->hostname);
111a2b8717efb fs/smb/client/connect.c 1153) kfree_sensitive(server);
762dfd1057360 fs/cifs/connect.c 1154)
762dfd1057360 fs/cifs/connect.c 1155) length = atomic_dec_return(&tcpSesAllocCount);
762dfd1057360 fs/cifs/connect.c 1156) if (length > 0)
11d83360452ea fs/cifs/connect.c 1157) mempool_resize(cifs_req_poolp, length + cifs_min_rcv);
762dfd1057360 fs/cifs/connect.c 1158) }
]
|
| 21/2 |
2026/10/17 01:47 |
llm |
expert |
0m
Model:
Tokens:
input: 44715
output: 33
thoughts: 1436
Thoughts: **The Cascade of Errors: A Deep Dive into the CIFS KASAN Splat**
My thought process began with dissecting the report, specifically focusing on the critical KASAN splat. I immediately zeroed in on the console message immediately preceding the crash: `CIFS: VFS: \\172.20.20.170 Error -512 sending data on socket to server`. My internal knowledge base flagged `-512` as `-ERESTARTSYS`, a signal indicating that the mounting process (`syz.3.92/6393`) was interrupted by a signal while attempting to send data over the network socket. This interruption likely occurred during the SMB2 negotiate or session setup phases within `dfs_mount_share` and subsequently `cifs_mount_get_session`. The `-ERESTARTSYS` return value then correctly triggered error cleanup in `cifs_mount`, leading to a call to `cifs_mount_put_conns` and ultimately `cifs_put_tcp_session`.
I then meticulously traced the execution path within `cifs_put_tcp_session`:
1. The `server->srv_count` was decremented to zero, and the `server` object was removed from the `cifs_tcp_ses_list`.
2. Delayed work items, `server->echo` and `server->reconnect`, were cancelled using `cancel_delayed_work_sync`.
3. Crucially, `server->tcpStatus` was set to `CifsExiting`.
At this juncture, my attention turned to another concurrent thread: `cifs_demultiplex_thread` (task 6394). I hypothesized about its state. It could have been woken up (given that `wake_up_process(tcp_ses->tsk)` was called in `cifs_get_tcp_session`), or it could have just returned from `cifs_read_from_socket`, or perhaps it hadn't even entered it yet, or `cifs_read_from_socket` returned an error like `-EAGAIN` or `-ERESTARTSYS` or a reconnect scenario. The key question became how `cifs_demultiplex_thread` would react to `server->tcpStatus` being set to `CifsExiting`.
I examined the relevant loop in `cifs_demultiplex_thread`: `while (server->tcpStatus != CifsExiting)`. I also noted the check within `cifs_readv_from_socket`: `if (server->tcpStatus == CifsExiting) return -ESHUTDOWN;`. It became clear that once `cifs_put_tcp_session` set `server->tcpStatus = CifsExiting;` at line 1737, if `cifs_demultiplex_thread` then checked this condition (at line 1284 or within `cifs_readv_from_socket`), it would indeed exit its `while` loop.
Following the thread's exit from the loop, I observed its subsequent actions:
* Buffer deallocation: `cifs_buf_release(server->bigbuf)` and `cifs_small_buf_release(server->smallbuf)`.
* Wake-up mechanism: `task_to_wake = xchg(&server->tsk, NULL);` (releasing the demultiplex task).
* Cleanup: `clean_demultiplex_info(server)`.
My investigation into `clean_demultiplex_info(server)` revealed the critical `msleep(125)` at line 1097, followed by socket closure and, most importantly, `kfree_sensitive(server);` at line 1153.
This is where the race condition materialized in my mind. I posited that if the `cifs_put_tcp_session` task (6393) was preempted *immediately* after setting `server->tcpStatus = CifsExiting;` and unlocking `server->srv_lock` (at line 1738), and if this preemption lasted for approximately 125 milliseconds – a plausible duration given a `PREEMPT(full)` kernel configuration – then the `cifs_demultiplex_thread` (6394) would have ample time to execute `clean_demultiplex_info(server)` and, critically, free the `server` object using `kfree_sensitive(server)`.
The ensuing catastrophe would occur when task 6393 resumed execution at line 1740, attempting to access the now-freed `server` object. The subsequent lines:
* `cifs_crypto_secmech_release(server);`
* `kfree_sensitive(server->session_key.response);`
* `server->session_key.response = NULL;`
* `server->session_key.len = 0;`
* `task = xchg(&server->tsk, NULL);`
All these operations would be attempting to dereference memory that has already been deallocated, leading directly to the KASAN reports. I specifically linked the observed KASAN reports to these lines: the reads within `cifs_crypto_secmech_release` (offsets 1168 and 1176) and the reads/writes on `server->session_key.response` (offset 1136) and the atomic RMW on `server->tsk` (line 1746). I also considered why lines 1744 and 1746 might not have individual KASAN reports – perhaps due to the order of reporting, subsequent accesses hitting the same freed object, or syzkaller's reporting limits.
Finally, I noted the need to consult commit `a5c3e1c725af9` to understand the original intent of the code being modified, as this could shed light on the conditions that led to this specific race.
|
| 22/2 |
2026/10/17 01:47 |
tool |
git-show |
0m
Args: map[Commit:a5c3e1c725af9]
Results: map[Output:commit a5c3e1c725af9e84deceb3c33939ca4ffe3fefc8
Author: Steve French <smfrench@gmail.com>
Date: Tue Sep 16 04:16:19 2014 -0500
Revert "cifs: No need to send SIGKILL to demux_thread during umount"
This reverts commit 52a36244443eabb594bdb63622ff2dd7a083f0e2.
Causes rmmod to fail for at least 7 seconds after unmount which
makes automated testing a little harder when reloading cifs.ko
between test runs.
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
CC: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve French <smfrench@gmail.com>
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 8a9fded7c135..36ca2045009b 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -837,6 +837,7 @@ cifs_demultiplex_thread(void *p)
struct TCP_Server_Info *server = p;
unsigned int pdu_length;
char *buf = NULL;
+ struct task_struct *task_to_wake = NULL;
struct mid_q_entry *mid_entry;
current->flags |= PF_MEMALLOC;
@@ -927,7 +928,19 @@ cifs_demultiplex_thread(void *p)
if (server->smallbuf) /* no sense logging a debug message if NULL */
cifs_small_buf_release(server->smallbuf);
+ task_to_wake = xchg(&server->tsk, NULL);
clean_demultiplex_info(server);
+
+ /* if server->tsk was NULL then wait for a signal before exiting */
+ if (!task_to_wake) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ while (!signal_pending(current)) {
+ schedule();
+ set_current_state(TASK_INTERRUPTIBLE);
+ }
+ set_current_state(TASK_RUNNING);
+ }
+
module_put_and_exit(0);
}
@@ -2050,6 +2063,8 @@ cifs_find_tcp_session(struct smb_vol *vol)
static void
cifs_put_tcp_session(struct TCP_Server_Info *server)
{
+ struct task_struct *task;
+
spin_lock(&cifs_tcp_ses_lock);
if (--server->srv_count > 0) {
spin_unlock(&cifs_tcp_ses_lock);
@@ -2073,6 +2088,10 @@ cifs_put_tcp_session(struct TCP_Server_Info *server)
kfree(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
+
+ task = xchg(&server->tsk, NULL);
+ if (task)
+ force_sig(SIGKILL, task);
}
static struct TCP_Server_Info *
]
|
| 23/2 |
2026/10/17 01:47 |
llm |
expert |
0m
Model:
Tokens:
input: 47074
output: 38
thoughts: 827
Thoughts: **A Critical Use-After-Free Vulnerability in CIFS TCP Session Management**
I've uncovered a severe vulnerability within the CIFS (Common Internet File System) TCP session handling, specifically in the `cifs_put_tcp_session` function. The core of the issue lies in a race condition that allows for a use-after-free exploit on the `struct TCP_Server_Info` object.
Here's how the breakdown of my thought process unfolded:
Firstly, I pinpointed the exact root cause. When `cifs_put_tcp_session` is invoked with the `from_reconnect` flag, it immediately sets `server->tcpStatus` to `CifsExiting`. This action triggers the `cifs_demultiplex_thread` to exit its primary loop. Crucially, it then proceeds to execute `task_to_wake = xchg(&server->tsk, NULL);` and `clean_demultiplex_info(server);`. The latter function, `clean_demultiplex_info`, is responsible for freeing the `server` structure itself using `kfree_sensitive(server)`.
The critical flaw emerges *immediately after* this free. `cifs_put_tcp_session` continues its execution, attempting to access members of the `server` structure that has already been deallocated. This leads to a cascade of dangerous operations:
* `cifs_crypto_secmech_release(server)`: This function attempts to read `server->secmech.enc` and `server->secmech.dec`. If these pointers are non-NULL, it calls `crypto_free_aead`, which effectively frees an arbitrary pointer or executes a destructor. More alarmingly, it then writes `NULL` (which translates to 8 bytes of zero) to these offsets within the freed memory.
* `kfree_sensitive(server->session_key.response)`: This attempts to free the `response` buffer pointed to by `server->session_key.response`. Following the free, it writes `NULL` (8 bytes) to `server->session_key.response` and `0` (4 bytes) to `server->session_key.len`. These are writes to already freed memory.
* `task = xchg(&server->tsk, NULL)`: This atomic operation attempts to read the value of `server->tsk` and replace it with `NULL`. If the read value (`task`) is non-NULL, it then calls `send_sig(SIGKILL, task, 1)`. This is a critical point: if the freed `server` structure's memory has been reallocated by the kernel for a *new* `TCP_Server_Info` object, this `xchg` operation will read and write to the *new* object's memory, and the `send_sig` call will be made on a pointer that is now part of the new, valid structure, potentially leading to a controlled crash or more.
The sequence of events – freeing `server`, then accessing its members, calling arbitrary frees (`crypto_free_aead`, `kfree_sensitive`), writing `NULL` to freed memory, and performing an atomic exchange followed by a `send_sig` call on a potentially reallocated chunk – constitutes a textbook and highly potent Use-After-Free vulnerability. The attacker gains the ability to trigger an arbitrary free, write zero bytes, perform pointer dereferences with controlled values (via `crypto_free_aead`, `kfree_sensitive`, and `send_sig`), all within the context of the `kmalloc-4k` allocation used for `TCP_Server_Info`.
Therefore, my conclusion is unequivocal: the vulnerability is definitely `Exploitable`, and it undeniably leads to `DenialOfService`.
My next crucial step is to meticulously examine all call sites of `cifs_put_tcp_session` across the entire kernel source tree. I will use `codesearch-find-references` to identify every place where this function is invoked, as this will be key to understanding the precise conditions and trigger dimensions for this exploit.
|
| 24/2 |
2026/10/17 01:47 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:cifs_put_tcp_session]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__cifs_put_smb_ses SourceFile:fs/smb/client/connect.c SourceLine:2172 SourceSnippet:2167: for (i = 1; i < ses->chan_count; i++) {
2168: if (ses->chans[i].iface) {
2169: kref_put(&ses->chans[i].iface->refcount, release_iface);
2170: ses->chans[i].iface = NULL;
2171: }
2172: cifs_put_tcp_session(ses->chans[i].server, 0);
2173: ses->chans[i].server = NULL;
2174: }
2175:
2176: /* we now account for primary channel in iface->refcount */
2177: if (ses->chans[0].iface) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__cifs_put_smb_ses SourceFile:fs/smb/client/connect.c SourceLine:2183 SourceSnippet:2178: kref_put(&ses->chans[0].iface->refcount, release_iface);
2179: ses->chans[0].server = NULL;
2180: }
2181:
2182: sesInfoFree(ses);
2183: cifs_put_tcp_session(server, 0);
2184: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_chan_skip_or_disable SourceFile:fs/smb/client/smb2pdu.c SourceLine:204 SourceSnippet: 199:
200: /* mark primary server as needing reconnect */
201: pserver = server->primary_server;
202: cifs_signal_cifsd_for_reconnect(pserver, false);
203:
204: cifs_put_tcp_session(server, from_reconnect);
205: skip_terminate:
206: return -EHOSTDOWN;
207: }
208:
209: cifs_decrease_secondary_channels(ses, disable_mchan);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_construct_tcon SourceFile:fs/smb/client/connect.c SourceLine:4273 SourceSnippet:4268: spin_unlock(&cifs_tcp_ses_lock);
4269:
4270: ses = cifs_get_smb_ses(master_tcon->ses->server, ctx);
4271: if (IS_ERR(ses)) {
4272: tcon = ERR_CAST(ses);
4273: cifs_put_tcp_session(master_tcon->ses->server, 0);
4274: goto out;
4275: }
4276:
4277: #ifdef CONFIG_CIFS_DFS_UPCALL
4278: spin_lock(&master_tcon->tc_lock);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_decrease_secondary_channels SourceFile:fs/smb/client/sess.c SourceLine:344 SourceSnippet: 339: if (server) {
340: if (!server->terminate) {
341: server->terminate = true;
342: cifs_signal_cifsd_for_reconnect(server, false);
343: }
344: cifs_put_tcp_session(server, false);
345: }
346:
347: spin_lock(&ses->chan_lock);
348: }
349:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_get_smb_ses SourceFile:fs/smb/client/connect.c SourceLine:2408 SourceSnippet:2403: spin_lock(&ses->chan_lock);
2404: }
2405: spin_unlock(&ses->chan_lock);
2406:
2407: /* existing SMB ses has a server reference already */
2408: cifs_put_tcp_session(server, 0);
2409: free_xid(xid);
2410: return ses;
2411: }
2412:
2413: rc = -ENOMEM;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_get_tcp_session SourceFile:fs/smb/client/connect.c SourceLine:1932 SourceSnippet:1927: put_net(cifs_net_ns(tcp_ses));
1928:
1929: out_err:
1930: if (tcp_ses) {
1931: if (SERVER_IS_CHAN(tcp_ses))
1932: cifs_put_tcp_session(tcp_ses->primary_server, false);
1933: kfree(tcp_ses->hostname);
1934: kfree(tcp_ses->leaf_fullpath);
1935: if (tcp_ses->ssocket)
1936: sock_release(tcp_ses->ssocket);
1937: smbd_destroy(tcp_ses);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_mount_put_conns SourceFile:fs/smb/client/connect.c SourceLine:3554 SourceSnippet:3549: if (mnt_ctx->tcon)
3550: cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx);
3551: else if (mnt_ctx->ses)
3552: cifs_put_smb_ses(mnt_ctx->ses);
3553: else if (mnt_ctx->server)
3554: cifs_put_tcp_session(mnt_ctx->server, 0);
3555: mnt_ctx->ses = NULL;
3556: mnt_ctx->tcon = NULL;
3557: mnt_ctx->server = NULL;
3558: atomic_andnot(CIFS_MOUNT_POSIX_PATHS, &cifs_sb->mnt_cifs_flags);
3559: free_xid(mnt_ctx->xid);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_put_tcp_session SourceFile:fs/smb/client/connect.c SourceLine:1734 SourceSnippet:1729: else
1730: cancel_delayed_work_sync(&server->reconnect);
1731:
1732: /* For secondary channels, we pick up ref-count on the primary server */
1733: if (SERVER_IS_CHAN(server))
1734: cifs_put_tcp_session(server->primary_server, from_reconnect);
1735:
1736: spin_lock(&server->srv_lock);
1737: server->tcpStatus = CifsExiting;
1738: spin_unlock(&server->srv_lock);
1739:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_ses_add_channel SourceFile:fs/smb/client/sess.c SourceLine:629 SourceSnippet: 624:
625: mutex_unlock(&ses->session_mutex);
626:
627: out:
628: if (rc && chan->server) {
629: cifs_put_tcp_session(chan->server, 0);
630:
631: spin_lock(&ses->chan_lock);
632:
633: /* we rely on all bits beyond chan_count to be clear */
634: cifs_chan_clear_need_reconnect(ses, chan->server);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_signal_cifsd_for_reconnect SourceFile:fs/smb/client/connect.c SourceLine:192 SourceSnippet: 187: spin_lock(&cifs_tcp_ses_lock);
188: list_for_each_entry_safe(server, nserver, &reco, rlist) {
189: list_del_init(&server->rlist);
190: set_need_reco(server);
191: spin_unlock(&cifs_tcp_ses_lock);
192: cifs_put_tcp_session(server, 0);
193: spin_lock(&cifs_tcp_ses_lock);
194: }
195: spin_unlock(&cifs_tcp_ses_lock);
196: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb2_reconnect_server SourceFile:fs/smb/client/smb2pdu.c SourceLine:4303 SourceSnippet:4298: /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */
4299: mutex_lock(&pserver->reconnect_mutex);
4300:
4301: /* if the server is marked for termination, drop the ref count here */
4302: if (server->terminate) {
4303: cifs_put_tcp_session(server, true);
4304: mutex_unlock(&pserver->reconnect_mutex);
4305: return;
4306: }
4307:
4308: INIT_LIST_HEAD(&tmp_list);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb2_reconnect_server SourceFile:fs/smb/client/smb2pdu.c SourceLine:4406 SourceSnippet:4401: if (resched)
4402: cifs_requeue_server_reconn(server);
4403: mutex_unlock(&pserver->reconnect_mutex);
4404:
4405: /* now we can safely release srv struct */
4406: cifs_put_tcp_session(server, true);
4407: }
]] TruncatedOutput:false]
|
| 25/2 |
2026/10/17 01:47 |
llm |
expert |
0m
Model:
Tokens:
input: 50851
output: 78
thoughts: 389
Thoughts: **Investigating the Lifespan and Creation of CIFS TCP Sessions**
My primary goal here is to thoroughly understand the lifecycle of a CIFS TCP session, represented by `struct TCP_Server_Info`. To achieve this, I'm meticulously examining every instance where `cifs_put_tcp_session` is invoked. This will naturally lead me to explore how these `TCP_Server_Info` structures are actually brought into existence and, consequently, how they are eventually deallocated.
A crucial aspect of this investigation is to determine if an unprivileged user, or a user operating within a user namespace, can initiate a CIFS mount. To probe this, I'm starting by looking at the definitions of `cifs_fs_type` and `smb3_fs_type`, which are defined in `fs/smb/client/cifsfs.c`.
Upon reviewing their definitions, I observe:
```c
struct file_system_type cifs_fs_type = {
.owner = THIS_MODULE,
.name = "cifs",
.init_fs_context = smb3_init_fs_context,
.parameters = smb3_fs_parameters,
.kill_sb = cifs_kill_sb,
.fs_flags = FS_RENAME_DOES_D_MOVE,
};
struct file_system_type smb3_fs_type = {
.owner = THIS_MODULE,
.name = "smb3",
.init_fs_context = smb3_init_fs_context,
.parameters = smb3_fs_parameters,
.kill_sb = cifs_kill_sb,
.fs_flags = FS_RENAME_DOES_D_MOVE,
};
```
A key observation here is that the `.fs_flags` member for both `cifs_fs_type` and `smb3_fs_type` **does not include `FS_USERNS_MOUNT`**. This immediately raises a question: when a `mount()` or `fsopen()` / `fsmount()` operation is performed for a filesystem that *lacks* the `FS_USERNS_MOUNT` flag, what specific capability checks are being enforced? To answer this, my next step is to delve into the `fsopen` and `do_new_mount` functions, which I expect to find within `fs/namespace.c` and `fs/fsopen.c` respectively. This will allow me to trace the execution path and understand the security implications for user namespace mounts.
|
| 26/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namespace.c Name:do_new_mount]
Results: map[SourceCode:3910: /*
3911: * create a new mount for userspace and request it to be added into the
3912: * namespace's tree
3913: */
3914: static int do_new_mount(const struct path *path, const char *fstype,
3915: int sb_flags, int mnt_flags,
3916: const char *name, void *data)
3917: {
3918: struct file_system_type *type;
3919: struct fs_context *fc;
3920: const char *subtype = NULL;
3921: int err = 0;
3922:
3923: if (!fstype)
3924: return -EINVAL;
3925:
3926: type = get_fs_type(fstype);
3927: if (!type)
3928: return -ENODEV;
3929:
3930: if (type->fs_flags & FS_HAS_SUBTYPE) {
3931: subtype = strchr(fstype, '.');
3932: if (subtype) {
3933: subtype++;
3934: if (!*subtype) {
3935: put_filesystem(type);
3936: return -EINVAL;
3937: }
3938: }
3939: }
3940:
3941: fc = fs_context_for_mount(type, sb_flags);
3942: put_filesystem(type);
3943: if (IS_ERR(fc))
3944: return PTR_ERR(fc);
3945:
3946: /*
3947: * Indicate to the filesystem that the mount request is coming
3948: * from the legacy mount system call.
3949: */
3950: fc->oldapi = true;
3951:
3952: if (subtype)
3953: err = vfs_parse_fs_string(fc, "subtype", subtype);
3954: if (!err && name)
3955: err = vfs_parse_fs_string(fc, "source", name);
3956: if (!err)
3957: err = parse_monolithic_mount_data(fc, data);
3958: if (!err && !mount_capable(fc))
3959: err = -EPERM;
3960: if (!err)
3961: err = do_new_mount_fc(fc, path, mnt_flags);
3962:
3963: put_fs_context(fc);
3964: return err;
3965: }
SourceFile:fs/namespace.c]
|
| 27/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/fsopen.c Name:SYSCALL_DEFINE2]
Results: map[SourceCode: SourceFile:]
|
| 28/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 52124
output: 72
thoughts: 33
Thoughts: **My Thought Process on Optimizing CIFS Session Handling**
My initial instinct is to investigate the `mount_capable` function within `fs/namespace.c`. I want to understand its role, particularly how it might be influencing or interacting with CIFS session establishment and management. Is it a gatekeeper, a configurator, or something else entirely? I need to get a clear picture of its responsibilities to ensure I'm not overlooking a critical piece of the puzzle.
Simultaneously, I'm directing my attention to all the places `cifs_get_tcp_session` is being called. This is a direct approach to identifying every instance where a new TCP session for CIFS is being initiated. By examining these call sites, I'm hoping to uncover:
* **Patterns of Usage:** Are sessions being requested frequently, or are there periods of dormancy? This could point to opportunities for caching or session reuse.
* **Context of Calls:** What triggers the need for a new session? Is it during mount, during file operations, or perhaps for specific authentication mechanisms? Understanding the context will be crucial for designing any optimizations.
* **Potential Redundancies:** Are there scenarios where multiple calls to `cifs_get_tcp_session` might be happening unnecessarily within a short timeframe? This is a prime candidate for optimization.
* **Error Handling and Recovery:** How are these calls being handled when they fail? Are there graceful fallbacks or retries that could be improved?
By correlating the information from `mount_capable` with the call sites of `cifs_get_tcp_session`, I aim to build a comprehensive understanding of the current session management logic and identify specific areas where performance improvements or resource optimizations can be made. This dual approach allows me to both understand the overarching policy (`mount_capable`) and the granular execution (`cifs_get_tcp_session` callers) for a thorough analysis.
|
| 29/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namespace.c Name:mount_capable]
Results: map[SourceCode: 799: bool mount_capable(struct fs_context *fc)
800: {
801: if (!(fc->fs_type->fs_flags & FS_USERNS_MOUNT))
802: return capable(CAP_SYS_ADMIN);
803: else
804: return ns_capable(fc->user_ns, CAP_SYS_ADMIN);
805: }
SourceFile:fs/super.c]
|
| 30/2 |
2026/10/17 01:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:cifs_get_tcp_session]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_mount_get_session SourceFile:fs/smb/client/connect.c SourceLine:3579 SourceSnippet:3574: goto out;
3575: }
3576: ctx = mnt_ctx->fs_ctx;
3577:
3578: /* get a reference to a tcp session */
3579: server = cifs_get_tcp_session(ctx, NULL);
3580: if (IS_ERR(server)) {
3581: rc = PTR_ERR(server);
3582: server = NULL;
3583: goto out;
3584: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_ses_add_channel SourceFile:fs/smb/client/sess.c SourceLine:599 SourceSnippet: 594: /* reuse master con client guid */
595: memcpy(&ctx->client_guid, ses->server->client_guid,
596: sizeof(ctx->client_guid));
597: ctx->use_client_guid = true;
598:
599: chan_server = cifs_get_tcp_session(ctx, ses->server);
600:
601: spin_lock(&ses->chan_lock);
602: chan = &ses->chans[ses->chan_count];
603: chan->server = chan_server;
604: if (IS_ERR(chan->server)) {
]] TruncatedOutput:false]
|
| 31/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 52837
output: 227
thoughts: 388
Thoughts: **The Unexpected Possibility of Remote Triggering of `cifs_put_tcp_session`**
My initial reaction was one of incredulity: could a remote SMB server actually provoke a call to `cifs_put_tcp_session` on an already established CIFS mount or connection? This seemed counterintuitive. I immediately decided that a thorough investigation of every single invocation of `cifs_put_tcp_session` was necessary to confirm or deny this hypothesis.
My process then involved meticulously examining each reference to the `cifs_put_tcp_session` function. I identified five key locations:
1. `cifs_chan_skip_or_disable` in `fs/smb/client/smb2pdu.c` at line 204.
2. `cifs_decrease_secondary_channels` in `fs/smb/client/sess.c` at line 344.
3. `cifs_ses_add_channel` in `fs/smb/client/sess.c` at line 629.
4. `smb2_reconnect_server` in `fs/smb/client/smb2pdu.c` at lines 4303 and 4406.
5. `cifs_signal_cifsd_for_reconnect` in `fs/smb/client/connect.c` at line 192.
With these locations identified, I felt it crucial to delve deeper into the context of each of these calls. My next step was to scrutinize the code within these specific functions: `cifs_signal_cifsd_for_reconnect`, `smb2_reconnect_server`, `cifs_chan_skip_or_disable`, `cifs_decrease_secondary_channels`, and `cifs_ses_add_channel`. To facilitate this, I planned to use `codesearch-definition-source` on each of these functions to gain the most precise understanding of their behavior and how they might, directly or indirectly, lead to the `cifs_put_tcp_session` call. My ultimate goal was to trace the execution flow and determine if any of these paths could be influenced by actions originating from the remote SMB server.
|
| 32/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_signal_cifsd_for_reconnect]
Results: map[SourceCode: 138: /*
139: * Update the tcpStatus for the server.
140: * This is used to signal the cifsd thread to call cifs_reconnect
141: * ONLY cifsd thread should call cifs_reconnect. For any other
142: * thread, use this function
143: *
144: * @server: the tcp ses for which reconnect is needed
145: * @all_channels: if this needs to be done for all channels
146: */
147: void
148: cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server,
149: bool all_channels)
150: {
151: struct TCP_Server_Info *nserver;
152: struct cifs_ses *ses;
153: LIST_HEAD(reco);
154: int i;
155:
156: /* if we need to signal just this channel */
157: if (!all_channels) {
158: set_need_reco(server);
159: return;
160: }
161:
162: if (SERVER_IS_CHAN(server))
163: server = server->primary_server;
164: scoped_guard(spinlock, &cifs_tcp_ses_lock) {
165: set_need_reco(server);
166: list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
167: spin_lock(&ses->ses_lock);
168: if (ses->ses_status == SES_EXITING) {
169: spin_unlock(&ses->ses_lock);
170: continue;
171: }
172: spin_lock(&ses->chan_lock);
173: for (i = 1; i < ses->chan_count; i++) {
174: nserver = ses->chans[i].server;
175: if (!nserver)
176: continue;
177: if (!list_empty(&nserver->rlist))
178: continue;
179: nserver->srv_count++;
180: list_add(&nserver->rlist, &reco);
181: }
182: spin_unlock(&ses->chan_lock);
183: spin_unlock(&ses->ses_lock);
184: }
185: }
186:
187: spin_lock(&cifs_tcp_ses_lock);
188: list_for_each_entry_safe(server, nserver, &reco, rlist) {
189: list_del_init(&server->rlist);
190: set_need_reco(server);
191: spin_unlock(&cifs_tcp_ses_lock);
192: cifs_put_tcp_session(server, 0);
193: spin_lock(&cifs_tcp_ses_lock);
194: }
195: spin_unlock(&cifs_tcp_ses_lock);
196: }
SourceFile:fs/smb/client/connect.c]
|
| 33/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/smb2pdu.c Name:smb2_reconnect_server]
Results: map[SourceCode:4273: void smb2_reconnect_server(struct work_struct *work)
4274: {
4275: struct TCP_Server_Info *server = container_of(work,
4276: struct TCP_Server_Info, reconnect.work);
4277: struct TCP_Server_Info *pserver;
4278: struct cifs_ses *ses, *ses2;
4279: struct cifs_tcon *tcon, *tcon2;
4280: struct list_head tmp_list, tmp_ses_list;
4281: bool ses_exist = false;
4282: bool tcon_selected = false;
4283: int rc;
4284: bool resched = false;
4285:
4286: /* first check if ref count has reached 0, if not inc ref count */
4287: spin_lock(&cifs_tcp_ses_lock);
4288: if (!server->srv_count) {
4289: spin_unlock(&cifs_tcp_ses_lock);
4290: return;
4291: }
4292: server->srv_count++;
4293: spin_unlock(&cifs_tcp_ses_lock);
4294:
4295: /* If server is a channel, select the primary channel */
4296: pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
4297:
4298: /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */
4299: mutex_lock(&pserver->reconnect_mutex);
4300:
4301: /* if the server is marked for termination, drop the ref count here */
4302: if (server->terminate) {
4303: cifs_put_tcp_session(server, true);
4304: mutex_unlock(&pserver->reconnect_mutex);
4305: return;
4306: }
4307:
4308: INIT_LIST_HEAD(&tmp_list);
4309: INIT_LIST_HEAD(&tmp_ses_list);
4310: cifs_dbg(FYI, "Reconnecting tcons and channels\n");
4311:
4312: spin_lock(&cifs_tcp_ses_lock);
4313: list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4314: spin_lock(&ses->ses_lock);
4315: if (ses->ses_status == SES_EXITING) {
4316: spin_unlock(&ses->ses_lock);
4317: continue;
4318: }
4319: spin_unlock(&ses->ses_lock);
4320:
4321: tcon_selected = false;
4322:
4323: list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
4324: if (tcon->need_reconnect || tcon->need_reopen_files) {
4325: spin_lock(&tcon->tc_lock);
4326: tcon->tc_count++;
4327: spin_unlock(&tcon->tc_lock);
4328: trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
4329: netfs_trace_tcon_ref_get_reconnect_server);
4330: list_add_tail(&tcon->rlist, &tmp_list);
4331: tcon_selected = true;
4332: }
4333: }
4334: /*
4335: * IPC has the same lifetime as its session and uses its
4336: * refcount.
4337: */
4338: if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) {
4339: list_add_tail(&ses->tcon_ipc->rlist, &tmp_list);
4340: tcon_selected = true;
4341: cifs_smb_ses_inc_refcount(ses);
4342: }
4343: /*
4344: * handle the case where channel needs to reconnect
4345: * binding session, but tcon is healthy (some other channel
4346: * is active)
4347: */
4348: spin_lock(&ses->chan_lock);
4349: if (!tcon_selected && cifs_chan_needs_reconnect(ses, server)) {
4350: list_add_tail(&ses->rlist, &tmp_ses_list);
4351: ses_exist = true;
4352: cifs_smb_ses_inc_refcount(ses);
4353: }
4354: spin_unlock(&ses->chan_lock);
4355: }
4356: spin_unlock(&cifs_tcp_ses_lock);
4357:
4358: list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) {
4359: rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true);
4360: if (!rc) {
4361: cifs_renegotiate_iosize(server, tcon);
4362: cifs_reopen_persistent_handles(tcon);
4363: } else
4364: resched = true;
4365: list_del_init(&tcon->rlist);
4366: if (tcon->ipc)
4367: cifs_put_smb_ses(tcon->ses);
4368: else
4369: cifs_put_tcon(tcon, netfs_trace_tcon_ref_put_reconnect_server);
4370: }
4371:
4372: if (!ses_exist)
4373: goto done;
4374:
4375: /* allocate a dummy tcon struct used for reconnect */
4376: tcon = tcon_info_alloc(false, netfs_trace_tcon_ref_new_reconnect_server);
4377: if (!tcon) {
4378: resched = true;
4379: list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
4380: list_del_init(&ses->rlist);
4381: cifs_put_smb_ses(ses);
4382: }
4383: goto done;
4384: }
4385: tcon->status = TID_GOOD;
4386: tcon->dummy = true;
4387:
4388: /* now reconnect sessions for necessary channels */
4389: list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
4390: tcon->ses = ses;
4391: rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true);
4392: if (rc)
4393: resched = true;
4394: list_del_init(&ses->rlist);
4395: cifs_put_smb_ses(ses);
4396: }
4397: tconInfoFree(tcon, netfs_trace_tcon_ref_free_reconnect_server);
4398:
4399: done:
4400: cifs_dbg(FYI, "Reconnecting tcons and channels finished\n");
4401: if (resched)
4402: cifs_requeue_server_reconn(server);
4403: mutex_unlock(&pserver->reconnect_mutex);
4404:
4405: /* now we can safely release srv struct */
4406: cifs_put_tcp_session(server, true);
4407: }
SourceFile:fs/smb/client/smb2pdu.c]
|
| 34/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/smb2pdu.c Name:cifs_chan_skip_or_disable]
Results: map[SourceCode: 166: /* helper function for code reuse */
167: static int
168: cifs_chan_skip_or_disable(struct cifs_ses *ses,
169: struct TCP_Server_Info *server,
170: bool from_reconnect, bool disable_mchan)
171: {
172: struct TCP_Server_Info *pserver;
173: unsigned int chan_index;
174:
175: if (SERVER_IS_CHAN(server)) {
176: cifs_dbg(VFS,
177: "server %s does not support multichannel anymore. Skip secondary channel\n",
178: ses->server->hostname);
179:
180: spin_lock(&ses->chan_lock);
181: chan_index = cifs_ses_get_chan_index(ses, server);
182: if (chan_index == CIFS_INVAL_CHAN_INDEX) {
183: spin_unlock(&ses->chan_lock);
184: goto skip_terminate;
185: }
186:
187: ses->chans[chan_index].server = NULL;
188: server->terminate = true;
189: spin_unlock(&ses->chan_lock);
190:
191: /*
192: * signal the channel and its primary server to
193: * reconnect before dropping the above reference of
194: * server by channel, which is done without holding
195: * chan_lock as cifs_put_tcp_session takes a higher
196: * lock i.e. cifs_tcp_ses_lock
197: */
198: cifs_signal_cifsd_for_reconnect(server, false);
199:
200: /* mark primary server as needing reconnect */
201: pserver = server->primary_server;
202: cifs_signal_cifsd_for_reconnect(pserver, false);
203:
204: cifs_put_tcp_session(server, from_reconnect);
205: skip_terminate:
206: return -EHOSTDOWN;
207: }
208:
209: cifs_decrease_secondary_channels(ses, disable_mchan);
210:
211: return 0;
212: }
SourceFile:fs/smb/client/smb2pdu.c]
|
| 35/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/sess.c Name:cifs_decrease_secondary_channels]
Results: map[SourceCode: 288: /*
289: * cifs_decrease_secondary_channels - Reduce the number of active secondary channels
290: * @ses: pointer to the CIFS session structure
291: * @disable_mchan: if true, reduce to a single channel; if false, reduce to chan_max
292: *
293: * This function disables and cleans up extra secondary channels for a CIFS session.
294: * If called during reconfiguration, it reduces the channel count to the new maximum (chan_max).
295: * Otherwise, it disables all but the primary channel.
296: */
297: void
298: cifs_decrease_secondary_channels(struct cifs_ses *ses, bool disable_mchan)
299: {
300: int i, chan_count;
301: struct TCP_Server_Info *server;
302: struct cifs_server_iface *iface;
303:
304: spin_lock(&ses->chan_lock);
305: chan_count = ses->chan_count;
306: if (chan_count == 1)
307: goto done;
308:
309: /* Update the chan_count to the new maximum */
310: if (disable_mchan) {
311: cifs_dbg(FYI, "server does not support multichannel anymore.\n");
312: ses->chan_count = 1;
313: } else {
314: ses->chan_count = ses->chan_max;
315: }
316:
317: /* Disable all secondary channels beyond the new chan_count */
318: for (i = ses->chan_count ; i < chan_count; i++) {
319: iface = ses->chans[i].iface;
320: server = ses->chans[i].server;
321:
322: /*
323: * remove these references first, since we need to unlock
324: * the chan_lock here, since iface_lock is a higher lock
325: */
326: ses->chans[i].iface = NULL;
327: ses->chans[i].server = NULL;
328: spin_unlock(&ses->chan_lock);
329:
330: if (iface) {
331: spin_lock(&ses->iface_lock);
332: iface->num_channels--;
333: if (iface->weight_fulfilled)
334: iface->weight_fulfilled--;
335: kref_put(&iface->refcount, release_iface);
336: spin_unlock(&ses->iface_lock);
337: }
338:
339: if (server) {
340: if (!server->terminate) {
341: server->terminate = true;
342: cifs_signal_cifsd_for_reconnect(server, false);
343: }
344: cifs_put_tcp_session(server, false);
345: }
346:
347: spin_lock(&ses->chan_lock);
348: }
349:
350: /* For extra secondary channels, reset the need reconnect bit */
351: if (ses->chan_count == 1) {
352: cifs_dbg(VFS, "Disable all secondary channels\n");
353: ses->chans_need_reconnect &= 1;
354: } else {
355: cifs_dbg(VFS, "Disable extra secondary channels\n");
356: ses->chans_need_reconnect &= ((1UL << ses->chan_max) - 1);
357: }
358:
359: done:
360: spin_unlock(&ses->chan_lock);
361: }
SourceFile:fs/smb/client/sess.c]
|
| 36/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/sess.c Name:cifs_ses_add_channel]
Results: map[SourceCode: 501: static int
502: cifs_ses_add_channel(struct cifs_ses *ses,
503: struct cifs_server_iface *iface)
504: {
505: struct TCP_Server_Info *chan_server;
506: struct cifs_chan *chan;
507: struct smb3_fs_context *ctx;
508: static const char unc_fmt[] = "\\%s\\foo";
509: struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
510: struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
511: size_t len;
512: int rc;
513: unsigned int xid = get_xid();
514:
515: if (iface->sockaddr.ss_family == AF_INET)
516: cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI4)\n",
517: ses, iface->speed, str_yes_no(iface->rdma_capable),
518: &ipv4->sin_addr);
519: else
520: cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI6)\n",
521: ses, iface->speed, str_yes_no(iface->rdma_capable),
522: &ipv6->sin6_addr);
523:
524: /*
525: * Setup a ctx with mostly the same info as the existing
526: * session and overwrite it with the requested iface data.
527: *
528: * We need to setup at least the fields used for negprot and
529: * sesssetup.
530: *
531: * We only need the ctx here, so we can reuse memory from
532: * the session and server without caring about memory
533: * management.
534: */
535: ctx = kzalloc_obj(*ctx);
536: if (!ctx) {
537: rc = -ENOMEM;
538: goto out_free_xid;
539: }
540:
541: /* Always make new connection for now (TODO?) */
542: ctx->nosharesock = true;
543:
544: /* Auth */
545: ctx->domainauto = ses->domainAuto;
546: ctx->domainname = ses->domainName;
547:
548: ctx->server_hostname = ses->server->hostname;
549:
550: ctx->username = ses->user_name;
551: ctx->password = ses->password;
552: ctx->sectype = ses->sectype;
553: ctx->sign = ses->sign;
554: ctx->unicode = ses->unicode;
555:
556: /* UNC and paths */
557: /* XXX: Use ses->server->hostname? */
558: len = sizeof(unc_fmt) + SERVER_NAME_LEN_WITH_NULL;
559: ctx->UNC = kzalloc(len, GFP_KERNEL);
560: if (!ctx->UNC) {
561: rc = -ENOMEM;
562: goto out_free_ctx;
563: }
564: scnprintf(ctx->UNC, len, unc_fmt, ses->ip_addr);
565: ctx->prepath = "";
566:
567: /* Reuse same version as master connection */
568: ctx->vals = ses->server->vals;
569: ctx->ops = ses->server->ops;
570:
571: ctx->noblocksnd = ses->server->noblocksnd;
572: ctx->noautotune = ses->server->noautotune;
573: ctx->sockopt_tcp_nodelay = ses->server->tcp_nodelay;
574: ctx->echo_interval = ses->server->echo_interval / HZ;
575: ctx->max_credits = ses->server->max_credits;
576: ctx->min_offload = ses->server->min_offload;
577: ctx->compress = ses->server->compression.requested;
578: ctx->dfs_conn = ses->server->dfs_conn;
579: ctx->ignore_signature = ses->server->ignore_signature;
580: ctx->leaf_fullpath = ses->server->leaf_fullpath;
581: ctx->rootfs = ses->server->noblockcnt;
582: ctx->retrans = ses->server->retrans;
583:
584: /*
585: * This will be used for encoding/decoding user/domain/pw
586: * during sess setup auth.
587: */
588: ctx->local_nls = ses->local_nls;
589:
590: /* Use RDMA if possible */
591: ctx->rdma = iface->rdma_capable;
592: memcpy(&ctx->dstaddr, &iface->sockaddr, sizeof(ctx->dstaddr));
593:
594: /* reuse master con client guid */
595: memcpy(&ctx->client_guid, ses->server->client_guid,
596: sizeof(ctx->client_guid));
597: ctx->use_client_guid = true;
598:
599: chan_server = cifs_get_tcp_session(ctx, ses->server);
600:
601: spin_lock(&ses->chan_lock);
602: chan = &ses->chans[ses->chan_count];
603: chan->server = chan_server;
604: if (IS_ERR(chan->server)) {
605: rc = PTR_ERR(chan->server);
606: chan->server = NULL;
607: spin_unlock(&ses->chan_lock);
608: goto out;
609: }
610: chan->iface = iface;
611: ses->chan_count++;
612: atomic_set(&ses->chan_seq, 0);
613:
614: /* Mark this channel as needing connect/setup */
615: cifs_chan_set_need_reconnect(ses, chan->server);
616:
617: spin_unlock(&ses->chan_lock);
618:
619: mutex_lock(&ses->session_mutex);
620:
621: rc = cifs_negotiate_protocol(xid, ses, chan->server);
622: if (!rc)
623: rc = cifs_setup_session(xid, ses, chan->server, ses->local_nls);
624:
625: mutex_unlock(&ses->session_mutex);
626:
627: out:
628: if (rc && chan->server) {
629: cifs_put_tcp_session(chan->server, 0);
630:
631: spin_lock(&ses->chan_lock);
632:
633: /* we rely on all bits beyond chan_count to be clear */
634: cifs_chan_clear_need_reconnect(ses, chan->server);
635: ses->chan_count--;
636: /*
637: * chan_count should never reach 0 as at least the primary
638: * channel is always allocated
639: */
640: WARN_ON(ses->chan_count < 1);
641: spin_unlock(&ses->chan_lock);
642: }
643:
644: kfree(ctx->UNC);
645: out_free_ctx:
646: kfree(ctx);
647: out_free_xid:
648: free_xid(xid);
649: return rc;
650: }
SourceFile:fs/smb/client/sess.c]
|
| 37/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 60812
output: 74
thoughts: 68
Thoughts: **My Thought Process on Analyzing CIFS Channel Management**
My primary goal here is to understand the lifecycle and state management of CIFS (Common Internet File System) sessions and their associated channels. Specifically, I'm interested in how new channels are added to an existing session and the mechanisms by which existing channels might be skipped or disabled. This knowledge is crucial for comprehending the robustness and error-handling capabilities of the CIFS client implementation, especially in dynamic network environments where connectivity can be intermittent.
To achieve this, I'll be leveraging my `codesearch-find-references` tool. This powerful utility allows me to perform a deep, code-level analysis by searching for the usage of specific functions across the entire codebase. My focus will be on two key functions:
1. `cifs_ses_add_channel`: This function is likely responsible for the core logic of establishing and integrating a new communication channel into an active CIFS session. I need to see *when* and *under what conditions* a new channel is initiated. Is it during initial session setup? Is it in response to a detected channel failure, triggering a re-establishment or addition of a backup channel? Understanding the call sites of this function will illuminate the process of channel provisioning.
2. `cifs_chan_skip_or_disable`: This function suggests a mechanism for de-prioritizing or outright deactivating a particular channel. I need to investigate the triggers for this. Does it happen due to persistent errors on that channel? Is it a proactive measure to conserve resources if a channel is deemed unreliable? Or perhaps it's a load-balancing or failover precursor. Examining the references to `cifs_chan_skip_or_disable` will reveal the fault tolerance and performance optimization strategies employed by the CIFS client.
By performing these searches, I aim to construct a comprehensive understanding of how CIFS sessions manage their underlying communication channels, from their creation and addition to their potential deactivation, thereby gaining insight into the client's resilience and operational dynamics.
|
| 38/2 |
2026/10/17 01:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:cifs_ses_add_channel]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cifs_try_adding_channels SourceFile:fs/smb/client/sess.c SourceLine:259 SourceSnippet: 254: spin_unlock(&ses->iface_lock);
255: break;
256: }
257:
258: spin_unlock(&ses->iface_lock);
259: rc = cifs_ses_add_channel(ses, candidate);
260: spin_lock(&ses->iface_lock);
261:
262: if (rc) {
263: cifs_dbg(VFS, "failed to open extra channel on iface:%pIS rc=%d\n",
264: &candidate->sockaddr,
]] TruncatedOutput:false]
|
| 39/2 |
2026/10/17 01:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:cifs_chan_skip_or_disable]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb3_update_ses_channels SourceFile:fs/smb/client/smb2pdu.c SourceLine:238 SourceSnippet: 233: * - If disable requested, skip or disable the channel
234: * - If below max channels, attempt to add more
235: * - If above max channels, skip or disable excess channels
236: */
237: if (disable_mchan)
238: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
239: else {
240: if (ses->chan_count < ses->chan_max)
241: rc = cifs_try_adding_channels(ses);
242: else if (ses->chan_count > ses->chan_max)
243: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb3_update_ses_channels SourceFile:fs/smb/client/smb2pdu.c SourceLine:243 SourceSnippet: 238: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
239: else {
240: if (ses->chan_count < ses->chan_max)
241: rc = cifs_try_adding_channels(ses);
242: else if (ses->chan_count > ses->chan_max)
243: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
244: }
245:
246: return rc;
247: }
]] TruncatedOutput:false]
|
| 40/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 61733
output: 83
thoughts: 18
Thoughts: **My Thought Process**
My immediate focus is on understanding the implementation and usage of `smb3_update_ses_channels`. To do this effectively, I need to examine the function itself and then trace all the places where it's invoked. This will give me a comprehensive view of its role within the system and how it interacts with other components.
|
| 41/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/smb2pdu.c Name:smb3_update_ses_channels]
Results: map[SourceCode: 214: /*
215: * smb3_update_ses_channels - Synchronize session channels with new configuration
216: * @ses: pointer to the CIFS session structure
217: * @server: pointer to the TCP server info structure
218: * @from_reconnect: indicates if called from reconnect context
219: * @disable_mchan: indicates if called from reconnect to disable multichannel
220: *
221: * Returns 0 on success or error code on failure.
222: *
223: * Outside of reconfigure, this function is called from cifs_mount() during mount
224: * and from reconnect scenarios to adjust channel count when the
225: * server's multichannel support changes.
226: */
227: int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *server,
228: bool from_reconnect, bool disable_mchan)
229: {
230: int rc = 0;
231: /*
232: * Manage session channels based on current count vs max:
233: * - If disable requested, skip or disable the channel
234: * - If below max channels, attempt to add more
235: * - If above max channels, skip or disable excess channels
236: */
237: if (disable_mchan)
238: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
239: else {
240: if (ses->chan_count < ses->chan_max)
241: rc = cifs_try_adding_channels(ses);
242: else if (ses->chan_count > ses->chan_max)
243: rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
244: }
245:
246: return rc;
247: }
SourceFile:fs/smb/client/smb2pdu.c]
|
| 42/2 |
2026/10/17 01:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:smb3_update_ses_channels]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:mchan_mount_work_fn SourceFile:fs/smb/client/connect.c SourceLine:3854 SourceSnippet:3849: static void
3850: mchan_mount_work_fn(struct work_struct *work)
3851: {
3852: struct mchan_mount *mchan_mount = container_of(work, struct mchan_mount, work);
3853:
3854: smb3_update_ses_channels(mchan_mount->ses,
3855: mchan_mount->ses->server,
3856: false /* from_reconnect */,
3857: false /* disable_mchan */);
3858:
3859: mchan_mount_free(mchan_mount);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb2_reconnect SourceFile:fs/smb/client/smb2pdu.c SourceLine:390 SourceSnippet: 385: * if server stopped supporting multichannel
386: * and the first channel reconnected, disable all the others.
387: */
388: if (ses->chan_count > 1 &&
389: !(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) {
390: rc = smb3_update_ses_channels(ses, server,
391: from_reconnect, true /* disable_mchan */);
392: if (rc) {
393: mutex_unlock(&ses->session_mutex);
394: goto out;
395: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb2_reconnect SourceFile:fs/smb/client/smb2pdu.c SourceLine:473 SourceSnippet: 468: * that multichannel has been disabled with server
469: * capabilities, rather return STATUS_NOT_IMPLEMENTED.
470: * treat this as server not supporting multichannel
471: */
472:
473: rc = smb3_update_ses_channels(ses, server,
474: from_reconnect,
475: true /* disable_mchan */);
476: goto skip_add_channels;
477: } else if (rc)
478: cifs_tcon_dbg(FYI, "%s: failed to query server interfaces: %d\n",
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb2_reconnect SourceFile:fs/smb/client/smb2pdu.c SourceLine:487 SourceSnippet: 482: ses->iface_count &&
483: !SERVER_IS_CHAN(server)) {
484: if (ses->chan_count == 1)
485: cifs_server_dbg(VFS, "supports multichannel now\n");
486:
487: smb3_update_ses_channels(ses, server, from_reconnect,
488: false /* disable_mchan */);
489: }
490: } else {
491: mutex_unlock(&ses->session_mutex);
492: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smb3_reconfigure SourceFile:fs/smb/client/fs_context.c SourceLine:1211 SourceSnippet:1206: /* Synchronize ses->chan_max with the new mount context */
1207: smb3_sync_ses_chan_max(ses, ctx->max_channels);
1208:
1209: mutex_unlock(&ses->session_mutex);
1210:
1211: smb3_update_ses_channels(ses, ses->server,
1212: false /* from_reconnect */,
1213: false /* disable_mchan */);
1214:
1215: /* Clear scaling flag after operation */
1216: spin_lock(&ses->ses_lock);
]] TruncatedOutput:false]
|
| 43/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 63594
output: 45
thoughts: 321
Thoughts: **My Thought Process Regarding NetworkTrigger and CIFS**
Alright, I need to assess if this `NetworkTrigger` is relevant here. My first thought is to define what "Ethernet Network Trigger" actually entails. The documentation states it's about whether a bug can be activated by processing incoming Ethernet network traffic, either directly through the network stack or via drivers that are exposed to this network data.
Now, I know CIFS is a network client filesystem, specifically located at `fs/smb/client/`. This immediately sparks a question: for any CIFS client connection to even *exist*, someone (root, with `CAP_SYS_ADMIN` privileges in the `init_user_ns`) must have mounted a CIFS share. Or, perhaps the trigger happens when a CIFS share *is* mounted or *is being* mounted. The core question then becomes: if a CIFS share is mounted and connected over the network, could an attacker on that network, or a malicious SMB server, or even a Man-in-the-Middle on the Ethernet segment, manage to trigger `cifs_put_tcp_session`?
I need to be methodical here. Let's assume a system *already has* a CIFS mount, or is in the process of mounting one, or has an active CIFS connection. The critical question is: can incoming network packets originating from the SMB server, or simply present on the Ethernet network, lead to `cifs_put_tcp_session` being invoked?
To figure this out, I'll trace the execution path. Let's consider Case A: this happens during an active CIFS session (or while a mount is in progress). I'll start by looking at scenarios with multichannel enabled, but I should also consider the case *without* multichannel initially.
My next step is to dive into the code, specifically within `fs/smb/client/smb2pdu.c`, and examine the `smb2_reconnect` function. I need to carefully review lines 482 through 488 of that file to understand the logic there.
|
| 44/2 |
2026/10/17 01:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/smb2pdu.c Name:smb2_reconnect]
Results: map[SourceCode: 249: static int
250: smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
251: struct TCP_Server_Info *server, bool from_reconnect)
252: {
253: struct cifs_ses *ses;
254: int xid;
255: int rc = 0;
256:
257: /*
258: * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so
259: * check for tcp and smb session status done differently
260: * for those three - in the calling routine.
261: */
262: if (tcon == NULL)
263: return 0;
264:
265: if (smb2_command == SMB2_TREE_CONNECT)
266: return 0;
267:
268: spin_lock(&tcon->tc_lock);
269: if (tcon->status == TID_EXITING) {
270: /*
271: * only tree disconnect allowed when disconnecting ...
272: */
273: if (smb2_command != SMB2_TREE_DISCONNECT) {
274: spin_unlock(&tcon->tc_lock);
275: cifs_tcon_dbg(FYI, "can not send cmd %d while umounting\n",
276: smb2_command);
277: return -ENODEV;
278: }
279: }
280: spin_unlock(&tcon->tc_lock);
281:
282: ses = tcon->ses;
283: if (!ses)
284: return smb_EIO(smb_eio_trace_null_pointers);
285: spin_lock(&ses->ses_lock);
286: if (ses->ses_status == SES_EXITING) {
287: spin_unlock(&ses->ses_lock);
288: return smb_EIO(smb_eio_trace_sess_exiting);
289: }
290: spin_unlock(&ses->ses_lock);
291: if (!ses->server || !server)
292: return smb_EIO(smb_eio_trace_null_pointers);
293:
294: spin_lock(&server->srv_lock);
295: if (server->tcpStatus == CifsNeedReconnect) {
296: /*
297: * Return to caller for TREE_DISCONNECT and LOGOFF and CLOSE
298: * here since they are implicitly done when session drops.
299: */
300: switch (smb2_command) {
301: /*
302: * BB Should we keep oplock break and add flush to exceptions?
303: */
304: case SMB2_TREE_DISCONNECT:
305: case SMB2_CANCEL:
306: case SMB2_CLOSE:
307: case SMB2_OPLOCK_BREAK:
308: spin_unlock(&server->srv_lock);
309: return -EAGAIN;
310: }
311: }
312:
313: /* if server is marked for termination, cifsd will cleanup */
314: if (server->terminate) {
315: spin_unlock(&server->srv_lock);
316: return -EHOSTDOWN;
317: }
318: spin_unlock(&server->srv_lock);
319:
320: again:
321: rc = cifs_wait_for_server_reconnect(server, tcon->retry);
322: if (rc)
323: return rc;
324:
325: spin_lock(&ses->chan_lock);
326: if (!cifs_chan_needs_reconnect(ses, server) && !tcon->need_reconnect) {
327: spin_unlock(&ses->chan_lock);
328: return 0;
329: }
330: spin_unlock(&ses->chan_lock);
331: cifs_tcon_dbg(FYI, "sess reconnect mask: 0x%lx, tcon reconnect: %d\n",
332: tcon->ses->chans_need_reconnect,
333: tcon->need_reconnect);
334:
335: mutex_lock(&ses->session_mutex);
336: /*
337: * Handle the case where a concurrent thread failed to negotiate or
338: * killed a channel.
339: */
340: spin_lock(&server->srv_lock);
341: switch (server->tcpStatus) {
342: case CifsExiting:
343: spin_unlock(&server->srv_lock);
344: mutex_unlock(&ses->session_mutex);
345: return -EHOSTDOWN;
346: case CifsNeedReconnect:
347: spin_unlock(&server->srv_lock);
348: mutex_unlock(&ses->session_mutex);
349: if (!tcon->retry)
350: return -EHOSTDOWN;
351: goto again;
352: default:
353: break;
354: }
355: spin_unlock(&server->srv_lock);
356:
357: /*
358: * need to prevent multiple threads trying to simultaneously
359: * reconnect the same SMB session
360: */
361: spin_lock(&ses->ses_lock);
362: spin_lock(&ses->chan_lock);
363: if (!cifs_chan_needs_reconnect(ses, server) &&
364: ses->ses_status == SES_GOOD) {
365: spin_unlock(&ses->chan_lock);
366: spin_unlock(&ses->ses_lock);
367: /* this means that we only need to tree connect */
368: if (tcon->need_reconnect)
369: goto skip_sess_setup;
370:
371: mutex_unlock(&ses->session_mutex);
372: goto out;
373: }
374: spin_unlock(&ses->chan_lock);
375: spin_unlock(&ses->ses_lock);
376:
377: rc = cifs_negotiate_protocol(0, ses, server);
378: if (rc) {
379: mutex_unlock(&ses->session_mutex);
380: if (!tcon->retry)
381: return -EHOSTDOWN;
382: goto again;
383: }
384: /*
385: * if server stopped supporting multichannel
386: * and the first channel reconnected, disable all the others.
387: */
388: if (ses->chan_count > 1 &&
389: !(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) {
390: rc = smb3_update_ses_channels(ses, server,
391: from_reconnect, true /* disable_mchan */);
392: if (rc) {
393: mutex_unlock(&ses->session_mutex);
394: goto out;
395: }
396: }
397:
398: rc = cifs_setup_session(0, ses, server, ses->local_nls);
399: if ((rc == -EACCES) || (rc == -EKEYEXPIRED) || (rc == -EKEYREVOKED)) {
400: /*
401: * Try alternate password for next reconnect (key rotation
402: * could be enabled on the server e.g.) if an alternate
403: * password is available and the current password is expired,
404: * but do not swap on non pwd related errors like host down
405: */
406: if (ses->password2)
407: swap(ses->password2, ses->password);
408: }
409: if (rc) {
410: mutex_unlock(&ses->session_mutex);
411: if (rc == -EACCES && !tcon->retry)
412: return -EHOSTDOWN;
413: goto out;
414: }
415:
416: skip_sess_setup:
417: if (!tcon->need_reconnect) {
418: mutex_unlock(&ses->session_mutex);
419: goto out;
420: }
421: cifs_mark_open_files_invalid(tcon);
422: if (tcon->use_persistent)
423: tcon->need_reopen_files = true;
424:
425: rc = cifs_tree_connect(0, tcon);
426:
427: cifs_tcon_dbg(FYI, "reconnect tcon rc = %d\n", rc);
428: if (rc) {
429: /* If sess reconnected but tcon didn't, something strange ... */
430: mutex_unlock(&ses->session_mutex);
431: cifs_tcon_dbg(VFS, "reconnect tcon failed rc = %d\n", rc);
432: goto out;
433: }
434:
435: spin_lock(&ses->ses_lock);
436: if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {
437: spin_unlock(&ses->ses_lock);
438: mutex_unlock(&ses->session_mutex);
439: goto skip_add_channels;
440: }
441: ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;
442: spin_unlock(&ses->ses_lock);
443:
444: if (!rc &&
445: (server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL) &&
446: server->ops->query_server_interfaces) {
447: /*
448: * query server network interfaces, in case they change.
449: * Also mark the session as pending this update while the query
450: * is in progress. This will be used to avoid calling
451: * smb2_reconnect recursively.
452: */
453: ses->flags |= CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
454: xid = get_xid();
455: rc = server->ops->query_server_interfaces(xid, tcon, false);
456: free_xid(xid);
457: ses->flags &= ~CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
458:
459: if (!tcon->ipc && !tcon->dummy)
460: queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
461: (SMB_INTERFACE_POLL_INTERVAL * HZ));
462:
463: mutex_unlock(&ses->session_mutex);
464:
465: if (rc == -EOPNOTSUPP && ses->chan_count > 1) {
466: /*
467: * some servers like Azure SMB server do not advertise
468: * that multichannel has been disabled with server
469: * capabilities, rather return STATUS_NOT_IMPLEMENTED.
470: * treat this as server not supporting multichannel
471: */
472:
473: rc = smb3_update_ses_channels(ses, server,
474: from_reconnect,
475: true /* disable_mchan */);
476: goto skip_add_channels;
477: } else if (rc)
478: cifs_tcon_dbg(FYI, "%s: failed to query server interfaces: %d\n",
479: __func__, rc);
480:
481: if (ses->chan_max > ses->chan_count &&
482: ses->iface_count &&
483: !SERVER_IS_CHAN(server)) {
484: if (ses->chan_count == 1)
485: cifs_server_dbg(VFS, "supports multichannel now\n");
486:
487: smb3_update_ses_channels(ses, server, from_reconnect,
488: false /* disable_mchan */);
489: }
490: } else {
491: mutex_unlock(&ses->session_mutex);
492: }
493:
494: skip_add_channels:
495: spin_lock(&ses->ses_lock);
496: ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS;
497: spin_unlock(&ses->ses_lock);
498:
499: if (smb2_command != SMB2_INTERNAL_CMD)
500: cifs_queue_server_reconn(server);
501:
502: atomic_inc(&tconInfoReconnectCount);
503: out:
504: /*
505: * Check if handle based operation so we know whether we can continue
506: * or not without returning to caller to reset file handle.
507: */
508: /*
509: * BB Is flush done by server on drop of tcp session? Should we special
510: * case it and skip above?
511: */
512: switch (smb2_command) {
513: case SMB2_FLUSH:
514: case SMB2_READ:
515: case SMB2_WRITE:
516: case SMB2_LOCK:
517: case SMB2_QUERY_DIRECTORY:
518: case SMB2_CHANGE_NOTIFY:
519: case SMB2_QUERY_INFO:
520: case SMB2_SET_INFO:
521: case SMB2_IOCTL:
522: rc = -EAGAIN;
523: }
524: return rc;
525: }
SourceFile:fs/smb/client/smb2pdu.c]
|
| 45/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 68088
output: 69
thoughts: 169
Thoughts: **My Thought Process Regarding Ethernet Network Triggers and CIFS**
My initial thought upon encountering the term "Ethernet Network Trigger" is to clarify its precise scope. Generally, I understand this to refer to the ability of an unauthenticated remote attacker to initiate an action simply by sending Ethernet frames or network packets. However, I need to be absolutely sure about what constitutes a "network trigger" in this context. Specifically, I'm pondering whether accessing an already-mounted CIFS share by an unprivileged local user, or scenarios involving `ioctl` calls, automounting, or DFS referrals, would also fall under this umbrella.
This ambiguity prompts me to delve deeper. I need to investigate the behavior when an unprivileged local user interacts with an existing CIFS mount. Furthermore, I want to understand the implications of `ioctl` operations, automounting mechanisms, and, crucially, DFS referrals.
My focus sharpens on DFS referrals. I need to determine precisely what happens when any user accesses a DFS referral directory within a CIFS mount. To get a definitive answer, I intend to examine the relevant kernel source code, specifically looking at `fs/smb/client/dfs.c` and `fs/smb/client/cifs_dfs_ref.c`. This direct code inspection will allow me to fully grasp the intricate workings and potential attack vectors associated with CIFS DFS referrals in relation to network triggers.
|
| 46/2 |
2026/10/17 01:48 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:fs/smb/client/dfs.c]
Results: map[Entities:[map[Kind:function Name:__dfs_mount_share] map[Kind:function Name:__dfs_referral_walk] map[Kind:function Name:cifs_tree_connect] map[Kind:function Name:dfs_mount_share] map[Kind:function Name:dfs_parse_target_referral] map[Kind:function Name:dfs_referral_walk] map[Kind:function Name:get_session] map[Kind:function Name:parse_dfs_target] map[Kind:function Name:set_root_smb_session] map[Kind:function Name:setup_dfs_ref] map[Kind:function Name:target_share_matches_server] map[Kind:function Name:tree_connect_dfs_target] map[Kind:function Name:update_fs_context_dstaddr]]]
|
| 47/2 |
2026/10/17 01:48 |
tool |
codesearch-file-index |
0m
Error:
Args: map[SourceFile:fs/smb/client/cifs_dfs_ref.c]
Results:
|
| 48/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 68589
output: 30
thoughts: 25
Thoughts: **My Thought Process on Inspecting the SMB Client Filesystem Directory**
Okay, so my immediate instinct here is to get a lay of the land. To do that, I need to see *everything* that constitutes the SMB client filesystem implementation. The most straightforward way to achieve this, in my experience, is to perform a direct directory listing. My target for this operation is `fs/smb/client/`. By invoking a command to list the contents of this specific directory, I'll be able to enumerate all the files and subdirectories that reside within it. This initial overview is crucial for understanding the scope and organization of the SMB client's codebase. It allows me to quickly identify the key components and modules involved, which will inform my subsequent analysis.
|
| 49/2 |
2026/10/17 01:48 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[asn1.c cached_dir.c cached_dir.h cifs_debug.c cifs_debug.h cifs_fs_sb.h cifs_ioctl.h cifs_spnego.c cifs_spnego.h cifs_swn.c cifs_swn.h cifs_unicode.c cifs_unicode.h cifsacl.c cifsacl.h cifsencrypt.c cifsfs.c cifsfs.h cifsglob.h cifspdu.h cifsproto.h cifsroot.c cifssmb.c compress.c compress.h connect.c dfs.c dfs.h dfs_cache.c dfs_cache.h dir.c dns_resolve.c dns_resolve.h export.c file.c fs_context.c fs_context.h fscache.c fscache.h inode.c ioctl.c link.c misc.c namespace.c netlink.c netlink.h netmisc.c nterr.h ntlmssp.h readdir.c reparse.c reparse.h rfc1002pdu.h sess.c smb1debug.c smb1encrypt.c smb1maperror.c smb1maperror_test.c smb1misc.c smb1ops.c smb1pdu.h smb1proto.h smb1session.c smb1transport.c smb2file.c smb2glob.h smb2inode.c smb2maperror.c smb2maperror_test.c smb2misc.c smb2ops.c smb2pdu.c smb2pdu.h smb2proto.h smb2transport.c smbdirect.c smbdirect.h smbencrypt.c smberr.h trace.c trace.h transport.c unc.c winucase.c xattr.c] Subdirs:<nil>]
|
| 50/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 69324
output: 65
thoughts: 29
Thoughts: **My Thought Process on Debugging SMB Namespace and Netlink Interaction**
My immediate instinct is to dive into the core logic governing how SMB handles namespaces and its communication mechanisms. Therefore, my first port of call is to examine the `fs/smb/client/namespace.c` file. I'm anticipating that this is where the kernel-level representation and manipulation of SMB network namespaces reside, and I need to understand how the client module is defining and interacting with these. I'll be looking for structures, functions, and data flow related to namespace registration, lookup, and management within the SMB context.
Concurrently, or immediately following that, I need to understand how this namespace information is being communicated or controlled externally. This leads me directly to `fs/smb/client/netlink.c`. Netlink is the standard kernel mechanism for user-space to kernel-space communication, and it's highly probable that the SMB client module is leveraging it for configuration, status reporting, or even dynamic updates related to its namespaces. My focus here will be on the Netlink protocol handlers, message types, and how they are marshaling and unmarshaling data, particularly anything concerning namespace attributes or operations. I'm looking for the bridge between the internal namespace representation and the external control plane.
|
| 51/2 |
2026/10/17 01:48 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:fs/smb/client/namespace.c]
Results: map[Entities:[map[Kind:function Name:automount_fullpath] map[Kind:function Name:cifs_build_devname] map[Kind:function Name:cifs_d_automount] map[Kind:function Name:cifs_do_automount] map[Kind:function Name:cifs_expire_automounts] map[Kind:function Name:cifs_release_automount_timer] map[Kind:function Name:fs_context_set_ids] map[Kind:function Name:is_dfs_mount] map[Kind:global_variable Name:cifs_automount_list] map[Kind:global_variable Name:cifs_automount_task] map[Kind:global_variable Name:cifs_mountpoint_expiry_timeout] map[Kind:global_variable Name:cifs_namespace_inode_operations]]]
|
| 52/2 |
2026/10/17 01:48 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:fs/smb/client/netlink.c]
Results: map[Entities:[map[Kind:function Name:cifs_genl_exit] map[Kind:function Name:cifs_genl_init] map[Kind:global_variable Name:cifs_genl_family] map[Kind:global_variable Name:cifs_genl_mcgrps] map[Kind:global_variable Name:cifs_genl_ops] map[Kind:global_variable Name:cifs_genl_policy]]]
|
| 53/2 |
2026/10/17 01:48 |
llm |
expert |
0m
Model:
Tokens:
input: 69798
output: 47
thoughts: 36
Thoughts: **A Deep Dive into Potential Netlink Interfaces for CIFS**
My current line of inquiry is focused on uncovering any Netlink interfaces that might be exposed by the CIFS (Common Internet File System) client. I'm specifically scrutinizing the `cifs_genl_ops` structure, which resides within the `fs/smb/client/netlink.c` file. My reasoning is that this structure is the likely nexus for defining and managing Netlink operations for CIFS. Therefore, a thorough examination of `cifs_genl_ops` should reveal whether there's a functional Netlink interface in place, and if so, what its capabilities and operational scope are. This is a crucial step to ensure I haven't overlooked any programmatic control or monitoring mechanisms that might be available through this kernel-userspace communication channel.
|
| 54/2 |
2026/10/17 01:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/netlink.c Name:cifs_genl_ops]
Results: map[SourceCode: 33: static const struct genl_ops cifs_genl_ops[] = {
34: {
35: .cmd = CIFS_GENL_CMD_SWN_NOTIFY,
36: .flags = GENL_ADMIN_PERM,
37: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
38: .doit = cifs_swn_notify,
39: },
40: };
SourceFile:fs/smb/client/netlink.c]
|
| 55/2 |
2026/10/17 01:49 |
llm |
expert |
0m
Model:
Tokens:
input: 70047
output: 91
thoughts: 1034
Thoughts: **My Thought Process Regarding CIFS/SMB3 Mount Permissions and a Potential Network Trigger for a Use-After-Free Vulnerability**
My initial focus was on understanding the privilege requirements for mounting CIFS/SMB3 shares, specifically examining the `GENL_ADMIN_PERM` permission and its dependency on `CAP_NET_ADMIN`. I quickly deduced that since `netns_ok` is false for `cifs_genl_family`, `GENL_ADMIN_PERM` needs `CAP_NET_ADMIN` in the initial user namespace. Furthermore, its functionality is limited to acting on existing CIFS connections, implying it's not the primary mechanism for initiating a mount.
To clarify how a CIFS mount is actually established, I traced the execution path. I confirmed that mounts are exclusively initiated through `mount("...", "...", "cifs" / "smb3", ...)` calls or via `fsopen("cifs" / "smb3")` followed by `fsmount()`. The critical observation here is that neither `cifs_fs_type` nor `smb3_fs_type` sets the `FS_USERNS_MOUNT` flag. This absence is significant because both `fsopen` (via `vfs_get_tree`) and `do_new_mount` explicitly check `mount_capable(fc)`, which, in turn, calls `capable(CAP_SYS_ADMIN)` if `FS_USERNS_MOUNT` is not set. Consequently, I concluded that mounting a CIFS/SMB3 share fundamentally requires `CAP_SYS_ADMIN` in the *initial* user namespace.
This led me to definitively categorize the vulnerability's triggers:
* **Unprivileged:** `false` – An unprivileged user cannot initiate a CIFS/SMB3 mount.
* **UserNamespace:** `false` – Even with capabilities granted within a user namespace, the mount will fail because `CAP_SYS_ADMIN` isn't met in the initial namespace due to the missing `FS_USERNS_MOUNT` flag.
* **FilesystemTrigger:** `false` – CIFS is a network client, not a local filesystem that can be mounted from external media or images.
* **VMGuestTrigger:** `false` – (Assumed, as no specific VM guest interaction is apparent).
* **VMHostTrigger:** `false` – (Assumed, as no specific VM host interaction is apparent).
* **PeripheralTrigger:** `false` – (Assumed, as no peripheral device interaction is apparent).
* **RemoteTrigger:** `false` – (Assumed, as no direct remote triggering is indicated by the mount permissions analysis).
However, I then paused and re-evaluated the `NetworkTrigger` category. This is where my thinking became more focused on the potential exploitability of the *actual bug*, not just the mount mechanism. I specifically asked myself: "Can this bug be triggered by ingress network Ethernet traffic?" This question shifted my attention from the mounting process to the underlying vulnerability, which I understood to be a use-after-free (UAF) in `cifs_put_tcp_session`.
To answer the network trigger question, I needed to understand *how* the UAF occurs. I began scrutinizing the `cifs_put_tcp_session` function, paying close attention to the reference counting and cleanup logic. I noted the critical `spin_lock(&cifs_tcp_ses_lock)` and the check for `server->srv_count`. If the count drops to zero, it proceeds to the cleanup phase, including `kfree_sensitive(server->session_key.response)` and freeing the `server` structure itself indirectly.
My next step was to understand *what causes the `cifs_demultiplex_thread` to exit its loop prematurely*, which is a key prerequisite for the UAF in `cifs_put_tcp_session` to be reachable in a vulnerable state. I then focused on the `while (server->tcpStatus != CifsExiting)` loop within `cifs_demultiplex_thread` and the `cifs_read_from_socket` call (and its underlying `cifs_readv_from_socket`). This is where my investigation is currently focused: I need to determine if malicious ingress network traffic, specifically SMB traffic from a compromised server or an attacker on the network, can manipulate the state of the `server` structure or trigger unexpected read results that would lead to the premature exit of the demultiplexing thread, thereby exposing the UAF in `cifs_put_tcp_session`. My current hypothesis is that a carefully crafted network packet could exploit this sequence of events.
|
| 56/2 |
2026/10/17 01:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_read_from_socket]
Results: map[SourceCode: 795: int
796: cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
797: unsigned int to_read)
798: {
799: struct msghdr smb_msg = {};
800: struct kvec iov = {.iov_base = buf, .iov_len = to_read};
801:
802: iov_iter_kvec(&smb_msg.msg_iter, ITER_DEST, &iov, 1, to_read);
803:
804: return cifs_readv_from_socket(server, &smb_msg);
805: }
SourceFile:fs/smb/client/connect.c]
|
| 57/2 |
2026/10/17 01:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/smb/client/connect.c Name:cifs_readv_from_socket]
Results: map[SourceCode: 738: static int
739: cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
740: {
741: int length = 0;
742: int total_read;
743:
744: for (total_read = 0; msg_data_left(smb_msg); total_read += length) {
745: try_to_freeze();
746:
747: /* reconnect if no credits and no requests in flight */
748: if (zero_credits(server)) {
749: cifs_reconnect(server, false);
750: return -ECONNABORTED;
751: }
752:
753: if (server_unresponsive(server))
754: return -ECONNABORTED;
755: if (cifs_rdma_enabled(server) && server->smbd_conn)
756: length = smbd_recv(server->smbd_conn, smb_msg);
757: else
758: length = sock_recvmsg(server->ssocket, smb_msg, 0);
759:
760: spin_lock(&server->srv_lock);
761: if (server->tcpStatus == CifsExiting) {
762: spin_unlock(&server->srv_lock);
763: return -ESHUTDOWN;
764: }
765:
766: if (server->tcpStatus == CifsNeedReconnect) {
767: spin_unlock(&server->srv_lock);
768: cifs_reconnect(server, false);
769: return -ECONNABORTED;
770: }
771: spin_unlock(&server->srv_lock);
772:
773: if (length == -ERESTARTSYS ||
774: length == -EAGAIN ||
775: length == -EINTR) {
776: /*
777: * Minimum sleep to prevent looping, allowing socket
778: * to clear and app threads to set tcpStatus
779: * CifsNeedReconnect if server hung.
780: */
781: usleep_range(1000, 2000);
782: length = 0;
783: continue;
784: }
785:
786: if (length <= 0) {
787: cifs_dbg(FYI, "Received no data or error: %d\n", length);
788: cifs_reconnect(server, false);
789: return -ECONNABORTED;
790: }
791: }
792: return total_read;
793: }
SourceFile:fs/smb/client/connect.c]
|
| 58/2 |
2026/10/17 01:49 |
llm |
expert |
0m
Model:
Tokens:
input: 72229
output: 71
thoughts: 860
Thoughts: **My Thought Process Regarding the CIFS Kernel Bug**
Alright, let's break down this CIFS bug analysis. My primary focus is on understanding the exact trigger conditions and the implications for the kernel's security posture, especially concerning the `NetworkTrigger` classification.
I started by diving into `cifs_readv_from_socket`. I observed how `sock_recvmsg` can return `-EAGAIN` due to a receive timeout. This is a normal, expected behavior. The crucial part is how `cifs_readv_from_socket` handles this: it checks `server->tcpStatus == CifsExiting`. If true, it returns `-ESHUTDOWN`. This, in turn, causes the `cifs_demultiplex_thread` to exit its loop and initiate a cleanup process, ultimately leading to `kfree_sensitive(server)`. This looks like a potential path to freeing `server` too early.
Then, the critical question arises: can this be triggered by network traffic in the traditional sense, i.e., `NetworkTrigger`? My analysis leads me to conclude, definitively, that it cannot. Here's why:
The definition of `NetworkTrigger` is clear: it's about bugs that can be triggered by processing *ingress* Ethernet traffic. This typically involves the network stack (`net/ipv4`, `net/ipv6`, `net/core`) or network device drivers. This specific bug, however, resides in `fs/smb/client/`. It's tied to the lifecycle of a CIFS mount or session teardown. The CIFS client code isn't actively listening for or processing any incoming network data *until* a CIFS mount is initiated by a local, privileged user. Without that initial `mount()` syscall (or an `umount()`), the relevant code paths aren't even active.
Furthermore, even when a CIFS share *is* mounted, the freeing of the `TCP_Server_Info` structure (`server`) within `cifs_put_tcp_session` is guarded. It only happens when `server->srv_count` reaches zero. This typically occurs during failed mounts or unmounts, or during specific multichannel operations. More importantly, the act of mounting a CIFS filesystem in the first place requires `CAP_SYS_ADMIN`. This immediately disqualifies it from being an unprivileged, remotely triggerable bug.
The race window I noted in `cifs_put_tcp_session` (between marking `CifsExiting` and clearing the thread pointer) is contingent on a substantial delay (`msleep(125)`) and preemption. This is not something that can be reliably induced by external network packets alone, especially given the prior `CAP_SYS_ADMIN` requirement.
Therefore, based on this reasoning, I confidently marked `NetworkTrigger` as `false`.
Before finalizing, I double-checked all other classification dimensions to ensure a complete picture:
* **Exploitable**: `true`. The core issue is a Use-After-Free (UAF) in `cifs_put_tcp_session` and `cifs_crypto_secmech_release` on `struct TCP_Server_Info`. This UAF involves both read operations (passed to `crypto_free_aead()`, `kfree_sensitive()`, `send_sig()`) and write operations, making it exploitable.
* **DenialOfService**: `true`. The UAF will inevitably lead to kernel crashes and memory corruption.
* **Unprivileged**: `false`. As mentioned, mounting CIFS/SMB3 requires `CAP_SYS_ADMIN` in the initial user namespace.
* **UserNamespace**: `false`. The `cifs_fs_type` and `smb3_fs_type` do not support user namespace mounts (`FS_USERNS_MOUNT`), meaning `capable(CAP_SYS_ADMIN)` is always checked against the `init_user_ns`.
* **VMGuestTrigger**: `false`.
* **VMHostTrigger**: `false`.
* **RemoteTrigger**: `false`. The requirement for `CAP_SYS_ADMIN` and local mounting prevents this.
* **PeripheralTrigger**: `false`.
* **FilesystemTrigger**: `false`. While related to the filesystem, the trigger isn't a typical filesystem operation that can be initiated by a non-privileged user without prior mount setup.
With all dimensions confirmed, I proceeded to the `set-results` step.
|
| 59/2 |
2026/10/17 01:49 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 60/2 |
2026/10/17 01:49 |
llm |
expert |
0m
Model:
Tokens:
input: 73227
output: 939
thoughts: 15
Thoughts: **My Thought Process for Finalizing the Response**
I've reached the point where all the necessary information is fully processed and confirmed. My understanding is complete and accurate. Therefore, I am now fully prepared to construct and deliver the final response.
|
| 61/1 |
2026/10/17 01:49 |
action |
format-explanation |
0m
Results: map[Explanation:### Root Cause Analysis
The bug is a race condition leading to a slab use-after-free on `struct
TCP_Server_Info` (`server`, allocated in `kmalloc-4k`) between
`cifs_put_tcp_session()` and `cifs_demultiplex_thread()`.
In `cifs_put_tcp_session()` (`fs/smb/client/connect.c`):
```c
spin_lock(&server->srv_lock);
server->tcpStatus = CifsExiting;
spin_unlock(&server->srv_lock);
cifs_crypto_secmech_release(server);
kfree_sensitive(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
task = xchg(&server->tsk, NULL);
if (task)
send_sig(SIGKILL, task, 1);
```
Meanwhile, `cifs_demultiplex_thread()` loops while `server->tcpStatus !=
CifsExiting`:
```c
while (server->tcpStatus != CifsExiting) {
...
}
...
task_to_wake = xchg(&server->tsk, NULL);
clean_demultiplex_info(server);
```
Inside `clean_demultiplex_info(server)`, `kfree_sensitive(server)` is called to
free the `struct TCP_Server_Info` object.
Because `cifs_put_tcp_session()` sets `server->tcpStatus = CifsExiting` *before*
releasing `server->secmech`, freeing `server->session_key.response`, and
performing `xchg(&server->tsk, NULL)`, if the task running
`cifs_put_tcp_session()` is preempted or delayed after setting `CifsExiting`,
`cifs_demultiplex_thread()` can observe `server->tcpStatus == CifsExiting`, exit
its main loop, and call `clean_demultiplex_info(server)` to free `server`. When
`cifs_put_tcp_session()` resumes, it performs UAF reads and writes on the freed
`server` structure:
1. `cifs_crypto_secmech_release(server)` reads `server->secmech.enc` and
`server->secmech.dec`, passing them to `crypto_free_aead()` if non-NULL and
writing `NULL` to those fields.
2. `kfree_sensitive(server->session_key.response)` reads
`server->session_key.response` and frees it, followed by writing `NULL` and `0`
to `server->session_key.response` and `server->session_key.len`.
3. `task = xchg(&server->tsk, NULL)` atomically exchanges `server->tsk` with
`NULL` and passes any non-NULL pointer to `send_sig(SIGKILL, task, 1)`.
### Security Impact Assessment
- **Exploitable (`true`) & Denial of Service (`true`)**: The bug is a
Use-After-Free on a `kmalloc-4k` object involving both UAF writes (zeroing
fields and atomic `xchg`) and UAF pointer reads passed directly to
`crypto_free_aead()`, `kfree_sensitive()`, and `send_sig()`. If the `kmalloc-4k`
slot is reallocated prior to `cifs_put_tcp_session()` resuming, this causes
arbitrary kernel memory free/corruption and kernel panic.
- **Accessible From Unprivileged Processes (`false`) & User Namespaces
(`false`)**: Reaching `cifs_mount()` / `cifs_put_tcp_session()` requires
mounting a `cifs` or `smb3` filesystem. Neither `cifs_fs_type` nor
`smb3_fs_type` sets `FS_USERNS_MOUNT` in `.fs_flags`, so `mount_capable()`
requires `capable(CAP_SYS_ADMIN)` in the initial user namespace.
- **Network / Remote / Filesystem / VM / Peripheral Triggers (`false`)**:
Triggering the bug requires a privileged local mount operation (`CAP_SYS_ADMIN`)
of a CIFS/SMB3 network share rather than parsing a disk filesystem image or
handling unsolicited ingress network/peripheral traffic.]
|