CVE-2025-22035: tracing: Fix use-after-free in print_graph_function_flags during tracer switching
In the Linux kernel, the following vulnerability has been resolved:
tracing: Fix use-after-free in printgraphfunctionflags during tracer switching
Kairui reported a UAF issue in printgraphfunctionflags() during ftrace stress testing [1]. This issue can be reproduced if puting a 'mdelay(10)' after 'mutexunlock(&tracetypeslock)' in sstart(), and executing the following script:
$ echo functiongraph > currenttracer $ cat trace > /dev/null & $ sleep 5 # Ensure the 'cat' reaches the 'mdelay(10)' point $ echo timerlat > currenttracer
The root cause lies in the two calls to printgraphfunctionflags within printtraceline during each sshow():
One through 'iter->trace->printline()'; Another through 'event->funcs->trace()', which is hidden in printtracefmt() before printtraceline returns.
Tracer switching only updates the former, while the latter continues to use the printline function of the old tracer, which in the script above is printgraphfunctionflags.
Moreover, when switching from the 'functiongraph' tracer to the 'timerlat' tracer, sstart only calls graphtraceclose of the 'functiongraph' tracer to free 'iter->private', but does not set it to NULL. This provides an opportunity for 'event->funcs->trace()' to use an invalid 'iter->private'.
To fix this issue, set 'iter->private' to NULL immediately after freeing it in graphtraceclose(), ensuring that an invalid pointer is not passed to other tracers. Additionally, clean up the unnecessary 'iter->private = NULL' during each 'cat trace' when using wakeup and irqsoff tracers.
[1] https://lore.kernel.org/all/20231112150030.84609-1-ryncsn@gmail.com/
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 5.15.180.1-1 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 6.6.92.2-1 - Configuration
Apply the described fix: set 'iter->private' to NULL immediately after it is freed in 'graph_trace_close()', preventing an invalid 'iter->private' from being used by other tracers when tracer switching occurs (where the second call path in print_trace_line uses the old/tracer print_line function).
Linux kernel ftrace function_graph tracer switching iter->private cleanup timing in print_graph_function_flags / graph_trace_close = Set iter->private = NULL immediately after freeing iter->private (after graph_trace_close()) to ensure an invalid pointer is not passed to other tracers during tracer switching; ensure it is set to NULL during each cat trace/wakeup path when using mdelay(10) after mutex_unlock(&trace_types_lock) in s_start()
Event History
Frequently Asked Questions
What is the severity of CVE-2025-22035?
CVE-2025-22035 has a medium severity rating, indicating potential risk but not immediate critical exposure.
How do I fix CVE-2025-22035?
To fix CVE-2025-22035, you should update your Linux kernel to the latest version where this vulnerability has been addressed.
What systems are affected by CVE-2025-22035?
CVE-2025-22035 affects the Linux kernel, particularly those versions that utilize the ftrace functionality for tracing.
What kind of attack does CVE-2025-22035 enable?
CVE-2025-22035 can potentially allow an attacker to exploit a use-after-free condition, leading to system instability or possible arbitrary code execution.
Is there a workaround for CVE-2025-22035?
There is no known workaround for CVE-2025-22035, so updating the kernel is the recommended action.