CVE-2024-41057
Severity CVSS v4.0:
Pending analysis
Type:
CWE-416
Use After Free
Publication date:
29/07/2024
Last modified:
03/11/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie()<br />
<br />
We got the following issue in our fault injection stress test:<br />
<br />
==================================================================<br />
BUG: KASAN: slab-use-after-free in cachefiles_withdraw_cookie+0x4d9/0x600<br />
Read of size 8 at addr ffff888118efc000 by task kworker/u78:0/109<br />
<br />
CPU: 13 PID: 109 Comm: kworker/u78:0 Not tainted 6.8.0-dirty #566<br />
Call Trace:<br />
<br />
kasan_report+0x93/0xc0<br />
cachefiles_withdraw_cookie+0x4d9/0x600<br />
fscache_cookie_state_machine+0x5c8/0x1230<br />
fscache_cookie_worker+0x91/0x1c0<br />
process_one_work+0x7fa/0x1800<br />
[...]<br />
<br />
Allocated by task 117:<br />
kmalloc_trace+0x1b3/0x3c0<br />
cachefiles_acquire_volume+0xf3/0x9c0<br />
fscache_create_volume_work+0x97/0x150<br />
process_one_work+0x7fa/0x1800<br />
[...]<br />
<br />
Freed by task 120301:<br />
kfree+0xf1/0x2c0<br />
cachefiles_withdraw_cache+0x3fa/0x920<br />
cachefiles_put_unbind_pincount+0x1f6/0x250<br />
cachefiles_daemon_release+0x13b/0x290<br />
__fput+0x204/0xa00<br />
task_work_run+0x139/0x230<br />
do_exit+0x87a/0x29b0<br />
[...]<br />
==================================================================<br />
<br />
Following is the process that triggers the issue:<br />
<br />
p1 | p2<br />
------------------------------------------------------------<br />
fscache_begin_lookup<br />
fscache_begin_volume_access<br />
fscache_cache_is_live(fscache_cache)<br />
cachefiles_daemon_release<br />
cachefiles_put_unbind_pincount<br />
cachefiles_daemon_unbind<br />
cachefiles_withdraw_cache<br />
fscache_withdraw_cache<br />
fscache_set_cache_state(cache, FSCACHE_CACHE_IS_WITHDRAWN);<br />
cachefiles_withdraw_objects(cache)<br />
fscache_wait_for_objects(fscache)<br />
atomic_read(&fscache_cache->object_count) == 0<br />
fscache_perform_lookup<br />
cachefiles_lookup_cookie<br />
cachefiles_alloc_object<br />
refcount_set(&object->ref, 1);<br />
object->volume = volume<br />
fscache_count_object(vcookie->cache);<br />
atomic_inc(&fscache_cache->object_count)<br />
cachefiles_withdraw_volumes<br />
cachefiles_withdraw_volume<br />
fscache_withdraw_volume<br />
__cachefiles_free_volume<br />
kfree(cachefiles_volume)<br />
fscache_cookie_state_machine<br />
cachefiles_withdraw_cookie<br />
cache = object->volume->cache;<br />
// cachefiles_volume UAF !!!<br />
<br />
After setting FSCACHE_CACHE_IS_WITHDRAWN, wait for all the cookie lookups<br />
to complete first, and then wait for fscache_cache->object_count == 0 to<br />
avoid the cookie exiting after the volume has been freed and triggering<br />
the above issue. Therefore call fscache_withdraw_volume() before calling<br />
cachefiles_withdraw_objects().<br />
<br />
This way, after setting FSCACHE_CACHE_IS_WITHDRAWN, only the following two<br />
cases will occur:<br />
1) fscache_begin_lookup fails in fscache_begin_volume_access().<br />
2) fscache_withdraw_volume() will ensure that fscache_count_object() has<br />
been executed before calling fscache_wait_for_objects().
Impact
Base Score 3.x
7.00
Severity 3.x
HIGH
Vulnerable products and versions
| CPE | From | Up to |
|---|---|---|
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.17 (including) | 6.1.101 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.2 (including) | 6.6.42 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.7 (including) | 6.9.11 (excluding) |
To consult the complete list of CPE names with products and versions, see this page
References to Advisories, Solutions, and Tools
- https://git.kernel.org/stable/c/5d8f805789072ea7fd39504694b7bd17e5f751c4
- https://git.kernel.org/stable/c/8de253177112a47c9af157d23ae934779188b4e1
- https://git.kernel.org/stable/c/9e67589a4a7b7e5660b524d1d5fe61242bcbcc11
- https://git.kernel.org/stable/c/ef81340401e8a371d6b17f69e76d861920972cfe
- https://git.kernel.org/stable/c/5d8f805789072ea7fd39504694b7bd17e5f751c4
- https://git.kernel.org/stable/c/8de253177112a47c9af157d23ae934779188b4e1
- https://git.kernel.org/stable/c/9e67589a4a7b7e5660b524d1d5fe61242bcbcc11
- https://git.kernel.org/stable/c/ef81340401e8a371d6b17f69e76d861920972cfe
- https://lists.debian.org/debian-lts-announce/2025/01/msg00001.html



