* [PATCH v2] sched/isolation: Enable cpuset_mutex/cpus_read_lock synchronization before freeing old housekeeping cpumask
@ 2026-11-17 5:18 Waiman Long
2026-11-17 6:43 ` Guopeng Zhang
0 siblings, 1 reply; 2+ messages in thread
From: Waiman Long @ 2026-11-17 5:18 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Tejun Heo,
Frederic Weisbecker
Cc: linux-kernel, Guopeng Zhang, Ridong Chen, Mathieu Desnoyers, Waiman Long
Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
holding cpus_read_lock") adds a new cpuset_top_mutex on top but drops
cpus_read_lock and cpuset_mutex before calling housekeeping_update()
which calls other functions that may acquire cpus_read_lock leading
to a possibility of deadlock if cpus_read_lock isn't dropped before
calling housekeeping_update().
This commit also changes lockdep_is_cpuset_held() to return true if
either cpuset_mutex or cpuset_top_mutex is held. lockdep_is_cpuset_held()
is used by housekeeping_dereference_check() as one of the conditions
that rcu_read_lock() is not needed to access HK_TYPE_DOMAIN
cpumask which can be changed by housekeeping_update() at run
time. The housekeeping_dereference_check() function also uses
lockdep_is_cpus_write_held() as another condition that can skip the
use of rcu_read_lock().
In reality, both cpuset_mutex and cpus_write_lock are now no longer
valid conditions to skip rcu_read_lock(). It is certainly possible
that there can be a parallel housekeeping_update() call going on if
only cpuset_mutex or cpus_write_lock is held. This can lead to a
potential use-after-free situation when HK_TYPE_DOMAIN housekeeping
cpumask is being accessed.
One possible solution is to hold rcu_read_lock for functions that may
be called with only cpuset_mutex or cpus_write_lock is held. Quite a
large number of functions will need to be modified if rcu_read_lock()
has to be added. A far simpler solution is to synchronize with other
cpuset_mutex and cpus_write_lock critical sections before freeing the old
housekeeping cpumask. This will ensure that code within those critical
sections will not have a UaF situation when accessing housekeeping
cpumask. This commit implements the latter solution and make the code
in lockdep_is_cpuset_held() and housekeeping_dereference_check() correct.
Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/sched/isolation.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 156025ef81b7..5634d6a597bd 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -159,6 +159,16 @@ int housekeeping_update(struct cpumask *isol_mask)
err = kthreads_update_housekeeping();
WARN_ON_ONCE(err < 0);
+ /*
+ * Synchronize with cpuset_mutex and cpus_read_lock to make sure that
+ * cpuset_mutex and cpus_write_lock critical sections afterward will
+ * not have access to the old housekeeping cpumask.
+ */
+ cpus_read_lock();
+ cpuset_lock();
+ cpuset_unlock();
+ cpus_read_unlock();
+
kfree(old);
return 0;
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] sched/isolation: Enable cpuset_mutex/cpus_read_lock synchronization before freeing old housekeeping cpumask
2026-11-17 5:18 [PATCH v2] sched/isolation: Enable cpuset_mutex/cpus_read_lock synchronization before freeing old housekeeping cpumask Waiman Long
@ 2026-11-17 6:43 ` Guopeng Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Guopeng Zhang @ 2026-11-17 6:43 UTC (permalink / raw)
To: Waiman Long, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, Tejun Heo,
Frederic Weisbecker
Cc: linux-kernel, Ridong Chen, Mathieu Desnoyers
在 2026/11/17 13:18, Waiman Long 写道:
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") adds a new cpuset_top_mutex on top but drops
> cpus_read_lock and cpuset_mutex before calling housekeeping_update()
> which calls other functions that may acquire cpus_read_lock leading
> to a possibility of deadlock if cpus_read_lock isn't dropped before
> calling housekeeping_update().
>
> This commit also changes lockdep_is_cpuset_held() to return true if
> either cpuset_mutex or cpuset_top_mutex is held. lockdep_is_cpuset_held()
> is used by housekeeping_dereference_check() as one of the conditions
> that rcu_read_lock() is not needed to access HK_TYPE_DOMAIN
> cpumask which can be changed by housekeeping_update() at run
> time. The housekeeping_dereference_check() function also uses
> lockdep_is_cpus_write_held() as another condition that can skip the
> use of rcu_read_lock().
>
> In reality, both cpuset_mutex and cpus_write_lock are now no longer
> valid conditions to skip rcu_read_lock(). It is certainly possible
> that there can be a parallel housekeeping_update() call going on if
> only cpuset_mutex or cpus_write_lock is held. This can lead to a
> potential use-after-free situation when HK_TYPE_DOMAIN housekeeping
> cpumask is being accessed.
>
> One possible solution is to hold rcu_read_lock for functions that may
> be called with only cpuset_mutex or cpus_write_lock is held. Quite a
> large number of functions will need to be modified if rcu_read_lock()
> has to be added. A far simpler solution is to synchronize with other
> cpuset_mutex and cpus_write_lock critical sections before freeing the old
> housekeeping cpumask. This will ensure that code within those critical
> sections will not have a UaF situation when accessing housekeeping
> cpumask. This commit implements the latter solution and make the code
> in lockdep_is_cpuset_held() and housekeeping_dereference_check() correct.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> kernel/sched/isolation.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
> index 156025ef81b7..5634d6a597bd 100644
> --- a/kernel/sched/isolation.c
> +++ b/kernel/sched/isolation.c
> @@ -159,6 +159,16 @@ int housekeeping_update(struct cpumask *isol_mask)
> err = kthreads_update_housekeeping();
> WARN_ON_ONCE(err < 0);
>
> + /*
> + * Synchronize with cpuset_mutex and cpus_read_lock to make sure that
> + * cpuset_mutex and cpus_write_lock critical sections afterward will
> + * not have access to the old housekeeping cpumask.
> + */
> + cpus_read_lock();
> + cpuset_lock();
> + cpuset_unlock();
> + cpus_read_unlock();
> +
> kfree(old);
>
> return 0;
Hi Waiman,
This looks good to me.
Nit: Could the comments in housekeeping_dereference_check() be updated
as well? They seem to be outdated after the locking changes.
Acked-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Thanks,
Guopeng
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 6:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 5:18 [PATCH v2] sched/isolation: Enable cpuset_mutex/cpus_read_lock synchronization before freeing old housekeeping cpumask Waiman Long
2026-11-17 6:43 ` Guopeng Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®