* [PATCH v3] profiling: don't free prof_cpu_mask on init failure
@ 2026-08-14 22:20 Tristan Madani
2026-08-15 0:53 ` Bradley Morgan
0 siblings, 1 reply; 2+ messages in thread
From: Tristan Madani @ 2026-08-14 22:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Tetsuo Handa, Rusty Russell, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
When profiling is enabled at runtime via /sys/kernel/profiling,
profile_init() allocates prof_cpu_mask then attempts to allocate
prof_buffer. If all prof_buffer allocations fail, the error path
frees prof_cpu_mask but leaves prof_on set.
Since profile_tick() runs from timer interrupt context and reads
prof_cpu_mask on every tick, it can access the freed cpumask between
the free and the next reboot.
Don't free prof_cpu_mask in the error path. The cpumask allocation
already succeeded and is small; keeping it on this rare failure path
avoids the stale access without additional synchronization.
Note: mainline removed prof_cpu_mask entirely in commit 7c51f7bbf057
("profiling: remove prof_cpu_mask"). This is a minimal fix for stable
trees where the variable is still present.
Fixes: c309b917cab55 ("cpumask: convert kernel/profile.c")
Cc: stable@vger.kernel.org
Suggested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
Changes in v3:
- Added comment explaining deliberate leak (Andrew Morton)
- Corrected Fixes tag from 22b8ce94708f to c309b917cab55 (Tetsuo Handa)
- Added stable-only context in commit message
Changes in v2:
- Remove the free_cpumask_var() call instead of adding a prof_on
guard in profile_tick(), which still raced with the free (Tetsuo Handa)
kernel/profile.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/profile.c b/kernel/profile.c
index 984f819b701c9..dcb65a2501558 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -123,7 +123,14 @@ int __ref profile_init(void)
if (prof_buffer)
return 0;
- free_cpumask_var(prof_cpu_mask);
+ /*
+ * Do not free prof_cpu_mask here. profile_tick() accesses it from
+ * timer interrupt context without synchronization, so freeing it
+ * while prof_on is set leads to a stale read. The cpumask is small
+ * and this error path is rare, so the leak is harmless.
+ * This code was removed entirely by commit 7c51f7bbf057
+ * ("profiling: remove prof_cpu_mask") in v6.11.
+ */
return -ENOMEM;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] profiling: don't free prof_cpu_mask on init failure
2026-08-14 22:20 [PATCH v3] profiling: don't free prof_cpu_mask on init failure Tristan Madani
@ 2026-08-15 0:53 ` Bradley Morgan
0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-08-15 0:53 UTC (permalink / raw)
To: tristmd; +Cc: akpm, linux-kernel, penguin-kernel, rusty, stable, tristan
Ummmm, not sure you should replace it with that long of a comment,
What you did was meant to cleanup useless crap. Let's not add more
useless crap by adding 7 new lines. When it could be explained shorter
IMHO, Here's a example, I mean, its not the best, but it works:
/* No need to free prof_cpu_mask()
* anymore, the error path is rare
* and the leak is harmless IMHO
*/
feel free to bikeshed. As per usual.
Also, here's some stable "rules" I tell most people
- Please please please add why this is bad in the commit description (you did that! Yay)
- A splat, please. It helps the stable folks not think that this is another "bug" (Do this if possible)
If I had to say "Bradley, just review this patch for what it does for f*ck
sake", I'd say this patch is useful (sorry for my french!)
So.. here is the tag to add for V4,
Reviewed-by: Bradley Morgan <include@grrlz.net>
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-15 0:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 22:20 [PATCH v3] profiling: don't free prof_cpu_mask on init failure Tristan Madani
2026-08-15 0:53 ` Bradley Morgan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.