From: Waiman Long <longman@redhat.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Tejun Heo <tj@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Guopeng Zhang <guopeng.zhang@linux.dev>,
Ridong Chen <ridong.chen@linux.dev>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH] sched/isolation: Enable cpuset_mutex synchronization before freeing old housekeeping cpumask
Date: Mon, 16 Nov 2026 23:15:55 -0500 [thread overview]
Message-ID: <20261117041555.2421505-1-longman@redhat.com> (raw)
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
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. In reality,
it isn't right to allow holding cpuset_mutex as a condition where
rcu_read_lock isn't needed. It is certainly possible that there can be
a parallel housekeeping_update() call going on if only cpuset_mutex is
being 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 held. Beside some cpuset functions,
several scheduler functions will also need to be changed. A far simpler
solution is to synchronize with other cpuset_mutex critical sections
before freeing the old housekeeping cpumask. This will ensure that code
within cpuset_mutex critical sections will not have a UaF situation
when accessing housekeeping cpumask. This commit implements the latter
solution and make the conditions used by lockdep_is_cpuset_held() 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 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 156025ef81b7..eb4ceeaf0f9d 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -159,6 +159,13 @@ int housekeeping_update(struct cpumask *isol_mask)
err = kthreads_update_housekeeping();
WARN_ON_ONCE(err < 0);
+ /*
+ * Synchronize with cpuset_mutex to make sure that its critical sections
+ * afterward will not have access to the old housekeeping cpumask.
+ */
+ cpuset_lock();
+ cpuset_unlock();
+
kfree(old);
return 0;
--
2.56.0
reply other threads:[~2026-11-17 4:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117041555.2421505-1-longman@redhat.com \
--to=longman@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=guopeng.zhang@linux.dev \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®