* [BUG 6.4] sched/core: Possible buffer overflow in do_set_cpu_allowed
@ 2023-07-07 20:28 Joe Korty
2023-07-07 23:24 ` Waiman Long
0 siblings, 1 reply; 2+ messages in thread
From: Joe Korty @ 2023-07-07 20:28 UTC (permalink / raw)
To: Waiman Long; +Cc: linux-kernel, Peter Zijlstra, Ingo Molnar
In commit 9a5418bc48bab ("sched/core: Use kfree_rcu() in
do_set_cpus_allowed()"), a kfree_rcu() is used to free a cpu mask.
However, cpu masks can be as short as 8 bytes and this is a problem,
as kfree_rcu requires the to-be freed buffer to be at least 16 bytes.
Thus there is a chance of buffer overflow corruption when the number of
possible cpus in the system is 64 or less.
I have not seen this corruption in the wild. I only noticed this possibility
when reviewing the scheduler differences between 6.1 and 6.4.
Regards,
Joe Korty
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [BUG 6.4] sched/core: Possible buffer overflow in do_set_cpu_allowed
2023-07-07 20:28 [BUG 6.4] sched/core: Possible buffer overflow in do_set_cpu_allowed Joe Korty
@ 2023-07-07 23:24 ` Waiman Long
0 siblings, 0 replies; 2+ messages in thread
From: Waiman Long @ 2023-07-07 23:24 UTC (permalink / raw)
To: Joe Korty; +Cc: linux-kernel, Peter Zijlstra, Ingo Molnar
On 7/7/23 16:28, Joe Korty wrote:
> In commit 9a5418bc48bab ("sched/core: Use kfree_rcu() in
> do_set_cpus_allowed()"), a kfree_rcu() is used to free a cpu mask.
> However, cpu masks can be as short as 8 bytes and this is a problem,
> as kfree_rcu requires the to-be freed buffer to be at least 16 bytes.
> Thus there is a chance of buffer overflow corruption when the number of
> possible cpus in the system is 64 or less.
>
> I have not seen this corruption in the wild. I only noticed this possibility
> when reviewing the scheduler differences between 6.1 and 6.4.
We were aware of this known limitation. If you look at
alloc_user_cpus_ptr():
static cpumask_t *alloc_user_cpus_ptr(int node)
{
/*
* See do_set_cpus_allowed() above for the rcu_head usage.
*/
int size = max_t(int, cpumask_size(), sizeof(struct rcu_head));
return kmalloc_node(size, GFP_KERNEL, node);
}
We made sure that the allocated buffer is big enough to hold struct
rcu_head.
Cheers,
Longman
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-07 23:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07 20:28 [BUG 6.4] sched/core: Possible buffer overflow in do_set_cpu_allowed Joe Korty
2023-07-07 23:24 ` Waiman Long
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox