| 0/0 |
2026/09/02 00:04 |
flow |
assessment-security |
39m
Results: map[DenialOfService:true Explanation:**Bug Analysis:**
The bug report indicates a circular locking dependency (lockdep warning) that
leads to a deadlock. The two locks involved are `fs_reclaim` (a pseudo-lock
representing memory reclaim context) and `profile->lock` (an `rw_semaphore`
protecting a `blk_crypto_profile`).
The dependency chain is as follows:
1. **`profile->lock` -> `fs_reclaim`**: When a process performs I/O on an
encrypted file, `blk_crypto_get_keyslot()` is called to prepare the encryption
key. It acquires `profile->lock` for write (via `blk_crypto_hw_enter()`) and
calls the profile's `keyslot_program` operation. If the underlying block device
lacks inline encryption hardware, the `blk-crypto-fallback` is used. The
fallback's `blk_crypto_fallback_keyslot_program()` configures the kernel crypto
API (e.g., calling `adiantum_setkey()`), which allocates memory using
`GFP_KERNEL`. This allocation can trigger direct memory reclaim, effectively
acquiring the `fs_reclaim` pseudo-lock.
2. **`fs_reclaim` -> `profile->lock`**: During memory reclaim (either direct
reclaim by a user thread or background reclaim by `kswapd`), the kernel may
shrink the inode cache and evict inodes to free memory. Evicting an encrypted
inode calls `fscrypt_put_encryption_info()`, which destroys the inline crypt key
by calling `blk_crypto_evict_key()`. This function calls
`blk_crypto_hw_enter()`, which attempts to acquire `profile->lock`.
**Impact:**
This creates a classic AB-BA deadlock (or a self-deadlock if direct reclaim
evicts an inode on the same thread). Because the `blk-crypto-fallback` uses a
single global profile (`blk_crypto_fallback_profile`), its `profile->lock` is
global. A deadlock here will permanently hang any thread attempting to perform
I/O on encrypted files using the fallback, and it can also hang `kswapd`,
severely impairing the system's ability to manage memory. This results in a
reliable **Denial of Service (DoS)**.
Since this is a pure deadlock and does not involve memory corruption,
use-after-free, or out-of-bounds accesses, it is **not exploitable** for
privilege escalation or arbitrary code execution.
**Accessibility:**
This bug is **accessible from unprivileged processes**. On systems where a
supported filesystem (like `ext4` or `f2fs`) is mounted with the `encrypt`
feature enabled, any unprivileged user can create a directory, set an encryption
policy on it using the `FS_IOC_SET_ENCRYPTION_POLICY` ioctl (which only requires
`inode_owner_or_capable`), and write to files within it. By doing so while
simultaneously inducing memory pressure (e.g., by allocating large amounts of
anonymous memory), an unprivileged user can reliably trigger the deadlock. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/09/02 00:04 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/09/02 00:04 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/d20ee096b85bb6348b207ca05fcfd1899d452eaa]
|
| 3/1 |
2026/09/02 00:04 |
action |
kernel-builder |
22m
Results: map[KernelObj:/app/workdir/cache/build/3a271094dfe57f2bda8eb8466e6d3deebfa9eaa8]
|
| 4/1 |
2026/09/02 00:27 |
action |
codesearch-prepare |
13m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/09/02 00:41 |
agent |
expert |
3m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
kswapd0/77 is trying to acquire lock:
ffff88803f77c4c8 (&profile->lock){++++}-{4:4}, at: blk_crypto_hw_enter block/blk-crypto-profile.c:55 [inline]
ffff88803f77c4c8 (&profile->lock){++++}-{4:4}, at: __blk_crypto_evict_key+0x111/0x5e0 block/blk-crypto-profile.c:359
but task is already holding lock:
ffffffff8ee91d60 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat mm/vmscan.c:7177 [inline]
ffffffff8ee91d60 (fs_reclaim){+.+.}-{0:0}, at: kswapd+0xa08/0x32c0 mm/vmscan.c:7555
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (fs_reclaim){+.+.}-{0:0}:
__fs_reclaim_acquire mm/page_alloc.c:4375 [inline]
fs_reclaim_acquire+0x71/0x100 mm/page_alloc.c:4389
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4636 [inline]
slab_alloc_node mm/slub.c:4974 [inline]
__do_kmalloc_node mm/slub.c:5413 [inline]
__kmalloc_noprof+0xbc/0x720 mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
adiantum_setkey+0x139/0x620 crypto/adiantum.c:129
crypto_skcipher_setkey+0x2a3/0x460 crypto/skcipher.c:422
crypto_sync_skcipher_setkey include/crypto/skcipher.h:621 [inline]
blk_crypto_fallback_keyslot_program+0x1ad/0x440 block/blk-crypto-fallback.c:122
blk_crypto_get_keyslot+0x941/0x1070 block/blk-crypto-profile.c:295
blk_crypto_fallback_encrypt_bio block/blk-crypto-fallback.c:362 [inline]
blk_crypto_fallback_bio_prep+0x424/0x1b40 block/blk-crypto-fallback.c:505
blk_crypto_submit_bio include/linux/blk-crypto.h:211 [inline]
f2fs_submit_write_bio+0x11b/0x2e0 fs/f2fs/data.c:575
__submit_merged_bio+0x258/0x6a0 fs/f2fs/data.c:590
__f2fs_submit_merged_write fs/f2fs/data.c:682 [inline]
__submit_merged_write_cond+0x3c9/0x4e0 fs/f2fs/data.c:706
f2fs_submit_merged_write_cond fs/f2fs/data.c:731 [inline]
f2fs_write_cache_pages fs/f2fs/data.c:3495 [inline]
__f2fs_write_data_pages fs/f2fs/data.c:3603 [inline]
f2fs_write_data_pages+0x2a27/0x36f0 fs/f2fs/data.c:3641
do_writepages+0x338/0x560 mm/page-writeback.c:2560
filemap_writeback mm/filemap.c:387 [inline]
filemap_fdatawrite_range mm/filemap.c:412 [inline]
file_write_and_wait_range+0x36e/0x440 mm/filemap.c:786
f2fs_do_sync_file+0x69d/0x1960 fs/f2fs/file.c:359
generic_write_sync include/linux/fs.h:2686 [inline]
f2fs_file_write_iter+0x68e/0x2920 fs/f2fs/file.c:5720
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&profile->lock){++++}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3181 [inline]
check_prevs_add kernel/locking/lockdep.c:3300 [inline]
validate_chain kernel/locking/lockdep.c:3924 [inline]
__lock_acquire+0x15ff/0x2e50 kernel/locking/lockdep.c:5254
lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5908
down_write+0x96/0x200 kernel/locking/rwsem.c:1631
blk_crypto_hw_enter block/blk-crypto-profile.c:55 [inline]
__blk_crypto_evict_key+0x111/0x5e0 block/blk-crypto-profile.c:359
blk_crypto_evict_key+0x230/0x3c0 block/blk-crypto.c:443
fscrypt_destroy_inline_crypt_key+0x1b9/0x260 fs/crypto/block.c:164
fscrypt_destroy_prepared_key fs/crypto/keysetup.c:173 [inline]
put_crypt_info+0x110/0x2f0 fs/crypto/keysetup.c:560
fscrypt_put_encryption_info+0xf6/0x140 fs/crypto/keysetup.c:786
f2fs_evict_inode+0x1c9f/0x21f0 fs/f2fs/inode.c:1105
evict+0x624/0xb50 fs/inode.c:822
dispose_list fs/inode.c:864 [inline]
prune_icache_sb+0x223/0x2d0 fs/inode.c:1011
super_cache_scan+0x3f5/0x500 fs/super.c:240
do_shrink_slab+0x6d0/0x10e0 mm/shrinker.c:443
shrink_slab_memcg mm/shrinker.c:560 [inline]
shrink_slab+0x838/0x1220 mm/shrinker.c:638
shrink_one+0x2a2/0x730 mm/vmscan.c:5119
shrink_many mm/vmscan.c:5180 [inline]
lru_gen_shrink_node mm/vmscan.c:5258 [inline]
shrink_node+0x35d0/0x3e30 mm/vmscan.c:6247
kswapd_shrink_node mm/vmscan.c:7101 [inline]
balance_pgdat mm/vmscan.c:7279 [inline]
kswapd+0x185e/0x32c0 mm/vmscan.c:7555
kthread+0x38b/0x480 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(fs_reclaim);
lock(&profile->lock);
lock(fs_reclaim);
lock(&profile->lock);
*** DEADLOCK ***
locks held by kswapd0/77: 2, last CPU#0:
#0: ffffffff8ee91d60 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat mm/vmscan.c:7177 [inline]
#0: ffffffff8ee91d60 (fs_reclaim){+.+.}-{0:0}, at: kswapd+0xa08/0x32c0 mm/vmscan.c:7555
#1: ffff8880355840e8 (&type->s_umount_key#53){.+.+}-{4:4}, at: super_trylock_shared fs/super.c:688 [inline]
#1: ffff8880355840e8 (&type->s_umount_key#53){.+.+}-{4:4}, at: super_cache_scan+0x94/0x500 fs/super.c:213
stack backtrace:
CPU: 0 UID: 0 PID: 77 Comm: kswapd0 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2059
check_noncircular+0x12f/0x150 kernel/locking/lockdep.c:2191
check_prev_add kernel/locking/lockdep.c:3181 [inline]
check_prevs_add kernel/locking/lockdep.c:3300 [inline]
validate_chain kernel/locking/lockdep.c:3924 [inline]
__lock_acquire+0x15ff/0x2e50 kernel/locking/lockdep.c:5254
lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5908
down_write+0x96/0x200 kernel/locking/rwsem.c:1631
blk_crypto_hw_enter block/blk-crypto-profile.c:55 [inline]
__blk_crypto_evict_key+0x111/0x5e0 block/blk-crypto-profile.c:359
blk_crypto_evict_key+0x230/0x3c0 block/blk-crypto.c:443
fscrypt_destroy_inline_crypt_key+0x1b9/0x260 fs/crypto/block.c:164
fscrypt_destroy_prepared_key fs/crypto/keysetup.c:173 [inline]
put_crypt_info+0x110/0x2f0 fs/crypto/keysetup.c:560
fscrypt_put_encryption_info+0xf6/0x140 fs/crypto/keysetup.c:786
f2fs_evict_inode+0x1c9f/0x21f0 fs/f2fs/inode.c:1105
evict+0x624/0xb50 fs/inode.c:822
dispose_list fs/inode.c:864 [inline]
prune_icache_sb+0x223/0x2d0 fs/inode.c:1011
super_cache_scan+0x3f5/0x500 fs/super.c:240
do_shrink_slab+0x6d0/0x10e0 mm/shrinker.c:443
shrink_slab_memcg mm/shrinker.c:560 [inline]
shrink_slab+0x838/0x1220 mm/shrinker.c:638
shrink_one+0x2a2/0x730 mm/vmscan.c:5119
shrink_many mm/vmscan.c:5180 [inline]
lru_gen_shrink_node mm/vmscan.c:5258 [inline]
shrink_node+0x35d0/0x3e30 mm/vmscan.c:6247
kswapd_shrink_node mm/vmscan.c:7101 [inline]
balance_pgdat mm/vmscan.c:7279 [inline]
kswapd+0x185e/0x32c0 mm/vmscan.c:7555
kthread+0x38b/0x480 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Reply: **Bug Analysis:**
The bug report indicates a circular locking dependency (lockdep warning) that leads to a deadlock. The two locks involved are `fs_reclaim` (a pseudo-lock representing memory reclaim context) and `profile->lock` (an `rw_semaphore` protecting a `blk_crypto_profile`).
The dependency chain is as follows:
1. **`profile->lock` -> `fs_reclaim`**: When a process performs I/O on an encrypted file, `blk_crypto_get_keyslot()` is called to prepare the encryption key. It acquires `profile->lock` for write (via `blk_crypto_hw_enter()`) and calls the profile's `keyslot_program` operation. If the underlying block device lacks inline encryption hardware, the `blk-crypto-fallback` is used. The fallback's `blk_crypto_fallback_keyslot_program()` configures the kernel crypto API (e.g., calling `adiantum_setkey()`), which allocates memory using `GFP_KERNEL`. This allocation can trigger direct memory reclaim, effectively acquiring the `fs_reclaim` pseudo-lock.
2. **`fs_reclaim` -> `profile->lock`**: During memory reclaim (either direct reclaim by a user thread or background reclaim by `kswapd`), the kernel may shrink the inode cache and evict inodes to free memory. Evicting an encrypted inode calls `fscrypt_put_encryption_info()`, which destroys the inline crypt key by calling `blk_crypto_evict_key()`. This function calls `blk_crypto_hw_enter()`, which attempts to acquire `profile->lock`.
**Impact:**
This creates a classic AB-BA deadlock (or a self-deadlock if direct reclaim evicts an inode on the same thread). Because the `blk-crypto-fallback` uses a single global profile (`blk_crypto_fallback_profile`), its `profile->lock` is global. A deadlock here will permanently hang any thread attempting to perform I/O on encrypted files using the fallback, and it can also hang `kswapd`, severely impairing the system's ability to manage memory. This results in a reliable **Denial of Service (DoS)**.
Since this is a pure deadlock and does not involve memory corruption, use-after-free, or out-of-bounds accesses, it is **not exploitable** for privilege escalation or arbitrary code execution.
**Accessibility:**
This bug is **accessible from unprivileged processes**. On systems where a supported filesystem (like `ext4` or `f2fs`) is mounted with the `encrypt` feature enabled, any unprivileged user can create a directory, set an encryption policy on it using the `FS_IOC_SET_ENCRYPTION_POLICY` ioctl (which only requires `inode_owner_or_capable`), and write to files within it. By doing so while simultaneously inducing memory pressure (e.g., by allocating large amounts of anonymous memory), an unprivileged user can reliably trigger the deadlock.
|
| 6/2 |
2026/09/02 00:41 |
llm |
expert |
0m
Model:
Tokens:
input: 9621
output: 41
thoughts: 391
Thoughts: **Analyzing a Potential Circular Locking Dependency**
Okay, so I'm looking at this lockdep warning: "WARNING: possible circular locking dependency detected." The kernel's complaining about a potential circular dependency involving `fs_reclaim` and `&profile->lock`. This is a classic concurrency problem, and I need to figure out the exact path.
The reported dependency chain, Chain #1, suggests the following: First, `&profile->lock` is held. Then, later, `fs_reclaim` is acquired. The call stack shows a series of function calls: `__fs_reclaim_acquire`, which, from what I know, triggers the allocation of memory. Then it moves into several key functions: `__kmalloc_noprof`, `adiantum_setkey`, `blk_crypto_fallback_keyslot_program`, `blk_crypto_get_keyslot`, all leading to `f2fs_submit_write_bio` and eventually all the way up to `vfs_write`. This is interesting because I know these are related to writing operations, specifically in the F2FS file system.
But wait a minute... looking at this `blk_crypto_get_keyslot` function... It seems like the code acquires `profile->lock` within that function. This is highly suspicious. If `fs_reclaim` is held during the call to `blk_crypto_get_keyslot`, and `blk_crypto_get_keyslot` itself tries to acquire `&profile->lock` which is held earlier in the process... that's a circular dependency! I'm going to quickly check the code for `blk_crypto_get_keyslot` in `block/blk-crypto-profile.c` to confirm this suspicion, and then work out how to deal with this, if it is confirmed.
|
| 7/2 |
2026/09/02 00:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-crypto-profile.c Name:blk_crypto_get_keyslot]
Results: map[SourceCode: 232: /**
233: * blk_crypto_get_keyslot() - Get a keyslot for a key, if needed.
234: * @profile: the crypto profile of the device the key will be used on
235: * @key: the key that will be used
236: * @slot_ptr: If a keyslot is allocated, an opaque pointer to the keyslot struct
237: * will be stored here. blk_crypto_put_keyslot() must be called
238: * later to release it. Otherwise, NULL will be stored here.
239: *
240: * If the device has keyslots, this gets a keyslot that's been programmed with
241: * the specified key. If the key is already in a slot, this reuses it;
242: * otherwise this waits for a slot to become idle and programs the key into it.
243: *
244: * Context: Process context. Takes and releases profile->lock.
245: * Return: BLK_STS_OK on success, meaning that either a keyslot was allocated or
246: * one wasn't needed; or a blk_status_t error on failure.
247: */
248: blk_status_t blk_crypto_get_keyslot(struct blk_crypto_profile *profile,
249: const struct blk_crypto_key *key,
250: struct blk_crypto_keyslot **slot_ptr)
251: {
252: struct blk_crypto_keyslot *slot;
253: int slot_idx;
254: int err;
255:
256: *slot_ptr = NULL;
257:
258: /*
259: * If the device has no concept of "keyslots", then there is no need to
260: * get one.
261: */
262: if (profile->num_slots == 0)
263: return BLK_STS_OK;
264:
265: down_read(&profile->lock);
266: slot = blk_crypto_find_and_grab_keyslot(profile, key);
267: up_read(&profile->lock);
268: if (slot)
269: goto success;
270:
271: for (;;) {
272: blk_crypto_hw_enter(profile);
273: slot = blk_crypto_find_and_grab_keyslot(profile, key);
274: if (slot) {
275: blk_crypto_hw_exit(profile);
276: goto success;
277: }
278:
279: /*
280: * If we're here, that means there wasn't a slot that was
281: * already programmed with the key. So try to program it.
282: */
283: if (!list_empty(&profile->idle_slots))
284: break;
285:
286: blk_crypto_hw_exit(profile);
287: wait_event(profile->idle_slots_wait_queue,
288: !list_empty(&profile->idle_slots));
289: }
290:
291: slot = list_first_entry(&profile->idle_slots, struct blk_crypto_keyslot,
292: idle_slot_node);
293: slot_idx = blk_crypto_keyslot_index(slot);
294:
295: err = profile->ll_ops.keyslot_program(profile, key, slot_idx);
296: if (err) {
297: wake_up(&profile->idle_slots_wait_queue);
298: blk_crypto_hw_exit(profile);
299: return errno_to_blk_status(err);
300: }
301:
302: /* Move this slot to the hash list for the new key. */
303: if (slot->key)
304: hlist_del(&slot->hash_node);
305: slot->key = key;
306: hlist_add_head(&slot->hash_node,
307: blk_crypto_hash_bucket_for_key(profile, key));
308:
309: atomic_set(&slot->slot_refs, 1);
310:
311: blk_crypto_remove_slot_from_lru_list(slot);
312:
313: blk_crypto_hw_exit(profile);
314: success:
315: *slot_ptr = slot;
316: return BLK_STS_OK;
317: }
SourceFile:block/blk-crypto-profile.c]
|
| 8/2 |
2026/09/02 00:41 |
llm |
expert |
0m
Model:
Tokens:
input: 11835
output: 40
thoughts: 38
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Diving into the Block Crypto Hardware Entry Point**
Right, `blk_crypto_hw_enter(profile)`... that's the function where things start getting interesting. The code mentions it's taking `profile->lock` as an argument and, critically, it's using `down_write`. That's a strong hint β this likely indicates a *writer* lock, which means this function is going to be modifying shared data protected by that lock. The `profile` variable itself probably contains some key configuration settings for the hardware crypto accelerator.
Okay, so I need to understand what's *actually* happening inside `blk_crypto_hw_enter`. Time to go digging into its implementation. I need to figure out what it's protecting and why it needs that write lock. Is it modifying the hardware registers directly? Are there shared data structures involved in key scheduling, buffer management, or context switching that necessitate exclusive access? The *why* is the important part here β is it a performance optimization, is it to enforce serialization, is it a protection mechanism? I need to understand the concurrency implications of this function and how it interfaces with the underlying hardware. Understanding the lock's purpose is key to understanding its implications for performance and, more importantly, correctness. Let's see what the function does.
|
| 9/2 |
2026/09/02 00:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-crypto-profile.c Name:blk_crypto_hw_enter]
Results: map[SourceCode: 45: static inline void blk_crypto_hw_enter(struct blk_crypto_profile *profile)
46: __acquires(&profile->lock)
47: {
48: /*
49: * Calling into the driver requires profile->lock held and the device
50: * resumed. But we must resume the device first, since that can acquire
51: * and release profile->lock via blk_crypto_reprogram_all_keys().
52: */
53: if (profile->dev)
54: pm_runtime_get_sync(profile->dev);
55: down_write(&profile->lock);
56: }
SourceFile:block/blk-crypto-profile.c]
|
| 10/2 |
2026/09/02 00:41 |
llm |
expert |
0m
Model:
Tokens:
input: 12418
output: 43
thoughts: 87
Thoughts: Okay, let's break this down.
**Diving into the Block Crypto Code**
Right, so `blk_crypto_hw_enter` starts by grabbing a write lock with `down_write(&profile->lock)`. Standard protection, I get it. The interesting part is what happens next: it calls `profile->ll_ops.keyslot_program(profile, key, slot_idx)`. That's where the key programming happens. Looking at the trace, the actual function being called is `blk_crypto_fallback_keyslot_program`. My gut tells me this is the entry point for the "software" implementation. Time to check out `blk_crypto_fallback_keyslot_program` and see what the fallback strategy is doing. Let's see if this is an abstraction layer, or something else entirely.
|
| 11/2 |
2026/09/02 00:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-crypto-fallback.c Name:blk_crypto_fallback_keyslot_program]
Results: map[SourceCode: 107: static int
108: blk_crypto_fallback_keyslot_program(struct blk_crypto_profile *profile,
109: const struct blk_crypto_key *key,
110: unsigned int slot)
111: {
112: struct blk_crypto_fallback_keyslot *slotp = &blk_crypto_keyslots[slot];
113: const enum blk_crypto_mode_num crypto_mode =
114: key->crypto_cfg.crypto_mode;
115: int err;
116:
117: if (crypto_mode != slotp->crypto_mode &&
118: slotp->crypto_mode != BLK_ENCRYPTION_MODE_INVALID)
119: blk_crypto_fallback_evict_keyslot(slot);
120:
121: slotp->crypto_mode = crypto_mode;
122: err = crypto_sync_skcipher_setkey(slotp->tfms[crypto_mode], key->bytes,
123: key->size);
124: if (err) {
125: blk_crypto_fallback_evict_keyslot(slot);
126: return err;
127: }
128: return 0;
129: }
SourceFile:block/blk-crypto-fallback.c]
|
| 12/2 |
2026/09/02 00:41 |
llm |
expert |
0m
Model:
Tokens:
input: 13125
output: 35
thoughts: 940
Thoughts: **Analyzing a Potential Lock Dependency Issue**
Okay, so here's what I'm seeing: the `crypto_sync_skcipher_setkey` function eventually calls `adiantum_setkey`. That function then triggers either `kzalloc` or `kmalloc`, and that in turn sets off `fs_reclaim`. This seems straightforward: `profile->lock` then gets involved in the process that goes to `fs_reclaim`.
Now, the interesting part, the dependency chain is #0: `fs_reclaim` is held, and `profile->lock` is acquired. Diving deeper into the stack trace, I see that `kswapd`, when it's handling memory pressure, ends up going down a path that involves `shrink_node`, `shrink_slab`, `super_cache_scan`, and then evicting an inode in `f2fs`. That `evict` operation eventually leads to `fscrypt_destroy_inline_crypt_key` and ultimately calls `down_write(&profile->lock)`. So, the path is clearly: `fs_reclaim` -> `profile->lock`.
Then, I remember `kswapd` actually holds `fs_reclaim` because it sets `PF_MEMALLOC`. Makes sense.
This looks like a classic lockdep warning, meaning there's a circular locking dependency. A circular dependency of locks *could* be exploitable and potentially lead to a deadlock, leading to a denial-of-service condition.
To trigger it, we need two things:
1. `fs_reclaim` -> `profile->lock`: Memory pressure forces `kswapd` to run, which evicts an inode from `f2fs` that contains an inline crypt key. This requires an encrypted `f2fs` filesystem and some memory pressure.
2. `profile->lock` -> `fs_reclaim`: A process writing to an encrypted `f2fs` file triggers `blk_crypto_fallback_keyslot_program`. That allocation should probably trigger memory reclaim, hence, setting off `fs_reclaim`.
Wait a minute... does `adiantum_setkey` allocate with `GFP_KERNEL`?
|
| 13/2 |
2026/09/02 00:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:crypto/adiantum.c Name:adiantum_setkey]
Results: map[SourceCode: 96: /*
97: * Given the XChaCha stream key K_S, derive the block cipher key K_E and the
98: * hash key K_H as follows:
99: *
100: * K_E || K_H || ... = XChaCha(key=K_S, nonce=1||0^191)
101: *
102: * Note that this denotes using bits from the XChaCha keystream, which here we
103: * get indirectly by encrypting a buffer containing all 0's.
104: */
105: static int adiantum_setkey(struct crypto_skcipher *tfm, const u8 *key,
106: unsigned int keylen)
107: {
108: struct adiantum_tfm_ctx *tctx = crypto_skcipher_ctx(tfm);
109: struct {
110: u8 iv[XCHACHA_IV_SIZE];
111: u8 derived_keys[BLOCKCIPHER_KEY_SIZE + HASH_KEY_SIZE];
112: struct scatterlist sg;
113: struct crypto_wait wait;
114: struct skcipher_request req; /* must be last */
115: } *data;
116: u8 *keyp;
117: int err;
118:
119: /* Set the stream cipher key (K_S) */
120: crypto_skcipher_clear_flags(tctx->streamcipher, CRYPTO_TFM_REQ_MASK);
121: crypto_skcipher_set_flags(tctx->streamcipher,
122: crypto_skcipher_get_flags(tfm) &
123: CRYPTO_TFM_REQ_MASK);
124: err = crypto_skcipher_setkey(tctx->streamcipher, key, keylen);
125: if (err)
126: return err;
127:
128: /* Derive the subkeys */
129: data = kzalloc(sizeof(*data) +
130: crypto_skcipher_reqsize(tctx->streamcipher), GFP_KERNEL);
131: if (!data)
132: return -ENOMEM;
133: data->iv[0] = 1;
134: sg_init_one(&data->sg, data->derived_keys, sizeof(data->derived_keys));
135: crypto_init_wait(&data->wait);
136: skcipher_request_set_tfm(&data->req, tctx->streamcipher);
137: skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP |
138: CRYPTO_TFM_REQ_MAY_BACKLOG,
139: crypto_req_done, &data->wait);
140: skcipher_request_set_crypt(&data->req, &data->sg, &data->sg,
141: sizeof(data->derived_keys), data->iv);
142: err = crypto_wait_req(crypto_skcipher_encrypt(&data->req), &data->wait);
143: if (err)
144: goto out;
145: keyp = data->derived_keys;
146:
147: /* Set the block cipher key (K_E) */
148: crypto_cipher_clear_flags(tctx->blockcipher, CRYPTO_TFM_REQ_MASK);
149: crypto_cipher_set_flags(tctx->blockcipher,
150: crypto_skcipher_get_flags(tfm) &
151: CRYPTO_TFM_REQ_MASK);
152: err = crypto_cipher_setkey(tctx->blockcipher, keyp,
153: BLOCKCIPHER_KEY_SIZE);
154: if (err)
155: goto out;
156: keyp += BLOCKCIPHER_KEY_SIZE;
157:
158: /* Set the hash key (K_H) */
159: poly1305_core_setkey(&tctx->header_hash_key, keyp);
160: keyp += POLY1305_BLOCK_SIZE;
161: poly1305_core_setkey(&tctx->msg_poly_key, keyp);
162: keyp += POLY1305_BLOCK_SIZE;
163: for (int i = 0; i < NH_KEY_WORDS; i++)
164: tctx->nh_key[i] = get_unaligned_le32(&keyp[i * 4]);
165: keyp += NH_KEY_BYTES;
166: WARN_ON(keyp != &data->derived_keys[ARRAY_SIZE(data->derived_keys)]);
167: out:
168: kfree_sensitive(data);
169: return err;
170: }
SourceFile:crypto/adiantum.c]
|
| 14/2 |
2026/09/02 00:41 |
llm |
expert |
0m
Model:
Tokens:
input: 15966
output: 40
thoughts: 470
Thoughts: **Deadlock Analysis in Block Crypto and f2fs Encryption**
Okay, so here's the breakdown of what I'm seeing. Line 129 of `adiantum_setkey` uses `GFP_KERNEL` for memory allocation. This is a crucial starting point. Then `blk_crypto_fallback_keyslot_program` gets called, and the `profile->lock` is already held β that comes from the `blk_crypto_get_keyslot` function. So, we've got a `GFP_KERNEL` allocation happening while `profile->lock` is held. This is a recipe for trouble because `GFP_KERNEL` can trigger `fs_reclaim`.
Now, if `fs_reclaim` starts evicting inodes, it might end up calling `blk_crypto_evict_key`. This function then calls `blk_crypto_hw_enter`, and *that's* where we have a problem: it attempts to acquire `profile->lock`. We've got a potential deadlock here: `fs_reclaim` is trying to evict an inode related to the crypto stuff which is trying to acquire the lock that it already holds.
However, I need to double-check this: the `blk_crypto_get_keyslot` function initially takes a read lock with `down_read(&profile->lock)` and then releases it. Then, `blk_crypto_hw_enter(profile)` takes a *write* lock using `down_write(&profile->lock)`. And ultimately, it calls `profile->ll_ops.keyslot_program(profile, key, slot_idx)`. So, the `profile->lock` is held for *write* during `keyslot_program`, confirming the write lock.
Is this deadlock exploitable? Yes, definitely. It's a denial of service, a deadlock.
Can an unprivileged user actually trigger this? Let's see... They could potentially create an encrypted directory on an f2fs filesystem (assuming they have write access and the filesystem is set up for encryption). Then, they write to it and induce memory pressure.
Okay, wait, f2fs encryption uses fscrypt. Does fscrypt allow unprivileged users to create encrypted directories? Yes, fscrypt allows any user with write access to a directory to set an encryption policy on an *empty* directory, and then create files within.
Wait, with fscrypt, the f2fs would need to be mounted with `test_dummy_encryption` or the user to have the key. If the user has the key, they can just use `FS_IOC_ADD_ENCRYPTION_KEY` and `FS_IOC_SET_ENCRYPTION_POLICY`. Good, these ioctls are available to unprivileged users, provided they own the directory or have write access. So, yes, an unprivileged user *can* trigger this. I can see this being a real problem.
|
| 15/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/policy.c Name:fscrypt_ioctl_set_policy]
Results: map[SourceCode: 522: int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
523: {
524: union fscrypt_policy policy;
525: union fscrypt_policy existing_policy;
526: struct inode *inode = file_inode(filp);
527: int size;
528: int ret;
529:
530: if (get_user(policy.version, (const u8 __user *)arg))
531: return -EFAULT;
532:
533: size = fscrypt_policy_size(&policy);
534: if (size <= 0)
535: return -EINVAL;
536:
537: if (copy_from_user((u8 *)&policy + 1, (const u8 __user *)arg + 1,
538: size - 1))
539: return -EFAULT;
540:
541: if (!inode_owner_or_capable(file_mnt_idmap(filp), inode))
542: return -EACCES;
543:
544: ret = mnt_want_write_file(filp);
545: if (ret)
546: return ret;
547:
548: inode_lock(inode);
549:
550: ret = fscrypt_get_policy(inode, &existing_policy);
551: if (ret == -ENODATA) {
552: if (!S_ISDIR(inode->i_mode))
553: ret = -ENOTDIR;
554: else if (IS_DEADDIR(inode))
555: ret = -ENOENT;
556: else if (!inode->i_sb->s_cop->empty_dir(inode))
557: ret = -ENOTEMPTY;
558: else
559: ret = set_encryption_policy(inode, &policy);
560: } else if (ret == -EINVAL ||
561: (ret == 0 && !fscrypt_policies_equal(&policy,
562: &existing_policy))) {
563: /* The file already uses a different encryption policy. */
564: ret = -EEXIST;
565: }
566:
567: inode_unlock(inode);
568:
569: mnt_drop_write_file(filp);
570: return ret;
571: }
SourceFile:fs/crypto/policy.c]
|
| 16/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 17863
output: 40
thoughts: 841
Thoughts: **Deadlock Analysis of Block Device Encryption Fallback**
Okay, so here's what I've got. The core issue revolves around a potential deadlock within the block device encryption fallback mechanism, specifically within the interaction between encryption key management and memory reclaim.
First, an unprivileged user can trigger this. They can set an encryption policy, add a key, write to a file, which leads to `blk_crypto_get_keyslot` and the `blk_crypto_fallback_keyslot_program` execution. The key here is the memory pressure - because, due to memory pressure, `kswapd` might run and attempt to evict an inode. Now, the inode eviction pathway is where things get interesting. Evicting the inode calls `blk_crypto_evict_key`. `blk_crypto_evict_key` eventually calls `fscrypt_put_encryption_info`, triggered via `fscrypt_destroy_inline_crypt_key` and so on, but the *key* (pun intended) is that eviction can be triggered by an unprivileged user through creating and deleting a bunch of files, or due to general memory pressure.
Now the actual deadlock: The Lockdep warning is about `fs_reclaim` and `profile->lock`. Is it a real deadlock? Yes, because here is how it's triggered, which I traced: Thread 1 starts, and executes `blk_crypto_get_keyslot`. That calls `blk_crypto_hw_enter`, which acquires the `profile->lock`, then `keyslot_program`. That calls `kzalloc(GFP_KERNEL)`, which eventually calls `fs_reclaim` which leads to `evict`, which leads to `blk_crypto_evict_key`. That also calls `blk_crypto_hw_enter`, but this time it tries to acquire `profile->lock` which is already held by the first call, so that deadlocks! This is a self-deadlock.
The crucial part is that `fs_reclaim` can recurse back into the same filesystem and evict an inode. So if it evicts an inode using *the same* `profile`, it'll try to acquire the `profile->lock` which it already holds (write lock!), causing a deadlock. `kswapd` or direct reclaim via `prune_icache_sb` and `evict`, can indeed do this. A single thread can thus deadlock itself. Two threads can also deadlock: Thread 1 with `blk_crypto_get_keyslot` blocks on memory reclaim while Thread 2 (`kswapd` and `evict`) is blocked waiting for Thread 1 to release the `profile->lock`, creating an AB-BA deadlock, and this depends on a dependency between memory reclaim.
The deadlock is not exploitable beyond DoS. Since the trace shows `blk_crypto_fallback_keyslot_program`, it means the block device doesn't do inline encryption. The fallback is enabled with `CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK=y`. If the fallback is used, `profile->lock` is the lock of the fallback profile.
The deadlock is accessible by unprivileged processes, assuming the system has an encrypted filesystem.
|
| 17/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-crypto-fallback.c Name:blk_crypto_fallback_init]
Results: map[SourceCode: 531: static int blk_crypto_fallback_init(void)
532: {
533: int i;
534: int err;
535:
536: if (blk_crypto_fallback_inited)
537: return 0;
538:
539: get_random_bytes(blank_key, sizeof(blank_key));
540:
541: err = bioset_init(&enc_bio_set, 64, 0, BIOSET_NEED_BVECS);
542: if (err)
543: goto out;
544:
545: /* Dynamic allocation is needed because of lockdep_register_key(). */
546: blk_crypto_fallback_profile = kzalloc_obj(*blk_crypto_fallback_profile);
547: if (!blk_crypto_fallback_profile) {
548: err = -ENOMEM;
549: goto fail_free_bioset;
550: }
551:
552: err = blk_crypto_profile_init(blk_crypto_fallback_profile,
553: blk_crypto_num_keyslots);
554: if (err)
555: goto fail_free_profile;
556: err = -ENOMEM;
557:
558: blk_crypto_fallback_profile->ll_ops = blk_crypto_fallback_ll_ops;
559: blk_crypto_fallback_profile->max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE;
560: blk_crypto_fallback_profile->key_types_supported = BLK_CRYPTO_KEY_TYPE_RAW;
561:
562: /* All blk-crypto modes have a crypto API fallback. */
563: for (i = 0; i < BLK_ENCRYPTION_MODE_MAX; i++)
564: blk_crypto_fallback_profile->modes_supported[i] = 0xFFFFFFFF;
565: blk_crypto_fallback_profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID] = 0;
566:
567: blk_crypto_wq = alloc_workqueue("blk_crypto_wq",
568: WQ_UNBOUND | WQ_HIGHPRI |
569: WQ_MEM_RECLAIM, num_online_cpus());
570: if (!blk_crypto_wq)
571: goto fail_destroy_profile;
572:
573: blk_crypto_keyslots = kzalloc_objs(blk_crypto_keyslots[0],
574: blk_crypto_num_keyslots);
575: if (!blk_crypto_keyslots)
576: goto fail_free_wq;
577:
578: blk_crypto_bounce_page_pool =
579: mempool_create_page_pool(num_prealloc_bounce_pg, 0);
580: if (!blk_crypto_bounce_page_pool)
581: goto fail_free_keyslots;
582:
583: bio_fallback_crypt_ctx_cache = KMEM_CACHE(bio_fallback_crypt_ctx, 0);
584: if (!bio_fallback_crypt_ctx_cache)
585: goto fail_free_bounce_page_pool;
586:
587: bio_fallback_crypt_ctx_pool =
588: mempool_create_slab_pool(num_prealloc_fallback_crypt_ctxs,
589: bio_fallback_crypt_ctx_cache);
590: if (!bio_fallback_crypt_ctx_pool)
591: goto fail_free_crypt_ctx_cache;
592:
593: blk_crypto_fallback_inited = true;
594:
595: return 0;
596: fail_free_crypt_ctx_cache:
597: kmem_cache_destroy(bio_fallback_crypt_ctx_cache);
598: fail_free_bounce_page_pool:
599: mempool_destroy(blk_crypto_bounce_page_pool);
600: fail_free_keyslots:
601: kfree(blk_crypto_keyslots);
602: fail_free_wq:
603: destroy_workqueue(blk_crypto_wq);
604: fail_destroy_profile:
605: blk_crypto_profile_destroy(blk_crypto_fallback_profile);
606: fail_free_profile:
607: kfree(blk_crypto_fallback_profile);
608: fail_free_bioset:
609: bioset_exit(&enc_bio_set);
610: out:
611: return err;
612: }
SourceFile:block/blk-crypto-fallback.c]
|
| 18/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 20828
output: 35
thoughts: 509
Thoughts: **Deadlock Deep Dive: The Fallback Profile Trap**
Okay, so here's the breakdown of this nasty deadlock, as I understand it. We have this global fallback profile, `blk_crypto_fallback_profile`, and its associated lock, `profile->lock`. The problem arises because of this sequence:
1. `blk_crypto_fallback_keyslot_program` gets called *with* the `profile->lock` already held.
2. Inside, it calls `crypto_sync_skcipher_setkey`. That function, predictably, allocates memory using `GFP_KERNEL`.
3. This memory allocation, as we know, can trigger direct reclaim.
4. Direct reclaim, in turn, can call `evict` on an inode.
5. Now, here's where it gets interesting: `evict` can lead to a call chain: `fscrypt_put_encryption_info` -> `fscrypt_destroy_inline_crypt_key` -> `blk_crypto_evict_key`.
6. The killer is this `blk_crypto_evict_key` function. It calls `blk_crypto_hw_enter`, and *that* attempts to acquire `profile->lock` again.
7. Boom! Deadlock! We're back where we started, trying to re-acquire a lock we *already* have.
Wait a second⦠`blk_crypto_evict_key` is being called on the *same* profile? Yep, that's the kicker. If the evicted inode was using the fallback profile, `blk_crypto_evict_key` will be called on that same fallback profile. Since there's only one, it's a near-guaranteed hit. This is a classic, textbook deadlock.
And the real kicker? An unprivileged user can trigger this, can't they? If they can create encrypted files and induce memory pressure, this is achievable. `fscrypt` is widespread, think Android, ChromeOS, some Linux distros... So it's widely available. And better yet, setting it up doesn't require any special privileges. `FS_IOC_SET_ENCRYPTION_POLICY` is easily called by a directory owner. So a user can create a directory, set an encryption policy, write a bunch of stuff. Boom. Allocate enough memory to trip the direct reclaim, and this deadlock is triggered.
Just to be thorough, I should double check: Does `crypto_sync_skcipher_setkey` always use `GFP_KERNEL`? Tracing shows a call to `adiantum_setkey`. Yep, `adiantum_setkey` allocates with `GFP_KERNEL` through `kzalloc`. OK, what about if the encryption algorithm is something different like AES-XTS?
|
| 19/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:crypto/xts.c Name:xts_setkey]
Results: map[SourceCode: 42: static int xts_setkey(struct crypto_skcipher *parent, const u8 *key,
43: unsigned int keylen)
44: {
45: struct xts_tfm_ctx *ctx = crypto_skcipher_ctx(parent);
46: struct crypto_skcipher *child;
47: struct crypto_cipher *tweak;
48: int err;
49:
50: err = xts_verify_key(parent, key, keylen);
51: if (err)
52: return err;
53:
54: keylen /= 2;
55:
56: /* we need two cipher instances: one to compute the initial 'tweak'
57: * by encrypting the IV (usually the 'plain' iv) and the other
58: * one to encrypt and decrypt the data */
59:
60: /* tweak cipher, uses Key2 i.e. the second half of *key */
61: tweak = ctx->tweak;
62: crypto_cipher_clear_flags(tweak, CRYPTO_TFM_REQ_MASK);
63: crypto_cipher_set_flags(tweak, crypto_skcipher_get_flags(parent) &
64: CRYPTO_TFM_REQ_MASK);
65: err = crypto_cipher_setkey(tweak, key + keylen, keylen);
66: if (err)
67: return err;
68:
69: /* data cipher, uses Key1 i.e. the first half of *key */
70: child = ctx->child;
71: crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
72: crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(parent) &
73: CRYPTO_TFM_REQ_MASK);
74: return crypto_skcipher_setkey(child, key, keylen);
75: }
SourceFile:crypto/xts.c]
|
| 20/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 22543
output: 38
thoughts: 135
Thoughts: **My Initial Thoughts on Memory Allocation with `xts_setkey` and Adiantum**
Okay, so `xts_setkey` itself doesn't appear to be the primary allocator, but it's calling into these `crypto_cipher_setkey` and `crypto_skcipher_setkey` functions. The memory allocation here is probably implementation-dependent. It's possible that something like AES-NI doesn't explicitly allocate, but Adiantum... Adiantum is a different beast entirely. My understanding is that Adiantum *does* leverage `GFP_KERNEL` for memory allocation, which is a key consideration.
Now, Adiantum is definitely supported by `fscrypt`. We know this from things like `FSCRYPT_POLICY_V2` using `FSCRYPT_MODE_ADIANTUM`. This means that an unprivileged user, given the right circumstances, can select Adiantum.
So the question becomes: does `fscrypt` even *allow* the unprivileged user to use Adiantum? That's the critical bit of information I need to check. Let's dig into the details of `fscrypt`'s behavior and see what the constraints are.
|
| 21/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/crypto/policy.c Name:fscrypt_supported_policies]
Results: map[SourceCode: SourceFile:]
|
| 22/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 22994
output: 22
thoughts: 26
Thoughts: Here's my take on the thought process, as if it were my own:
**Investigating Filesystem Encryption Modes**
Okay, so I need to dig into how filesystem encryption modes are handled. My first instinct, given my experience, is to head directly into the kernel source. Specifically, I'm thinking the `fs/crypto` directory is the most likely location for the core encryption logic. Within that, I'm betting that something related to *keysetup* would be the key. Therefore, I'm going to start by checking `fscrypt_modes` in `fs/crypto/keysetup.c`, or a file with a similar name related to key setup, as it's the most probable place for how these modes are defined and configured. That's my initial approach; this seems like the logical starting point for understanding the low-level details.
|
| 23/2 |
2026/09/02 00:42 |
tool |
grepper |
0m
Args: map[Expression:FSCRYPT_MODE_ADIANTUM]
Results: map[Output:Documentation/filesystems/fscrypt.rst=602=This structure must be initialized as follows:
--
Documentation/filesystems/fscrypt.rst-621- (FSCRYPT_MODE_AES_128_CBC, FSCRYPT_MODE_AES_128_CTS), and
Documentation/filesystems/fscrypt.rst:622: (FSCRYPT_MODE_ADIANTUM, FSCRYPT_MODE_ADIANTUM). v2 policies support
Documentation/filesystems/fscrypt.rst-623- all combinations documented in `Supported modes`_.
--
fs/crypto/keysetup.c=17=struct fscrypt_mode fscrypt_modes[] = {
--
fs/crypto/keysetup.c-62- },
fs/crypto/keysetup.c:63: [FSCRYPT_MODE_ADIANTUM] = {
fs/crypto/keysetup.c-64- .friendly_name = "Adiantum",
--
fs/crypto/policy.c=72=static bool fscrypt_valid_enc_modes_v1(u32 contents_mode, u32 filenames_mode)
--
fs/crypto/policy.c-81-
fs/crypto/policy.c:82: if (contents_mode == FSCRYPT_MODE_ADIANTUM &&
fs/crypto/policy.c:83: filenames_mode == FSCRYPT_MODE_ADIANTUM)
fs/crypto/policy.c-84- return true;
--
include/uapi/linux/fscrypt.h-30-#define FSCRYPT_MODE_SM4_CTS 8
include/uapi/linux/fscrypt.h:31:#define FSCRYPT_MODE_ADIANTUM 9
include/uapi/linux/fscrypt.h-32-#define FSCRYPT_MODE_AES_256_HCTR2 10
--
include/uapi/linux/fscrypt.h=146=struct fscrypt_get_key_status_arg {
--
include/uapi/linux/fscrypt.h-191-#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS
include/uapi/linux/fscrypt.h:192:#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM
include/uapi/linux/fscrypt.h-193-#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX
--
tools/include/uapi/linux/fscrypt.h-30-#define FSCRYPT_MODE_SM4_CTS 8
tools/include/uapi/linux/fscrypt.h:31:#define FSCRYPT_MODE_ADIANTUM 9
tools/include/uapi/linux/fscrypt.h-32-#define FSCRYPT_MODE_AES_256_HCTR2 10
--
tools/include/uapi/linux/fscrypt.h=146=struct fscrypt_get_key_status_arg {
--
tools/include/uapi/linux/fscrypt.h-191-#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS
tools/include/uapi/linux/fscrypt.h:192:#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM
tools/include/uapi/linux/fscrypt.h-193-#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX
]
|
| 24/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 24119
output: 41
thoughts: 93
Thoughts: Okay, here's my interpretation of these thoughts, as if they were my own:
**Analyzing the Adiantum Deadlock Scenario**
Right, Adiantum is definitely supported, which is good. That means an unprivileged user can indeed create an Adiantum encrypted directory, write some data, and potentially cause this deadlock. That's the setup.
Now, the lockdep warning is focusing on `profile->lock` and `fs_reclaim`. Hmm, I need to figure out *when* `profile->lock` might be held during the execution of `blk_crypto_fallback_keyslot_program`. My gut tells me there's a problem here. I need to refresh my understanding of where `profile->lock` is used. I'll need to go back and examine `blk_crypto_get_keyslot` again, very carefully. I'm pretty sure I need to trace the execution path from there.
|
| 25/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-crypto-profile.c Name:blk_crypto_get_keyslot]
Results: map[SourceCode: 232: /**
233: * blk_crypto_get_keyslot() - Get a keyslot for a key, if needed.
234: * @profile: the crypto profile of the device the key will be used on
235: * @key: the key that will be used
236: * @slot_ptr: If a keyslot is allocated, an opaque pointer to the keyslot struct
237: * will be stored here. blk_crypto_put_keyslot() must be called
238: * later to release it. Otherwise, NULL will be stored here.
239: *
240: * If the device has keyslots, this gets a keyslot that's been programmed with
241: * the specified key. If the key is already in a slot, this reuses it;
242: * otherwise this waits for a slot to become idle and programs the key into it.
243: *
244: * Context: Process context. Takes and releases profile->lock.
245: * Return: BLK_STS_OK on success, meaning that either a keyslot was allocated or
246: * one wasn't needed; or a blk_status_t error on failure.
247: */
248: blk_status_t blk_crypto_get_keyslot(struct blk_crypto_profile *profile,
249: const struct blk_crypto_key *key,
250: struct blk_crypto_keyslot **slot_ptr)
251: {
252: struct blk_crypto_keyslot *slot;
253: int slot_idx;
254: int err;
255:
256: *slot_ptr = NULL;
257:
258: /*
259: * If the device has no concept of "keyslots", then there is no need to
260: * get one.
261: */
262: if (profile->num_slots == 0)
263: return BLK_STS_OK;
264:
265: down_read(&profile->lock);
266: slot = blk_crypto_find_and_grab_keyslot(profile, key);
267: up_read(&profile->lock);
268: if (slot)
269: goto success;
270:
271: for (;;) {
272: blk_crypto_hw_enter(profile);
273: slot = blk_crypto_find_and_grab_keyslot(profile, key);
274: if (slot) {
275: blk_crypto_hw_exit(profile);
276: goto success;
277: }
278:
279: /*
280: * If we're here, that means there wasn't a slot that was
281: * already programmed with the key. So try to program it.
282: */
283: if (!list_empty(&profile->idle_slots))
284: break;
285:
286: blk_crypto_hw_exit(profile);
287: wait_event(profile->idle_slots_wait_queue,
288: !list_empty(&profile->idle_slots));
289: }
290:
291: slot = list_first_entry(&profile->idle_slots, struct blk_crypto_keyslot,
292: idle_slot_node);
293: slot_idx = blk_crypto_keyslot_index(slot);
294:
295: err = profile->ll_ops.keyslot_program(profile, key, slot_idx);
296: if (err) {
297: wake_up(&profile->idle_slots_wait_queue);
298: blk_crypto_hw_exit(profile);
299: return errno_to_blk_status(err);
300: }
301:
302: /* Move this slot to the hash list for the new key. */
303: if (slot->key)
304: hlist_del(&slot->hash_node);
305: slot->key = key;
306: hlist_add_head(&slot->hash_node,
307: blk_crypto_hash_bucket_for_key(profile, key));
308:
309: atomic_set(&slot->slot_refs, 1);
310:
311: blk_crypto_remove_slot_from_lru_list(slot);
312:
313: blk_crypto_hw_exit(profile);
314: success:
315: *slot_ptr = slot;
316: return BLK_STS_OK;
317: }
SourceFile:block/blk-crypto-profile.c]
|
| 26/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 25840
output: 42
thoughts: 350
Thoughts: **Analyzing a Potential Deadlock in the Block Crypto Hardware Path**
Okay, so looking at this code, it's clear that `blk_crypto_hw_enter(profile)` grabs the write lock, `profile->lock`, using `down_write()`. Then, the `keyslot_program` operation is called through `profile->ll_ops.keyslot_program`. Finally, `blk_crypto_hw_exit(profile)` releases the lock. So, the `profile->lock` is definitely held for writing while `keyslot_program` is running. This setup immediately makes me wonder if a deadlock is possible here.
My initial thought is, can we avoid this lock contention? Perhaps using `GFP_NOFS` or `memalloc_nofs_save()` around the `keyslot_program` call could do the trick. However, I'm already anticipating a potential hurdle. I recall that `blk_crypto_fallback_keyslot_program` calls `crypto_sync_skcipher_setkey`, which leads to `adiantum_setkey`. And, if my memory serves, `adiantum_setkey` uses `GFP_KERNEL` for memory allocation. That's a potential problem because `GFP_KERNEL` might trigger `fs_reclaim`.
So, the key seems to be in `blk_crypto_get_keyslot`. If it uses `memalloc_nofs_save()`, we might be able to prevent `fs_reclaim` from being called, therefore avoiding the deadlock. Let me check if that's the case.
Hmm, it doesn't appear that `blk_crypto_get_keyslot` uses `memalloc_nofs_save()`. Now, I need to trace this call. I see that `blk_crypto_get_keyslot` is called from `blk_crypto_fallback_bio_prep`, which is called from `blk_crypto_submit_bio`, which is then called from `f2fs_submit_write_bio`. This suggests that the whole process flows into F2FS, via `f2fs_submit_write_bio`. Where is this function called from?
Aha! `f2fs_submit_write_bio` gets called during writeback operations. Writeback operations *usually* happen in contexts where `PF_MEMALLOC_NOFS` is set. So, the question is, does the `f2fs_write_data_pages` function set `PF_MEMALLOC_NOFS`? This is the next thing I need to investigate.
|
| 27/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/f2fs/data.c Name:f2fs_write_data_pages]
Results: map[SourceCode:3636: static int f2fs_write_data_pages(struct address_space *mapping,
3637: struct writeback_control *wbc)
3638: {
3639: struct inode *inode = mapping->host;
3640:
3641: return __f2fs_write_data_pages(mapping, wbc,
3642: F2FS_I(inode)->cp_task == current ?
3643: FS_CP_DATA_IO : FS_DATA_IO);
3644: }
SourceFile:fs/f2fs/data.c]
|
| 28/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 26965
output: 43
thoughts: 16
Thoughts: Okay, here's my summary, presented as a stream of thought:
**Diving into the F2FS Write Data Pages Function**
Alright, time to get my hands dirty. Let's start by digging into `__f2fs_write_data_pages`. This is where the rubber meets the road, as they say, for F2FS writes. This is a critical function, and a good place to start my investigation. I need to understand exactly how the data pages are handled, how the metadata is updated in response, and how this all interacts with the wear-leveling and garbage collection mechanisms. This function's probably going to provide clues to any recent issues I've been seeing with my read-write benchmarks and it's a good starting point for a deeper dive.
|
| 29/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/f2fs/data.c Name:__f2fs_write_data_pages]
Results: map[SourceCode:3555: static int __f2fs_write_data_pages(struct address_space *mapping,
3556: struct writeback_control *wbc,
3557: enum iostat_type io_type)
3558: {
3559: struct inode *inode = mapping->host;
3560: struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
3561: struct blk_plug plug;
3562: int ret;
3563: bool locked = false;
3564:
3565: /* skip writing if there is no dirty page in this inode */
3566: if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE)
3567: return 0;
3568:
3569: /* during POR, we don't need to trigger writepage at all. */
3570: if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
3571: goto skip_write;
3572:
3573: if ((S_ISDIR(inode->i_mode) || IS_NOQUOTA(inode)) &&
3574: wbc->sync_mode == WB_SYNC_NONE &&
3575: get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) &&
3576: f2fs_available_free_memory(sbi, DIRTY_DENTS))
3577: goto skip_write;
3578:
3579: /* skip writing in file defragment preparing stage */
3580: if (is_inode_flag_set(inode, FI_SKIP_WRITES))
3581: goto skip_write;
3582:
3583: trace_f2fs_writepages(mapping->host, wbc, DATA);
3584:
3585: /* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */
3586: if (wbc->sync_mode == WB_SYNC_ALL)
3587: atomic_inc(&sbi->wb_sync_req[DATA]);
3588: else if (atomic_read(&sbi->wb_sync_req[DATA])) {
3589: /* to avoid potential deadlock */
3590: if (current->plug)
3591: blk_finish_plug(current->plug);
3592: goto skip_write;
3593: }
3594:
3595: if (__should_serialize_io(inode, wbc)) {
3596: mutex_lock(&sbi->writepages);
3597: locked = true;
3598: }
3599:
3600: account_writeback(inode, true);
3601:
3602: blk_start_plug(&plug);
3603: ret = f2fs_write_cache_pages(mapping, wbc, io_type);
3604: blk_finish_plug(&plug);
3605:
3606: account_writeback(inode, false);
3607:
3608: if (locked)
3609: mutex_unlock(&sbi->writepages);
3610:
3611: if (wbc->sync_mode == WB_SYNC_ALL)
3612: atomic_dec(&sbi->wb_sync_req[DATA]);
3613: /*
3614: * if some pages were truncated, we cannot guarantee its mapping->host
3615: * to detect pending bios.
3616: */
3617:
3618: f2fs_remove_dirty_inode(inode);
3619:
3620: /*
3621: * f2fs_write_cache_pages() has retry logic for EAGAIN case which is
3622: * common when racing w/ checkpoint, so only update skipped write
3623: * when ret is non-zero.
3624: */
3625: if (ret)
3626: update_skipped_write(sbi, wbc);
3627: return ret;
3628:
3629: skip_write:
3630: wbc->pages_skipped += get_dirty_pages(inode);
3631: update_skipped_write(sbi, wbc);
3632: trace_f2fs_writepages(mapping->host, wbc, DATA);
3633: return 0;
3634: }
SourceFile:fs/f2fs/data.c]
|
| 30/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 28467
output: 36
thoughts: 51
Thoughts: **Investigating the PF_MEMALLOC_NOFS Flag in Page Writeback**
Okay, so I'm trying to figure out if something's setting `PF_MEMALLOC_NOFS`. It doesn't *appear* to be happening directly, at least not in the code I'm immediately looking at. Hmm, now where would that be happening? My first thought is to check if `do_writepages` might be the culprit. It's the obvious candidate when considering file system interaction during writeback. Let me go take a look at `do_writepages`... gotta navigate to `mm/page-writeback.c` and see what's actually going on in there. Time to dig in and see if this hunch is correct.
|
| 31/2 |
2026/09/02 00:42 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/page-writeback.c Name:do_writepages]
Results: map[SourceCode:2549: int do_writepages(struct address_space *mapping, struct writeback_control *wbc)
2550: {
2551: int ret;
2552: struct bdi_writeback *wb;
2553:
2554: if (wbc->nr_to_write <= 0)
2555: return 0;
2556: wb = inode_to_wb_wbc(mapping->host, wbc);
2557: wb_bandwidth_estimate_start(wb);
2558: while (1) {
2559: if (mapping->a_ops->writepages)
2560: ret = mapping->a_ops->writepages(mapping, wbc);
2561: else
2562: /* deal with chardevs and other special files */
2563: ret = 0;
2564: if (ret != -ENOMEM || wbc->sync_mode != WB_SYNC_ALL)
2565: break;
2566:
2567: /*
2568: * Lacking an allocation context or the locality or writeback
2569: * state of any of the inode's pages, throttle based on
2570: * writeback activity on the local node. It's as good a
2571: * guess as any.
2572: */
2573: reclaim_throttle(NODE_DATA(numa_node_id()),
2574: VMSCAN_THROTTLE_WRITEBACK);
2575: }
2576: /*
2577: * Usually few pages are written by now from those we've just submitted
2578: * but if there's constant writeback being submitted, this makes sure
2579: * writeback bandwidth is updated once in a while.
2580: */
2581: if (time_is_before_jiffies(READ_ONCE(wb->bw_time_stamp) +
2582: BANDWIDTH_INTERVAL))
2583: wb_update_bandwidth(wb);
2584: return ret;
2585: }
SourceFile:mm/page-writeback.c]
|
| 32/2 |
2026/09/02 00:42 |
llm |
expert |
0m
Model:
Tokens:
input: 29321
output: 39
thoughts: 60
Thoughts: Okay, let's see...
**Analyzing Page Writeback and `PF_MEMALLOC_NOFS`**
Right, I'm pretty sure `do_writepages` *doesn't* set `PF_MEMALLOC_NOFS`. That's not its role. Now, I need to pinpoint where the relevant flag manipulation is actually happening, or not happening. Was it in `filemap_writeback` or perhaps `file_write_and_wait_range`? I should probably check that last function, `file_write_and_wait_range`. It seems the most likely candidate. Let's dig into that code path and confirm.
|
| 33/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/filemap.c Name:file_write_and_wait_range]
Results: map[SourceCode: 761: /**
762: * file_write_and_wait_range - write out & wait on a file range
763: * @file: file pointing to address_space with pages
764: * @lstart: offset in bytes where the range starts
765: * @lend: offset in bytes where the range ends (inclusive)
766: *
767: * Write out and wait upon file offsets lstart->lend, inclusive.
768: *
769: * Note that @lend is inclusive (describes the last byte to be written) so
770: * that this function can be used to write to the very end-of-file (end = -1).
771: *
772: * After writing out and waiting on the data, we check and advance the
773: * f_wb_err cursor to the latest value, and return any errors detected there.
774: *
775: * Return: %0 on success, negative error code otherwise.
776: */
777: int file_write_and_wait_range(struct file *file, loff_t lstart, loff_t lend)
778: {
779: int err = 0, err2;
780: struct address_space *mapping = file->f_mapping;
781:
782: if (lend < lstart)
783: return 0;
784:
785: if (mapping_needs_writeback(mapping)) {
786: err = filemap_fdatawrite_range(mapping, lstart, lend);
787: /* See comment of filemap_write_and_wait() */
788: if (err != -EIO)
789: __filemap_fdatawait_range(mapping, lstart, lend);
790: }
791: err2 = file_check_and_advance_wb_err(file);
792: if (!err)
793: err = err2;
794: return err;
795: }
SourceFile:mm/filemap.c]
|
| 34/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 30165
output: 42
thoughts: 670
Thoughts: **My Analysis of the Potential Deadlock**
Okay, so it appears we have a genuine deadlock situation here. The use of `GFP_KERNEL` is the key β it can trigger `fs_reclaim`, and that's the crucial link. This means it's not a theoretical issue; an unprivileged user can trigger this.
Let's break down the exploitability dimensions. It's not memory corruption or an information leak, but a deadlock due to a circular locking dependency. So:
* **Exploitable:** No. It's a deadlock, not a memory corruption bug.
* **Denial of Service:** Absolutely. A deadlock means the system, or at least the tasks involved (kswapd and the writing task), will hang. If kswapd hangs, it's game over β the system will exhaust memory and potentially crash or panic.
* **Accessible from Unprivileged Processes:** Yes. Users can create encrypted directories (assuming fscrypt is enabled and they have write access to a supported filesystem like f2fs/ext4) and write to those, triggering the deadlock.
* **Accessible from User Namespaces:** Yep, same deal as above.
* **VM Guest Trigger:** Nope, this is a host-level kernel bug.
* **VM Host Trigger in the Confidential Computing Context:** No go.
* **Ethernet Network Trigger:** Not at all.
* **Other Remote Trigger:** Nope.
* **Peripheral Trigger:** No.
* **Malicious Filesystem Trigger:** I initially thought potentially, but it's not a parsing bug, as it's triggered by fscrypt/blk-crypto interaction, not a specific filesystem parsing flaw. I have marked this as false.
While it's *technically* possible to trigger by mounting a malicious filesystem, it's not a core *parsing* bug. The deadlock occurs during normal filesystem operations.
If a malicious filesystem *could* provide encrypted files, then the bug could be triggered, but that is not the primary attack vector. The primary vector is the unprivileged user using the system call. So, False.
Now, let's make sure I'm right about the privileges: `fscrypt_ioctl_set_policy` needs `inode_owner_or_capable`. But that is trivial; Any user can create a directory, even in `/tmp`, and call `FS_IOC_SET_ENCRYPTION_POLICY` on it. After that, they write a file.
That's the trigger for `blk_crypto_get_keyslot`, which calls `blk_crypto_fallback_keyslot_program`. Wait, that function is *only* called if the block device *doesn't* support inline encryption, or if a fallback is forced. By default, if the hardware doesn't support inline encryption, `fscrypt` should use the filesystem's crypto bounce pages, which uses the crypto API directly, not `blk-crypto`.
Wait! Does `fscrypt` actually *use* the `blk-crypto` fallback by default? I need to double-check the `fscrypt` initialization flow. Something is missing here.
|
| 35/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/crypto/inline_crypt.c Name:fscrypt_select_encryption_impl]
Results: map[SourceCode: SourceFile:]
|
| 36/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 31578
output: 42
thoughts: 15
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:
**Analyzing `fscrypt_setup_encryption_info`**
Alright, time to get my head in the game. I need to take a look at `fscrypt_setup_encryption_info`. This is a crucial function, and it's where the rubber meets the road for file system encryption setup. I know the nuances here are critical. I'm thinking, "what's the core purpose? How does it handle key management? Is it considering the different encryption models?" I'm mentally parsing the code, checking for any potential vulnerabilities or logical flaws. Gotta make sure it correctly sets up the encryption parameters, handles key derivation securely, and integrates smoothly with the rest of the file system stack. My focus is on the details now, making sure the setup is secure and robust. I need to understand this function's exact operation thoroughly; the devil is always in the details!
|
| 37/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/keysetup.c Name:fscrypt_setup_encryption_info]
Results: map[SourceCode: 580: static int
581: fscrypt_setup_encryption_info(struct inode *inode,
582: const union fscrypt_policy *policy,
583: const u8 nonce[FSCRYPT_FILE_NONCE_SIZE],
584: bool need_dirhash_key)
585: {
586: struct fscrypt_inode_info *crypt_info;
587: struct fscrypt_mode *mode;
588: struct fscrypt_master_key *mk = NULL;
589: int res;
590:
591: res = fscrypt_initialize(inode->i_sb);
592: if (res)
593: return res;
594:
595: crypt_info = kmem_cache_zalloc(fscrypt_inode_info_cachep, GFP_KERNEL);
596: if (!crypt_info)
597: return -ENOMEM;
598:
599: crypt_info->ci_inode = inode;
600: crypt_info->ci_policy = *policy;
601: memcpy(crypt_info->ci_nonce, nonce, FSCRYPT_FILE_NONCE_SIZE);
602:
603: mode = select_encryption_mode(&crypt_info->ci_policy, inode);
604: if (IS_ERR(mode)) {
605: res = PTR_ERR(mode);
606: goto out;
607: }
608: WARN_ON_ONCE(mode->ivsize > FSCRYPT_MAX_IV_SIZE);
609: crypt_info->ci_mode = mode;
610:
611: crypt_info->ci_data_unit_bits =
612: fscrypt_policy_du_bits(&crypt_info->ci_policy, inode);
613:
614: res = setup_file_encryption_key(crypt_info, need_dirhash_key, &mk);
615: if (res)
616: goto out;
617:
618: /*
619: * For existing inodes, multiple tasks may race to set the inode's
620: * fscrypt info pointer. So use cmpxchg_release(). This pairs with the
621: * smp_load_acquire() in fscrypt_get_inode_info(). I.e., publish the
622: * pointer with a RELEASE barrier so that other tasks can ACQUIRE it.
623: */
624: if (cmpxchg_release(fscrypt_inode_info_addr(inode), NULL, crypt_info) ==
625: NULL) {
626: /*
627: * We won the race and set the inode's fscrypt info to our
628: * crypt_info. Now link it into the master key's inode list.
629: */
630: if (mk) {
631: crypt_info->ci_master_key = mk;
632: refcount_inc(&mk->mk_active_refs);
633: spin_lock(&mk->mk_decrypted_inodes_lock);
634: list_add(&crypt_info->ci_master_key_link,
635: &mk->mk_decrypted_inodes);
636: spin_unlock(&mk->mk_decrypted_inodes_lock);
637: }
638: crypt_info = NULL;
639: }
640: res = 0;
641: out:
642: if (mk) {
643: up_read(&mk->mk_sem);
644: fscrypt_put_master_key(mk);
645: }
646: put_crypt_info(crypt_info);
647: return res;
648: }
SourceFile:fs/crypto/keysetup.c]
|
| 38/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 32983
output: 40
thoughts: 31
Thoughts: Here's my summary, as though I'm thinking through this process:
**Diving into the Encryption Key Setup**
Okay, so I'm digging into how this encryption key is set up. Specifically, I'm looking at `setup_file_encryption_key` and it's calling `fscrypt_setup_inline_crypt_key`. That makes sense. This confirms my expectation that if inline encryption is enabled, that's the function handling the setup. Gotta keep track of that dependency, since inline encryption is important for the performance. Now I need to know under what conditions inline encryption is enabled. It sounds like this is the main entrypoint for the key setup path when inline encryption is the target. I need to make sure I understand the full calling chain, particularly the conditions that *lead* to this specific call. Thatβs probably where Iβll find the relevant configuration.
|
| 39/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/keysetup.c Name:setup_file_encryption_key]
Results: map[SourceCode: 451: /*
452: * Find the master key, then set up the inode's actual encryption key.
453: *
454: * If the master key is found in the filesystem-level keyring, then it is
455: * returned in *mk_ret with its semaphore read-locked. This is needed to ensure
456: * that only one task links the fscrypt_inode_info into ->mk_decrypted_inodes
457: * (as multiple tasks may race to create an fscrypt_inode_info for the same
458: * inode), and to synchronize the master key being removed with a new inode
459: * starting to use it.
460: */
461: static int setup_file_encryption_key(struct fscrypt_inode_info *ci,
462: bool need_dirhash_key,
463: struct fscrypt_master_key **mk_ret)
464: {
465: struct super_block *sb = ci->ci_inode->i_sb;
466: struct fscrypt_key_specifier mk_spec;
467: struct fscrypt_master_key *mk;
468: int err;
469:
470: err = fscrypt_policy_to_key_spec(&ci->ci_policy, &mk_spec);
471: if (err)
472: return err;
473:
474: mk = fscrypt_find_master_key(sb, &mk_spec);
475: if (unlikely(!mk)) {
476: const union fscrypt_policy *dummy_policy =
477: fscrypt_get_dummy_policy(sb);
478:
479: /*
480: * Add the test_dummy_encryption key on-demand. In principle,
481: * it should be added at mount time. Do it here instead so that
482: * the individual filesystems don't need to worry about adding
483: * this key at mount time and cleaning up on mount failure.
484: */
485: if (dummy_policy &&
486: fscrypt_policies_equal(dummy_policy, &ci->ci_policy)) {
487: err = fscrypt_add_test_dummy_key(sb, &mk_spec);
488: if (err)
489: return err;
490: mk = fscrypt_find_master_key(sb, &mk_spec);
491: }
492: }
493: if (unlikely(!mk)) {
494: if (ci->ci_policy.version != FSCRYPT_POLICY_V1)
495: return -ENOKEY;
496:
497: /*
498: * As a legacy fallback for v1 policies, search for the key in
499: * the current task's subscribed keyrings too. Don't move this
500: * to before the search of ->s_master_keys, since users
501: * shouldn't be able to override filesystem-level keys.
502: */
503: return fscrypt_setup_v1_file_key_via_subscribed_keyrings(ci);
504: }
505: down_read(&mk->mk_sem);
506:
507: if (!mk->mk_present) {
508: /* FS_IOC_REMOVE_ENCRYPTION_KEY has been executed on this key */
509: err = -ENOKEY;
510: goto out_release_key;
511: }
512:
513: if (!fscrypt_valid_master_key_size(mk, ci)) {
514: err = -ENOKEY;
515: goto out_release_key;
516: }
517:
518: switch (ci->ci_policy.version) {
519: case FSCRYPT_POLICY_V1:
520: if (WARN_ON_ONCE(mk->mk_secret.is_hw_wrapped)) {
521: /*
522: * This should never happen, as adding a v1 policy key
523: * that is hardware-wrapped isn't allowed.
524: */
525: err = -EINVAL;
526: goto out_release_key;
527: }
528: err = fscrypt_setup_v1_file_key(ci, mk->mk_secret.bytes);
529: break;
530: case FSCRYPT_POLICY_V2:
531: err = fscrypt_setup_v2_file_key(ci, mk, need_dirhash_key);
532: break;
533: default:
534: WARN_ON_ONCE(1);
535: err = -EINVAL;
536: break;
537: }
538: if (err)
539: goto out_release_key;
540:
541: *mk_ret = mk;
542: return 0;
543:
544: out_release_key:
545: up_read(&mk->mk_sem);
546: fscrypt_put_master_key(mk);
547: return err;
548: }
SourceFile:fs/crypto/keysetup.c]
|
| 40/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 34815
output: 45
thoughts: 18
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:
**Analyzing `fscrypt_setup_v2_file_key`**
Alright, time to get into this `fscrypt_setup_v2_file_key` function. I need to refresh my understanding of how this particular piece fits into the overall `fscrypt` architecture. This likely involves key management, file encryption setup, and interactions with the kernel's crypto subsystems, and I need to think through how that's working. I'll need to double check any assumptions about the version being v2, specifically what's changed since v1. Let's see how this function is handling the initialization and association of file keys. Is it calling into the generic key management layer, or are there custom routines here? What about error handling? And how are the keys protected and stored, especially in the context of persistent storage and potential key derivation from user passwords or passphrases? Let's trace it and see how it works.
|
| 41/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/keysetup.c Name:fscrypt_setup_v2_file_key]
Results: map[SourceCode: 354: static int fscrypt_setup_v2_file_key(struct fscrypt_inode_info *ci,
355: struct fscrypt_master_key *mk,
356: bool need_dirhash_key)
357: {
358: int err;
359:
360: if (mk->mk_secret.is_hw_wrapped &&
361: !(ci->ci_policy.v2.flags & (FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 |
362: FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32))) {
363: fscrypt_warn(ci->ci_inode,
364: "Hardware-wrapped keys are only supported with IV_INO_LBLK policies");
365: return -EINVAL;
366: }
367:
368: if (ci->ci_policy.v2.flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
369: /*
370: * DIRECT_KEY: instead of deriving per-file encryption keys, the
371: * per-file nonce will be included in all the IVs. But unlike
372: * v1 policies, for v2 policies in this case we don't encrypt
373: * with the master key directly but rather derive a per-mode
374: * encryption key. This ensures that the master key is
375: * consistently used only for HKDF, avoiding key reuse issues.
376: */
377: err = setup_per_mode_enc_key(ci, mk, HKDF_CONTEXT_DIRECT_KEY,
378: false);
379: } else if (ci->ci_policy.v2.flags &
380: FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) {
381: /*
382: * IV_INO_LBLK_64: encryption keys are derived from (master_key,
383: * mode_num, filesystem_uuid), and inode number is included in
384: * the IVs. This format is optimized for use with inline
385: * encryption hardware compliant with the UFS standard.
386: */
387: err = setup_per_mode_enc_key(
388: ci, mk, HKDF_CONTEXT_IV_INO_LBLK_64_KEY, true);
389: } else if (ci->ci_policy.v2.flags &
390: FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) {
391: err = fscrypt_setup_iv_ino_lblk_32_key(ci, mk);
392: } else {
393: u8 derived_key[FSCRYPT_MAX_RAW_KEY_SIZE];
394:
395: fscrypt_hkdf_expand(&mk->mk_secret.hkdf,
396: HKDF_CONTEXT_PER_FILE_ENC_KEY,
397: ci->ci_nonce, FSCRYPT_FILE_NONCE_SIZE,
398: derived_key, ci->ci_mode->keysize);
399: err = fscrypt_set_per_file_enc_key(ci, derived_key);
400: memzero_explicit(derived_key, sizeof(derived_key));
401: }
402: if (err)
403: return err;
404:
405: /* Derive a secret dirhash key for directories that need it. */
406: if (need_dirhash_key)
407: fscrypt_derive_dirhash_key(ci, mk);
408:
409: return 0;
410: }
SourceFile:fs/crypto/keysetup.c]
|
| 42/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 36187
output: 46
thoughts: 19
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Diving into `fscrypt_set_per_file_enc_key`**
Okay, so I'm focusing in on `fscrypt_set_per_file_enc_key`. Right, this is where the per-file encryption key is set, obviously. Need to refresh my memory on the critical aspects of this function; what are the security assumptions, the potential race conditions, and how does it interact with the key derivation process. I immediately want to think about the key slot management, and how the interaction of that relates to the locking scheme. Gotta consider what happens if a filesystem is mounted and unmounted multiple times, and the impact of setting the encryption key on mounted versus unmounted filesystems. I bet there are some important considerations for the in-memory data structures, cache invalidation, and ensuring key persistence across reboots, that are handled within this context. I should also think about how it's called, especially during file creation and modification, and then after mount/unmount scenarios. Let me double-check the interaction with the key management daemons and any potential vulnerabilities there. I want to make sure I'm fully up to date with any known exploits, and look for any new vectors. Finally, I should look at any existing audit logs/error handling to see if that reveals anything new. It's time to dive in.
|
| 43/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/keysetup.c Name:fscrypt_set_per_file_enc_key]
Results: map[SourceCode: 177: /* Given a per-file encryption key, set up the file's crypto transform object */
178: int fscrypt_set_per_file_enc_key(struct fscrypt_inode_info *ci,
179: const u8 *raw_key)
180: {
181: ci->ci_owns_key = true;
182: return fscrypt_prepare_key(&ci->ci_enc_key, raw_key, ci);
183: }
SourceFile:fs/crypto/keysetup.c]
|
| 44/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 36729
output: 40
thoughts: 13
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `fscrypt_prepare_key`**
Okay, time to dissect `fscrypt_prepare_key`. Given the context, I'm assuming we're dealing with the initialization of keys for filesystem encryption, likely using fs-verity or something similar under the hood. I need to understand exactly how this function prepares the key material. The name itself is somewhat generic, so I need to go beyond the label. Is it loading from persistent storage? Deriving the key from a passphrase or something else? Is it checking key validity or integrity at this stage? Or is it simply setting up internal data structures? The devil, as always, is in the details, especially the error handling - what potential failure modes are considered? Let's trace the arguments and the calling context as a starting point, and get into the code itself. I'm looking for the core logic, anything related to key derivation functions (KDFs), and any security-relevant operations like memory sanitization or secure key storage practices. This is the critical stage, so it had better be robust.
|
| 45/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/keysetup.c Name:fscrypt_prepare_key]
Results: map[SourceCode: 145: /*
146: * Prepare the crypto transform object or blk-crypto key in @prep_key, given the
147: * raw key, encryption mode (@ci->ci_mode), predicate indicating which style of
148: * key is needed (fscrypt_using_inline_encryption(ci)), IV generation method
149: * (@ci->ci_policy.flags), and data unit size (@ci->ci_data_unit_bits).
150: */
151: int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
152: const u8 *raw_key, const struct fscrypt_inode_info *ci)
153: {
154: struct crypto_sync_skcipher *tfm;
155:
156: if (fscrypt_using_inline_encryption(ci))
157: return fscrypt_prepare_inline_crypt_key(prep_key, raw_key,
158: ci->ci_mode->keysize,
159: false, ci);
160:
161: tfm = fscrypt_allocate_skcipher(ci->ci_mode, raw_key, ci->ci_inode);
162: if (IS_ERR(tfm))
163: return PTR_ERR(tfm);
164: prep_key->tfm = tfm;
165: return 0;
166: }
SourceFile:fs/crypto/keysetup.c]
|
| 46/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 37457
output: 44
thoughts: 40
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Checking Inline Encryption Method**
Right, let's see, the goal here is to understand if we're leveraging the `blk-crypto` path. My primary tool for this seems to be `fscrypt_using_inline_encryption(ci)`. That's where I need to focus. I need to understand how *that* function works, what conditions it checks. I'll need to drill down into the implementation of `fscrypt_using_inline_encryption` to fully grasp its logic and, more importantly, *why* it's making the decisions it does about inline encryption. Understanding `fscrypt_using_inline_encryption` is key to figuring out how the system makes a call on `blk-crypto`. I need to figure out how it determines the flag `blk-crypto` in general.
|
| 47/2 |
2026/09/02 00:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/fscrypt_private.h Name:fscrypt_using_inline_encryption]
Results: map[SourceCode: 400: static inline bool
401: fscrypt_using_inline_encryption(const struct fscrypt_inode_info *ci)
402: {
403: const struct inode *inode = ci->ci_inode;
404:
405: return S_ISREG(inode->i_mode) && inode->i_sb->s_cop->is_block_based;
406: }
SourceFile:fs/crypto/fscrypt_private.h]
|
| 48/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 37889
output: 27
thoughts: 193
Thoughts: **My Understanding of `fscrypt` and Block-Based Filesystems**
Okay, so `fscrypt_using_inline_encryption` is always going to return true for *any* regular file on a block-based filesystem like f2fs or ext4. Thatβs interesting. Does that mean it *always* uses `blk-crypto` for regular files then? Yes, of course. Since kernel version 5.15 or so, `fscrypt` defaults to `blk-crypto` for all files on filesystems using block devices. If the underlying block device itself doesn't offer inline encryption capabilities, then the code falls back to `blk-crypto-fallback`. So that means `blk-crypto` *is* always being leveraged for regular files on f2fs and ext4.
This implies that the deadlock situation is extremely simple to trigger. Any unprivileged user who can simply create an encrypted file on either of these filesystems now has the potential to trigger that deadlock.
Now, wait a moment. Is `CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK` enabled by default? Time to consult `block/Kconfig` and verify.
|
| 49/2 |
2026/09/02 00:43 |
tool |
grepper |
0m
Args: map[Expression:config BLK_INLINE_ENCRYPTION_FALLBACK]
Results: map[Output:block/Kconfig=195=config BLK_INLINE_ENCRYPTION
--
block/Kconfig-201-
block/Kconfig:202:config BLK_INLINE_ENCRYPTION_FALLBACK
block/Kconfig-203- bool "Enable crypto API fallback for blk-crypto"
]
|
| 50/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 38448
output: 37
thoughts: 20
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Debugging the Encryption Fallback**
Alright, let's dive in. My immediate thought is to check the default setting for `BLK_INLINE_ENCRYPTION_FALLBACK`. We're likely dealing with an issue related to how inline encryption behaves under specific conditions, and the fallback mechanism is the first place I'd look. Understanding the default state of this crucial parameter is fundamental to isolating the root cause. Depending on the current configuration, its behavior can be vastly different. Is it enabled by default? Disabled? Does the behavior depend on the underlying hardware/software configuration? Any previous or custom settings? Let's verify.
|
| 51/2 |
2026/09/02 00:43 |
tool |
grepper |
0m
Args: map[Expression:config BLK_INLINE_ENCRYPTION_FALLBACK PathPrefix:block/Kconfig]
Results: map[Output:block/Kconfig=195=config BLK_INLINE_ENCRYPTION
--
block/Kconfig-201-
block/Kconfig:202:config BLK_INLINE_ENCRYPTION_FALLBACK
block/Kconfig-203- bool "Enable crypto API fallback for blk-crypto"
]
|
| 52/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 38744
output: 36
thoughts: 17
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Navigating the Kconfig Labyrinth**
Okay, let's dive into the `block/Kconfig` file. I'm specifically interested in getting a handle on the configuration options defined around line 202. I'm probably looking for something specific related to block device handling, maybe a particular feature flag or a dependency definition. I need to understand how some aspect of block device configuration is structured, or perhaps how a new feature I'm working with is introduced into the configuration tree. I know this file can be a bit dense, but with this targeted approach, I should be able to quickly zero in on the relevant details. Let's see what's there...
|
| 53/2 |
2026/09/02 00:43 |
tool |
read-file |
0m
Error:
Args: map[File:block/Kconfig FirstLine:200 LineCount:20]
|
| 54/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 38990
output: 32
thoughts: 11
Thoughts: Okay, I'm ready. Here's my summary, taking the provided thought and putting myself in the role of the expert:
**Integer Interpretation**
Right, okay, so looking at this, the initial assumption I'm making is that "FirstLine" is intended to be an integer. It just *feels* right, based on the context I'm seeing (or assuming). I'm not going to jump to any elaborate conclusions yet, but my gut reaction, based on past experience and patterns I've encountered, is that this variable is numerical and whole.
|
| 55/2 |
2026/09/02 00:43 |
tool |
read-file |
0m
Args: map[File:block/Kconfig FirstLine:200 LineCount:20]
Results: map[Contents: 200: advantage of inline encryption hardware if present.
201:
202: config BLK_INLINE_ENCRYPTION_FALLBACK
203: bool "Enable crypto API fallback for blk-crypto"
204: depends on BLK_INLINE_ENCRYPTION
205: select CRYPTO
206: select CRYPTO_SKCIPHER
207: help
208: Enabling this lets the block layer handle inline encryption
209: by falling back to the kernel crypto API when inline
210: encryption hardware is not present.
211:
212: source "block/partitions/Kconfig"
213:
214: config BLK_PM
215: def_bool PM
216:
217: # do not use in new code
218: config BLOCK_HOLDER_DEPRECATED
219: bool
]
|
| 56/2 |
2026/09/02 00:43 |
llm |
expert |
0m
Model:
Tokens:
input: 39426
output: 27
thoughts: 42
Thoughts: Okay, here's my interpretation of those thoughts, presented as a first-person summary, keeping in mind my expertise:
**Deciphering the Configuration Dependency**
Hmm, this variable is behaving a bit unexpectedly. It doesn't seem to have a defined `default` value, so the system should be falling back to `n` (no). But the fact that `FS_ENCRYPTION` is somehow triggering its selection is peculiar. That suggests a direct or indirect dependency I need to trace. Best to dive into the kernel configuration files. My first instinct is to check `fs/crypto/Kconfig`. That's where I'd expect to find the dependencies related to filesystem encryption options. Let's see if we can find the link there.
|
| 57/2 |
2026/09/02 00:44 |
tool |
grepper |
0m
Args: map[Expression:select BLK_INLINE_ENCRYPTION_FALLBACK]
Results: map[Output:fs/crypto/Kconfig=2=config FS_ENCRYPTION
--
fs/crypto/Kconfig-4- select BLK_INLINE_ENCRYPTION if BLOCK
fs/crypto/Kconfig:5: select BLK_INLINE_ENCRYPTION_FALLBACK if BLOCK
fs/crypto/Kconfig-6- select CRYPTO
]
|
| 58/2 |
2026/09/02 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 39746
output: 30
thoughts: 343
Thoughts: **My Analysis of the Kernel Encryption Deadlock**
Alright, let's break this down. Yes! `FS_ENCRYPTION` automatically implies `BLK_INLINE_ENCRYPTION_FALLBACK` when the block layer is active. Makes sense. So, with `FS_ENCRYPTION` enabled β which is common in a lot of distro kernels, especially for ext4 and f2fs encryption β the fallback mechanism is also enabled.
Okay, the bug centers around this sequence:
1. `blk_crypto_get_keyslot` grabs `profile->lock` for writing.
2. Then it calls `keyslot_program`, which allocates memory using `GFP_KERNEL`. Standard kernel allocation.
3. Memory reclaim kicks in and can evict an inode, which in turn calls `blk_crypto_evict_key`.
4. And *here* is where it goes sideways: `blk_crypto_evict_key` attempts to obtain `profile->lock` for writing.
5. Bam. Deadlock. It's obvious; it's a circular dependency.
This is a clear Denial of Service scenario. An unprivileged user who can create encrypted files and exert memory pressure can trigger this. The critical question: Is it exploitable beyond a DoS? No. It's a lockdep warning, a straightforward deadlock. Deadlocks, while problematic, are not typically a vector for privilege escalation or code execution; they just cause a service interruption, in this case, a DOS.
Just to be absolutely sure, let me confirm that `fscrypt_using_inline_encryption` holds true for regular files. Yes, `S_ISREG(inode->i_mode) && inode->i_sb->s_cop->is_block_based`. For f2fs, `is_block_based` is definitely true. Hold on, need to check `f2fs_cryptops`... gotta dot all the i's and cross the t's.
|
| 59/2 |
2026/09/02 00:44 |
tool |
grepper |
0m
Args: map[Expression:is_block_based PathPrefix:fs/f2fs]
Results: map[Output:fs/f2fs/super.c=3812=static const struct fscrypt_operations f2fs_cryptops = {
--
fs/f2fs/super.c-3814- (int)offsetof(struct f2fs_inode_info, vfs_inode),
fs/f2fs/super.c:3815: .is_block_based = 1,
fs/f2fs/super.c-3816- .has_32bit_inodes = 1,
]
|
| 60/2 |
2026/09/02 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 40688
output: 40
thoughts: 499
Thoughts: **My Analysis of the F2FS Encryption Deadlock**
Okay, the code confirms that if `is_block_based = 1`, then F2FS consistently leverages `blk-crypto` for regular files. Now, I need to understand the potential attack vectors. Can this be triggered remotely? I don't think so. While a remote user *could* create encrypted files through Samba or NFS, the typical setup of encryption policies requires local access or specific ioctls. These aren't usually exposed through standard network protocols, so "Remote Trigger" is a clear no.
What about a "Malicious Filesystem Trigger"? If someone mounts a compromised filesystem image containing an encrypted file, and then tries to read or write to it, that could induce the deadlock. However, the problem isn't in parsing the filesystem image itself. It's in the standard operations of `fscrypt` and `blk-crypto`. So, although mounting a malicious filesystem *is* a prerequisite to hit this bug, it doesn't represent a "malicious filesystem trigger" in the sense of a parsing vulnerability exploit. It's just a way to set the conditions. Mark that as False.
Now, let's nail down the dimensions of this vulnerability. It's not exploitable for code execution, but it's a denial of serviceβTrue. Can unprivileged processes trigger it? Yes, and it looks like any user can use fscrypt on directories they own: True. User namespaces also: True. VM Guest trigger: False. VM Host in confidential computing context: False. Ethernet network trigger: False. Other remote triggers: False. Peripheral trigger: False. Malicious filesystem trigger: False.
Wait, back up. Confirm that "Accessible From Unprivileged Processes" assessment. Does `fscrypt` require a specific mount option? For both ext4 and f2fs, you need the "encrypt" feature enabled in the superblock. But if the feature is enabled, any user can use `FS_IOC_SET_ENCRYPTION_POLICY` on an empty directory they own. Are these encryption features enabled by default in modern distros? Android relies on f2fs/ext4 encryption heavily, and many Linux distributions enable it. So, that unprivileged access *is* the case, and I'll confirm that assessment.
Now, I need to just confirm there are no capability checks inside of the `fscrypt_ioctl_set_policy` function to confirm it.
|
| 61/2 |
2026/09/02 00:44 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/policy.c Name:fscrypt_ioctl_set_policy]
Results: map[SourceCode: 522: int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
523: {
524: union fscrypt_policy policy;
525: union fscrypt_policy existing_policy;
526: struct inode *inode = file_inode(filp);
527: int size;
528: int ret;
529:
530: if (get_user(policy.version, (const u8 __user *)arg))
531: return -EFAULT;
532:
533: size = fscrypt_policy_size(&policy);
534: if (size <= 0)
535: return -EINVAL;
536:
537: if (copy_from_user((u8 *)&policy + 1, (const u8 __user *)arg + 1,
538: size - 1))
539: return -EFAULT;
540:
541: if (!inode_owner_or_capable(file_mnt_idmap(filp), inode))
542: return -EACCES;
543:
544: ret = mnt_want_write_file(filp);
545: if (ret)
546: return ret;
547:
548: inode_lock(inode);
549:
550: ret = fscrypt_get_policy(inode, &existing_policy);
551: if (ret == -ENODATA) {
552: if (!S_ISDIR(inode->i_mode))
553: ret = -ENOTDIR;
554: else if (IS_DEADDIR(inode))
555: ret = -ENOENT;
556: else if (!inode->i_sb->s_cop->empty_dir(inode))
557: ret = -ENOTEMPTY;
558: else
559: ret = set_encryption_policy(inode, &policy);
560: } else if (ret == -EINVAL ||
561: (ret == 0 && !fscrypt_policies_equal(&policy,
562: &existing_policy))) {
563: /* The file already uses a different encryption policy. */
564: ret = -EEXIST;
565: }
566:
567: inode_unlock(inode);
568:
569: mnt_drop_write_file(filp);
570: return ret;
571: }
SourceFile:fs/crypto/policy.c]
|
| 62/2 |
2026/09/02 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 42504
output: 42
thoughts: 354
Thoughts: **My Analysis of the Deadlock Vulnerability**
Okay, so `inode_owner_or_capable` is the *only* check here. That means an unprivileged user can indeed trigger this on their own directories, which is the immediate issue.
Now, how else can we trigger `blk_crypto_get_keyslot`? Aha, reading or writing to an already encrypted file. That's a key point. This means that if there's *any* encrypted file on the system, *any* user with read/write access to it can potentially trigger the `blk_crypto_get_keyslot` function. Combine that with the ability to induce memory pressure, which virtually *any* user can accomplish by simply allocating a large chunk of memory and the vulnerability is open.
But let's dive deeper. The deadlock itself specifically requires `fs_reclaim` to evict an inode that's utilizing `blk-crypto`. So, if either `kswapd` (the kernel swap daemon) or direct reclaim (the synchronous eviction of pages) is responsible for evicting the inode, then the chain of function calls begins. It calls `evict()`, which calls `fscrypt_put_encryption_info()`, which calls `fscrypt_destroy_inline_crypt_key()`, which finally calls `blk_crypto_evict_key()`.
And here's where it gets interesting: `blk_crypto_evict_key()` acquires `profile->lock`. If the thread doing the direct reclaim happens to be the same thread that *already* holds `profile->lock` -- perhaps from being inside `blk_crypto_fallback_keyslot_program` -- it's a guaranteed deadlock.
Or, if another thread, like `kswapd`, is doing the reclaim, it will block on `profile->lock`. Meanwhile, the thread holding `profile->lock` will block while trying to allocate memory while waiting for `kswapd` to release memory, which is blocked. This creates an classic AB-BA deadlock situation.
Yes, the deadlock is very real and easily exploitable. The key vector seems to be read/write access to an encrypted file and inducing memory pressure by allocating a large block of memory.
I should double-check that `fscrypt_destroy_inline_crypt_key` *always* calls `blk_crypto_evict_key`.
|
| 63/2 |
2026/09/02 00:44 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/block.c Name:fscrypt_destroy_inline_crypt_key]
Results: map[SourceCode: 147: void fscrypt_destroy_inline_crypt_key(struct super_block *sb,
148: struct fscrypt_prepared_key *prep_key)
149: {
150: struct blk_crypto_key *blk_key = prep_key->blk_key;
151: struct block_device *devs[FSCRYPT_MAX_DEVICES];
152: unsigned int num_devs;
153: unsigned int i;
154:
155: if (!blk_key)
156: return;
157:
158: /*
159: * Evict the key from all the filesystem's block devices.
160: * This *must* be done before the key is freed.
161: */
162: num_devs = fscrypt_get_devices(sb, devs);
163: for (i = 0; i < num_devs; i++)
164: blk_crypto_evict_key(devs[i], blk_key);
165:
166: kfree_sensitive(blk_key);
167: }
SourceFile:fs/crypto/block.c]
|
| 64/2 |
2026/09/02 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 43766
output: 66
thoughts: 190
Thoughts: **Analyzing the Potential Impact of a Circular Locking Dependency**
Okay, yes, I see the circular dependency. My initial thought is always to consider potential privilege escalation, but in this case, it appears we're dealing with a deadlock caused by a circular locking dependency. The threads involved are going to get stuck in an uninterruptible sleep state, the dreaded `D` state.
While a stuck `kswapd` would eventually lead to an out-of-memory situation and potentially trigger the OOM killer due to impaired memory reclaim, this specific scenario seems more insidious. A user thread being blocked on `down_write(&profile->lock)` is concerning because that `profile->lock` is a GLOBAL lock, specifically for the fallback profile.
The implications are significant! If one thread is stuck, *all* subsequent crypto operations utilizing the fallback profile will also block. This means any other process attempting to read or write encrypted files using that profile will hang. This is a clear and effective Denial of Service (DoS) vulnerability.
However, after a closer look, it's not a memory corruption issue, so we can rule out any direct code execution exploit. At least, not as it stands. For now, it's a DoS, which is still a major problem that needs addressing! Let's get these results set.
|
| 65/2 |
2026/09/02 00:44 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 66/2 |
2026/09/02 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 44361
output: 647
thoughts: 507
Thoughts: **My Analysis of the Filesystem Encryption Deadlock**
Alright, the data's in, and it's time to craft the final response. My analysis has led me to a pretty clear conclusion: we've got a classic circular locking dependency, a deadlock, between `fs_reclaim` (the memory reclaim mechanism) and `profile->lock`, specifically the lock associated with the fallback blk-crypto profile.
Here's the breakdown of the dependency chain as I see it:
1. **`profile->lock` to `fs_reclaim`:** The process begins with encrypted file I/O operations. When a process reads or writes to an encrypted file, `blk_crypto_get_keyslot()` is invoked, leading to the acquisition of `profile->lock`. This happens during the `blk_crypto_hw_enter()` call. From here, `keyslot_program()` is called. If inline encryption isn't supported by the block device, we end up using `blk_crypto_fallback_keyslot_program()`. This function then sets up the necessary crypto keys (e.g., calling `adiantum_setkey()`), and that key setup allocates memory using `GFP_KERNEL`. This allocation, as we all know, can directly trigger memory reclaim β `fs_reclaim` β if the system is under pressure.
2. **`fs_reclaim` to `profile->lock`:** Now, during this memory reclaim phase (whether it's direct reclaim triggered by the allocation or the background `kswapd` process), the kernel might evict inodes to free up memory. When an encrypted inode gets evicted, `fscrypt_put_encryption_info()` is called, which handles the destruction of the inline crypto key by calling `blk_crypto_evict_key()`. This, in turn, calls `blk_crypto_hw_enter()` *again*, and this attempts to acquire `profile->lock`.
The crux of the problem is that if the *same* thread that's currently holding `profile->lock` also ends up triggering direct reclaim, then we get a deadlock: the thread is waiting for itself. Alternatively, if `kswapd` tries to evict an inode while another thread already has `profile->lock`, we end up with an AB-BA deadlock scenario.
Because this fallback profile lock (`profile->lock`) is global, this deadlock effectively hangs all subsequent operations on encrypted files using the fallback and can potentially hang `kswapd`, which then leads to a nasty denial-of-service.
Interestingly, this deadlock can be triggered by unprivileged users. All they have to do is get write access to a filesystem that supports `fscrypt` (e.g., ext4, f2fs) with encryption enabled. They can create a directory, set an encryption policy, write to a file to trigger the keyslot programming, and simultaneously exert enough memory pressure to force reclaim.
The good news (if you can call it that) is that it's a deadlock, so there's no memory corruption or information leak. Therefore, it's not directly exploitable for privilege escalation or code execution.
|
| 67/1 |
2026/09/02 00:44 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis:**
The bug report indicates a circular locking dependency (lockdep warning) that
leads to a deadlock. The two locks involved are `fs_reclaim` (a pseudo-lock
representing memory reclaim context) and `profile->lock` (an `rw_semaphore`
protecting a `blk_crypto_profile`).
The dependency chain is as follows:
1. **`profile->lock` -> `fs_reclaim`**: When a process performs I/O on an
encrypted file, `blk_crypto_get_keyslot()` is called to prepare the encryption
key. It acquires `profile->lock` for write (via `blk_crypto_hw_enter()`) and
calls the profile's `keyslot_program` operation. If the underlying block device
lacks inline encryption hardware, the `blk-crypto-fallback` is used. The
fallback's `blk_crypto_fallback_keyslot_program()` configures the kernel crypto
API (e.g., calling `adiantum_setkey()`), which allocates memory using
`GFP_KERNEL`. This allocation can trigger direct memory reclaim, effectively
acquiring the `fs_reclaim` pseudo-lock.
2. **`fs_reclaim` -> `profile->lock`**: During memory reclaim (either direct
reclaim by a user thread or background reclaim by `kswapd`), the kernel may
shrink the inode cache and evict inodes to free memory. Evicting an encrypted
inode calls `fscrypt_put_encryption_info()`, which destroys the inline crypt key
by calling `blk_crypto_evict_key()`. This function calls
`blk_crypto_hw_enter()`, which attempts to acquire `profile->lock`.
**Impact:**
This creates a classic AB-BA deadlock (or a self-deadlock if direct reclaim
evicts an inode on the same thread). Because the `blk-crypto-fallback` uses a
single global profile (`blk_crypto_fallback_profile`), its `profile->lock` is
global. A deadlock here will permanently hang any thread attempting to perform
I/O on encrypted files using the fallback, and it can also hang `kswapd`,
severely impairing the system's ability to manage memory. This results in a
reliable **Denial of Service (DoS)**.
Since this is a pure deadlock and does not involve memory corruption,
use-after-free, or out-of-bounds accesses, it is **not exploitable** for
privilege escalation or arbitrary code execution.
**Accessibility:**
This bug is **accessible from unprivileged processes**. On systems where a
supported filesystem (like `ext4` or `f2fs`) is mounted with the `encrypt`
feature enabled, any unprivileged user can create a directory, set an encryption
policy on it using the `FS_IOC_SET_ENCRYPTION_POLICY` ioctl (which only requires
`inode_owner_or_capable`), and write to files within it. By doing so while
simultaneously inducing memory pressure (e.g., by allocating large amounts of
anonymous memory), an unprivileged user can reliably trigger the deadlock.]
|