]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()
authorWaiman Long <longman@redhat.com>
Tue, 2 Sep 2025 18:15:37 +0000 (14:15 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 3 Sep 2025 18:40:11 +0000 (08:40 -1000)
Commit 5806b3d05165 ("cpuset: decouple tmpmasks and cpumasks freeing in
cgroup") separates out the freeing of tmpmasks into a new free_tmpmask()
helper but removes the NULL pointer check in the process. Unfortunately a
NULL pointer can be passed to free_tmpmasks() in cpuset_handle_hotplug()
if cpuset v1 is active. This can cause segmentation fault and crash
the kernel.

Fix that by adding the NULL pointer check to free_tmpmasks().

Fixes: 5806b3d05165 ("cpuset: decouple tmpmasks and cpumasks freeing in cgroup")
Reported-by: Ashay Jaiswal <quic_ashayj@quicinc.com>
Closes: https://lore.kernel.org/lkml/20250902-cpuset-free-on-condition-v1-1-f46ffab53eac@quicinc.com/
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c

index a78ccd11ce9b43c2e8b0e2c454a8ee845ebdc808..c0c281a8860d3552738bdb3f828e304f1a5532b5 100644 (file)
@@ -484,6 +484,9 @@ static inline int alloc_tmpmasks(struct tmpmasks *tmp)
  */
 static inline void free_tmpmasks(struct tmpmasks *tmp)
 {
+       if (!tmp)
+               return;
+
        free_cpumask_var(tmp->new_cpus);
        free_cpumask_var(tmp->addmask);
        free_cpumask_var(tmp->delmask);