* [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()
@ 2025-09-02 18:15 Waiman Long
2025-09-03 0:39 ` Chen Ridong
2025-09-03 18:40 ` Tejun Heo
0 siblings, 2 replies; 3+ messages in thread
From: Waiman Long @ 2025-09-02 18:15 UTC (permalink / raw)
To: Tejun Heo, Johannes Weiner, Michal Koutný
Cc: cgroups, linux-kernel, Ashay Jaiswal, Chen Ridong, 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")
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>
---
kernel/cgroup/cpuset.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index a78ccd11ce9b..c0c281a8860d 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -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);
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()
2025-09-02 18:15 [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks() Waiman Long
@ 2025-09-03 0:39 ` Chen Ridong
2025-09-03 18:40 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Chen Ridong @ 2025-09-03 0:39 UTC (permalink / raw)
To: Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný
Cc: cgroups, linux-kernel, Ashay Jaiswal, Chen Ridong
On 2025/9/3 2:15, Waiman Long wrote:
> 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>
> ---
> kernel/cgroup/cpuset.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index a78ccd11ce9b..c0c281a8860d 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -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.
--
Best regards,
Ridong
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks()
2025-09-02 18:15 [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks() Waiman Long
2025-09-03 0:39 ` Chen Ridong
@ 2025-09-03 18:40 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2025-09-03 18:40 UTC (permalink / raw)
To: Waiman Long
Cc: Johannes Weiner, Michal Koutný, cgroups, linux-kernel,
Ashay Jaiswal, Chen Ridong
On Tue, Sep 02, 2025 at 02:15:37PM -0400, Waiman Long wrote:
> 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>
Applied to cgroup/for-6.18.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-03 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02 18:15 [PATCH] cgroup/cpuset: Prevent NULL pointer access in free_tmpmasks() Waiman Long
2025-09-03 0:39 ` Chen Ridong
2025-09-03 18:40 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).