profile: Fix use after free in profile_tick()
PATCH 1/1 profile: Fix use after free in profile_tick()
[free]profiling_store()
--> profile_init()
--> free_cpumask_var(prof_cpu_mask) <-- freed
[use]tick_sched_timer()
--> profile_tick()
--> cpumask_available(prof_cpu_mask) <-- prof_cpu_mask is not NULL
if cpumask offstack
--> cpumask_test_cpu(smp_processor_id(), prof_cpu_mask) <-- use after freeWhen profile_init() failed if prof_buffer is not allocated, prof_cpu_mask will be kfreed by free_cpumask_var() but not set to NULL when CONFIG_CPUMASK_OFFSTACK=y, thus profile_tick() will use prof_cpu_mask after free.
--- kernel/profile.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/profile.c +3 -0
@@ -137,6 +137,9 @@ int __ref profile_init(void)return 0 ;free_cpumask_var (prof_cpu_mask); +#ifdef CONFIG_CPUMASK_OFFSTACK + prof_cpu_mask =NULL ; +#endif return -ENOMEM ; }
Signature · 1 line
2.43.5
Greg KH
maintainerQuoted 40 lines · Xingrui Yi
[free]
profiling_store()
-->profile_init()--> free_cpumask_var(prof_cpu_mask) <-- freed[use]
tick_sched_timer()
-->profile_tick()--> cpumask_available(prof_cpu_mask) <-- prof_cpu_mask is not NULL if cpumask offstack --> cpumask_test_cpu(smp_processor_id(), prof_cpu_mask) <-- use after freeWhen
profile_init()failed ifprof_bufferis not allocated,prof_cpu_maskwill be kfreed byfree_cpumask_var()but not set to NULL whenCONFIG_CPUMASK_OFFSTACK=y, thusprofile_tick()will useprof_cpu_maskafter free.Signed-off-by Xingrui Yi <[email protected]>--- kernel/profile.c | 3 +++ 1 file changed, 3 insertions(+)kernel/profile.c +3
-0@@ -137,6 +137,9 @@ int __ref profile_init(void)return 0 ;free_cpumask_var (prof_cpu_mask); +#ifdef CONFIG_CPUMASK_OFFSTACK + prof_cpu_mask =NULL ; +#endif return -ENOMEM ; }Signature · 1 line
2.43.5
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
No upstream commit was identified. Using temporary commit for testing.
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-5.10.y | Success | Failed |
Build Errors:
Build error for stable/linux-5.10.y:
ssh: connect to host 192.168.1.58 port 22: No route to host