HIGH
mm/damon Context UAF
CVE-2026-31652
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
KernelScan AI7.8HIGH
01Description
In the Linux kernel, the following vulnerability has been resolved: mm/damon/stat: deallocate damon_call() failure leaking damon_ctx damon_stat_start() always allocates the module's damon_ctx object (damon_stat_context). Meanwhile, if damon_call() in the function fails, the damon_ctx object is not deallocated. Hence, if the damon_call() is failed, and the user writes Y to “enabled” again, the previously allocated damon_ctx object is leaked. This cannot simply be fixed by deallocating the damon_ctx object when damon_call() fails. That's because damon_call() failure doesn't guarantee the kdamond main function, which accesses the damon_ctx object, is completely finished. In other words, if damon_stat_start() deallocates the damon_ctx object after damon_call() failure, the not-yet-terminated kdamond could access the freed memory (use-after-free). Fix the leak while avoiding the use-after-free by keeping returning damon_stat_start() without deallocating the damon_ctx object after damon_call() failure, but deallocating it when the function is invoked again and the kdamond is completely terminated. If the kdamond is not yet terminated, simply return -EAGAIN, as the kdamond will soon be terminated. The issue was discovered [1] by sashiko.
02KernelScan AI Analysis
Risk summary
A local attacker with sufficient privileges to control DAMON statistics can trigger memory corruption by repeatedly enabling/disabling the feature when the underlying damon_call() fails. This could lead to system crashes or potential privilege escalation through use-after-free exploitation.
Vulnerability analysis
Root Cause: The damon_stat_start() function allocates a damon_ctx object but fails to properly deallocate it when damon_call() fails. This creates a memory leak on subsequent invocations. The vulnerability arises from a race condition where the kdamond thread may still be accessing the damon_ctx object even after damon_call() fails, making immediate deallocation unsafe and potentially causing use-after-free.
Attack Surface: Local attack surface requiring privileged access to write to the DAMON stat 'enabled' sysfs interface. The vulnerability is triggered through repeated enable/disable operations when damon_call() fails, making it dependent on specific timing conditions and system state.
Fix Mechanism: The patch implements a deferred cleanup strategy: (1) On function entry, check if damon_stat_context already exists, (2) If it exists and kdamond is still running, return -EAGAIN to indicate retry needed, (3) If it exists but kdamond has terminated, safely destroy the old context before allocating a new one, (4) Set damon_stat_context to NULL in damon_stat_stop() to ensure proper state tracking. This prevents both memory leaks and use-after-free conditions.
03Fix Versions
| Branch | Fixed in | Patch commit |
|---|---|---|
| 6.18 | 6.18.23 | 447f8870b484 |
| 6.19 | 6.19.13 | 16c92e9bf55f |
| mainline | 7.0 | 4c04c6b47c36 |