Skip to contentSkip to conversation

cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()

PATCH Applied Waiman Long 3 participants 3 messages Sep 2, 2025 – Sep 3, 2025

Subsystems (2)
lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

PATCH 1/1 cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()

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")
---
 kernel/cgroup/cpuset.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/cgroup/cpuset.c +3 -0
index a78ccd11ce9b..c0c281a8860d 100644
@@ -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);
Signature · 1 line
2.50.1
#1 lore raw
Quoted 22 lines · Waiman Long

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")
---
 kernel/cgroup/cpuset.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/cgroup/cpuset.c +0 -0
index a78ccd11ce9b..c0c281a8860d 100644

kernel/cgroup/cpuset.c static inline int alloc_tmpmasks(struct tmpmasks *tmp) · line 492

Quoted 9 lines
kernel/cgroup/cpuset.c +3 -0
@@ -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);

Thank you, Longman and Ashay.

My apologies for missing the NULL pointer check, which led to this issue.
I have double-checked the free_cpuset function, and it does not receive a NULL pointer as input.

Signature · 2 lines
Best regards,
Ridong
maintainer Applied
#2 lore raw
In reply to Waiman Long
Quoted 7 lines · Waiman Long

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.

Quoted 6 lines

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

Fixes 5806b3d05165 ("cpuset: decouple tmpmasks and cpumasks freeing in cgroup")

Applied to cgroup/for-6.18.

Thanks.

Signature · 1 line
tejun