* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 8:39 ` [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex Ridong
@ 2026-11-17 16:15 ` Waiman Long
2026-11-18 0:03 ` Ridong Chen
2026-11-17 21:18 ` Tejun Heo
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Waiman Long @ 2026-11-17 16:15 UTC (permalink / raw)
To: Ridong, frederic, tj, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny
Cc: linux-kernel, cgroups, guopeng.zhang, mathieu.desnoyers,
Ridong Chen
On 11/17/26 3:39 AM, Ridong wrote:
> From: Ridong Chen <chenridong@xiaomi.com>
>
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") calls housekeeping_update() after dropping
> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> switched and freed outside of those locks. But readers holding either
> lock may still access it without rcu_read_lock() as allowed by
> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> for them:
>
> CPU A CPU B
> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> mutex_lock(&cpuset_mutex)
> p = housekeeping_cpumask(DOMAIN)
> housekeeping_update()
> rcu_assign_pointer()
> synchronize_rcu()
> kfree(old)
> access p <- UAF
>
> Fix it by moving the pointer switch into housekeeping_publish(), which
> is called before dropping the locks. Then CPU A either finishes before
> CPU B switches the pointer, or only sees the new cpumask:
>
> CPU A CPU B
> cpuset_update_sd_hk_unlock()
> housekeeping_publish()
> rcu_assign_pointer()
> mutex_lock(&cpuset_mutex) <- wait
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> <- new cpumask synchronize_rcu()
> kfree(old)
>
> The rest of housekeeping_update(), including the workqueue flushes,
> still runs without those locks.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
> ---
> include/linux/sched/isolation.h | 6 ++++--
> kernel/cgroup/cpuset.c | 12 ++++++++----
> kernel/sched/isolation.c | 23 ++++++++++++++++-------
> 3 files changed, 28 insertions(+), 13 deletions(-)
>
> diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
> index cf0fd03dd7a24..09fabf42e3224 100644
> --- a/include/linux/sched/isolation.h
> +++ b/include/linux/sched/isolation.h
> @@ -43,7 +43,8 @@ extern const struct cpumask *housekeeping_cpumask(enum hk_type type);
> extern bool housekeeping_enabled(enum hk_type type);
> extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
> extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
> -extern int housekeeping_update(struct cpumask *isol_mask);
> +extern struct cpumask *housekeeping_publish(struct cpumask *isol_mask);
> +extern void housekeeping_update(struct cpumask *isol_mask, struct cpumask *old);
> extern void __init housekeeping_init(void);
>
> #else
> @@ -71,7 +72,8 @@ static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)
> return true;
> }
>
> -static inline int housekeeping_update(struct cpumask *isol_mask) { return 0; }
> +static inline struct cpumask *housekeeping_publish(struct cpumask *isol_mask) { return NULL; }
> +static inline void housekeeping_update(struct cpumask *isol_mask, struct cpumask *old) { }
> static inline void housekeeping_init(void) { }
> #endif /* CONFIG_CPU_ISOLATION */
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 8a8a424a389f3..1673bb25a797b 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1472,17 +1472,21 @@ static void cpuset_update_sd_hk_unlock(void)
> rebuild_sched_domains_locked();
>
> if (update_housekeeping) {
> + struct cpumask *old;
> +
> update_housekeeping = false;
> cpumask_copy(isolated_hk_cpus, isolated_cpus);
>
> /*
> - * housekeeping_update() is now called without holding
> - * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex
> - * is still being held for mutual exclusion.
> + * Publish the new cpumask with cpus_read_lock and cpuset_mutex
> + * held, but call housekeeping_update() without them. Only
> + * cpuset_top_mutex is still being held for mutual exclusion.
> */
> + old = housekeeping_publish(isolated_hk_cpus);
> mutex_unlock(&cpuset_mutex);
> cpus_read_unlock();
> - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus));
> + if (!WARN_ON_ONCE(IS_ERR(old)))
> + housekeeping_update(isolated_hk_cpus, old);
> mutex_unlock(&cpuset_top_mutex);
> } else {
> cpuset_full_unlock();
> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
> index 156025ef81b75..9e202269e42f6 100644
> --- a/kernel/sched/isolation.c
> +++ b/kernel/sched/isolation.c
> @@ -120,23 +120,26 @@ bool housekeeping_test_cpu(int cpu, enum hk_type type)
> }
> EXPORT_SYMBOL_GPL(housekeeping_test_cpu);
>
> -int housekeeping_update(struct cpumask *isol_mask)
> +/* Called with cpus_read_lock and cpuset_mutex held */
> +struct cpumask *housekeeping_publish(struct cpumask *isol_mask)
> {
> struct cpumask *trial, *old = NULL;
> - int err;
> +
> + lockdep_assert_cpus_held();
> + lockdep_assert_cpuset_lock_held();
>
> trial = kmalloc(cpumask_size(), GFP_KERNEL);
> if (!trial)
> - return -ENOMEM;
> + return ERR_PTR(-ENOMEM);
>
> cpumask_andnot(trial, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT), isol_mask);
> if (!cpumask_intersects(trial, cpu_online_mask)) {
> kfree(trial);
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> }
>
> if (!housekeeping.flags)
> - static_branch_enable(&housekeeping_overridden);
> + static_branch_enable_cpuslocked(&housekeeping_overridden);
>
> if (housekeeping.flags & HK_FLAG_DOMAIN)
> old = housekeeping_cpumask_dereference(HK_TYPE_DOMAIN);
> @@ -144,6 +147,14 @@ int housekeeping_update(struct cpumask *isol_mask)
> WRITE_ONCE(housekeeping.flags, housekeeping.flags | HK_FLAG_DOMAIN);
> rcu_assign_pointer(housekeeping.cpumasks[HK_TYPE_DOMAIN], trial);
>
> + return old;
> +}
> +
> +/* Called without cpus_read_lock and cpuset_mutex held */
> +void housekeeping_update(struct cpumask *isol_mask, struct cpumask *old)
> +{
> + int err;
> +
> synchronize_rcu();
>
> pci_probe_flush_workqueue();
> @@ -160,8 +171,6 @@ int housekeeping_update(struct cpumask *isol_mask)
> WARN_ON_ONCE(err < 0);
>
> kfree(old);
> -
> - return 0;
> }
>
> void __init housekeeping_init(void)
Yes, that should work too.
Acked-by: Waiman Long <longman@redhat.com>
I will let other decide which one do they want.
Cheers,
Longman
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 16:15 ` Waiman Long
@ 2026-11-18 0:03 ` Ridong Chen
0 siblings, 0 replies; 14+ messages in thread
From: Ridong Chen @ 2026-11-18 0:03 UTC (permalink / raw)
To: Waiman Long, frederic, tj, peterz, mingo, juri.lelli,
vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
vschneid, kprateek.nayak, hannes, mkoutny
Cc: linux-kernel, cgroups, guopeng.zhang, mathieu.desnoyers,
Ridong Chen
On 11/18/2026 12:15 AM, Waiman Long wrote:
> On 11/17/26 3:39 AM, Ridong wrote:
>> From: Ridong Chen <chenridong@xiaomi.com>
>>
>> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
>> holding cpus_read_lock") calls housekeeping_update() after dropping
>> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
>> switched and freed outside of those locks. But readers holding either
>> lock may still access it without rcu_read_lock() as allowed by
>> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
>> for them:
>>
>> CPU A CPU B
>> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
>> mutex_unlock(&cpuset_mutex)
>> cpus_read_unlock()
>> mutex_lock(&cpuset_mutex)
>> p = housekeeping_cpumask(DOMAIN)
>> housekeeping_update()
>> rcu_assign_pointer()
>> synchronize_rcu()
>> kfree(old)
>> access p <- UAF
>>
>> Fix it by moving the pointer switch into housekeeping_publish(), which
>> is called before dropping the locks. Then CPU A either finishes before
>> CPU B switches the pointer, or only sees the new cpumask:
>>
>> CPU A CPU B
>> cpuset_update_sd_hk_unlock()
>> housekeeping_publish()
>> rcu_assign_pointer()
>> mutex_lock(&cpuset_mutex) <- wait
>> mutex_unlock(&cpuset_mutex)
>> cpus_read_unlock()
>> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
>> <- new cpumask synchronize_rcu()
>> kfree(old)
>>
>> The rest of housekeeping_update(), including the workqueue flushes,
>> still runs without those locks.
>>
>> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
>> holding cpus_read_lock")
>> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
>> ---
>> include/linux/sched/isolation.h | 6 ++++--
>> kernel/cgroup/cpuset.c | 12 ++++++++----
>> kernel/sched/isolation.c | 23 ++++++++++++++++-------
>> 3 files changed, 28 insertions(+), 13 deletions(-)
>>
>> diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
>> index cf0fd03dd7a24..09fabf42e3224 100644
>> --- a/include/linux/sched/isolation.h
>> +++ b/include/linux/sched/isolation.h
>> @@ -43,7 +43,8 @@ extern const struct cpumask *housekeeping_cpumask(enum
>> hk_type type);
>> extern bool housekeeping_enabled(enum hk_type type);
>> extern void housekeeping_affine(struct task_struct *t, enum hk_type type);
>> extern bool housekeeping_test_cpu(int cpu, enum hk_type type);
>> -extern int housekeeping_update(struct cpumask *isol_mask);
>> +extern struct cpumask *housekeeping_publish(struct cpumask *isol_mask);
>> +extern void housekeeping_update(struct cpumask *isol_mask, struct cpumask *old);
>> extern void __init housekeeping_init(void);
>> #else
>> @@ -71,7 +72,8 @@ static inline bool housekeeping_test_cpu(int cpu, enum
>> hk_type type)
>> return true;
>> }
>> -static inline int housekeeping_update(struct cpumask *isol_mask) { return 0; }
>> +static inline struct cpumask *housekeeping_publish(struct cpumask *isol_mask)
>> { return NULL; }
>> +static inline void housekeeping_update(struct cpumask *isol_mask, struct
>> cpumask *old) { }
>> static inline void housekeeping_init(void) { }
>> #endif /* CONFIG_CPU_ISOLATION */
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 8a8a424a389f3..1673bb25a797b 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -1472,17 +1472,21 @@ static void cpuset_update_sd_hk_unlock(void)
>> rebuild_sched_domains_locked();
>> if (update_housekeeping) {
>> + struct cpumask *old;
>> +
>> update_housekeeping = false;
>> cpumask_copy(isolated_hk_cpus, isolated_cpus);
>> /*
>> - * housekeeping_update() is now called without holding
>> - * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex
>> - * is still being held for mutual exclusion.
>> + * Publish the new cpumask with cpus_read_lock and cpuset_mutex
>> + * held, but call housekeeping_update() without them. Only
>> + * cpuset_top_mutex is still being held for mutual exclusion.
>> */
>> + old = housekeeping_publish(isolated_hk_cpus);
>> mutex_unlock(&cpuset_mutex);
>> cpus_read_unlock();
>> - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus));
>> + if (!WARN_ON_ONCE(IS_ERR(old)))
>> + housekeeping_update(isolated_hk_cpus, old);
>> mutex_unlock(&cpuset_top_mutex);
>> } else {
>> cpuset_full_unlock();
>> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
>> index 156025ef81b75..9e202269e42f6 100644
>> --- a/kernel/sched/isolation.c
>> +++ b/kernel/sched/isolation.c
>> @@ -120,23 +120,26 @@ bool housekeeping_test_cpu(int cpu, enum hk_type type)
>> }
>> EXPORT_SYMBOL_GPL(housekeeping_test_cpu);
>> -int housekeeping_update(struct cpumask *isol_mask)
>> +/* Called with cpus_read_lock and cpuset_mutex held */
>> +struct cpumask *housekeeping_publish(struct cpumask *isol_mask)
>> {
>> struct cpumask *trial, *old = NULL;
>> - int err;
>> +
>> + lockdep_assert_cpus_held();
>> + lockdep_assert_cpuset_lock_held();
>> trial = kmalloc(cpumask_size(), GFP_KERNEL);
>> if (!trial)
>> - return -ENOMEM;
>> + return ERR_PTR(-ENOMEM);
>> cpumask_andnot(trial, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT),
>> isol_mask);
>> if (!cpumask_intersects(trial, cpu_online_mask)) {
>> kfree(trial);
>> - return -EINVAL;
>> + return ERR_PTR(-EINVAL);
>> }
>> if (!housekeeping.flags)
>> - static_branch_enable(&housekeeping_overridden);
>> + static_branch_enable_cpuslocked(&housekeeping_overridden);
>> if (housekeeping.flags & HK_FLAG_DOMAIN)
>> old = housekeeping_cpumask_dereference(HK_TYPE_DOMAIN);
>> @@ -144,6 +147,14 @@ int housekeeping_update(struct cpumask *isol_mask)
>> WRITE_ONCE(housekeeping.flags, housekeeping.flags | HK_FLAG_DOMAIN);
>> rcu_assign_pointer(housekeeping.cpumasks[HK_TYPE_DOMAIN], trial);
>> + return old;
>> +}
>> +
>> +/* Called without cpus_read_lock and cpuset_mutex held */
>> +void housekeeping_update(struct cpumask *isol_mask, struct cpumask *old)
>> +{
>> + int err;
>> +
>> synchronize_rcu();
>> pci_probe_flush_workqueue();
>> @@ -160,8 +171,6 @@ int housekeeping_update(struct cpumask *isol_mask)
>> WARN_ON_ONCE(err < 0);
>> kfree(old);
>> -
>> - return 0;
>> }
>> void __init housekeeping_init(void)
>
> Yes, that should work too.
>
> Acked-by: Waiman Long <longman@redhat.com>
>
> I will let other decide which one do they want.
>
Thanks.
--
Best regards
Ridong
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 8:39 ` [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex Ridong
2026-11-17 16:15 ` Waiman Long
@ 2026-11-17 21:18 ` Tejun Heo
2026-11-18 14:20 ` Frederic Weisbecker
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Tejun Heo @ 2026-11-17 21:18 UTC (permalink / raw)
To: Ridong
Cc: longman, frederic, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny, linux-kernel, cgroups,
guopeng.zhang, mathieu.desnoyers, Ridong Chen
On Tue, Nov 17, 2026 at 04:39:15PM +0800, Ridong wrote:
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") calls housekeeping_update() after dropping
> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> switched and freed outside of those locks. But readers holding either
> lock may still access it without rcu_read_lock() as allowed by
> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> for them:
>
> CPU A CPU B
> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> mutex_lock(&cpuset_mutex)
> p = housekeeping_cpumask(DOMAIN)
> housekeeping_update()
> rcu_assign_pointer()
> synchronize_rcu()
> kfree(old)
> access p <- UAF
>
> Fix it by moving the pointer switch into housekeeping_publish(), which
> is called before dropping the locks. Then CPU A either finishes before
> CPU B switches the pointer, or only sees the new cpumask:
>
> CPU A CPU B
> cpuset_update_sd_hk_unlock()
> housekeeping_publish()
> rcu_assign_pointer()
> mutex_lock(&cpuset_mutex) <- wait
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> <- new cpumask synchronize_rcu()
> kfree(old)
>
> The rest of housekeeping_update(), including the workqueue flushes,
> still runs without those locks.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 8:39 ` [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex Ridong
2026-11-17 16:15 ` Waiman Long
2026-11-17 21:18 ` Tejun Heo
@ 2026-11-18 14:20 ` Frederic Weisbecker
2026-11-18 17:16 ` Waiman Long
2026-11-27 2:15 ` Ridong Chen
2026-11-27 13:13 ` Frederic Weisbecker
4 siblings, 1 reply; 14+ messages in thread
From: Frederic Weisbecker @ 2026-11-18 14:20 UTC (permalink / raw)
To: Ridong
Cc: longman, tj, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny, linux-kernel, cgroups,
guopeng.zhang, mathieu.desnoyers, Ridong Chen
Le Tue, Nov 17, 2026 at 04:39:15PM +0800, Ridong a écrit :
> From: Ridong Chen <chenridong@xiaomi.com>
>
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") calls housekeeping_update() after dropping
> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> switched and freed outside of those locks. But readers holding either
> lock may still access it without rcu_read_lock() as allowed by
> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> for them:
>
> CPU A CPU B
> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> mutex_lock(&cpuset_mutex)
> p = housekeeping_cpumask(DOMAIN)
> housekeeping_update()
> rcu_assign_pointer()
> synchronize_rcu()
> kfree(old)
> access p <- UAF
>
> Fix it by moving the pointer switch into housekeeping_publish(), which
> is called before dropping the locks. Then CPU A either finishes before
> CPU B switches the pointer, or only sees the new cpumask:
>
> CPU A CPU B
> cpuset_update_sd_hk_unlock()
> housekeeping_publish()
> rcu_assign_pointer()
> mutex_lock(&cpuset_mutex) <- wait
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> <- new cpumask synchronize_rcu()
> kfree(old)
>
> The rest of housekeeping_update(), including the workqueue flushes,
> still runs without those locks.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
Ok that should work but, IIRC this whole locking puzzle is there because
cpuset_handle_hotplug() can change isolated partitions. Why is it the case
since cpuset.cpus shouldn't care about offline CPUs?
I remember Waiman said it could be fixed in the long run. I don't remember
the details though.
Thanks.
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-18 14:20 ` Frederic Weisbecker
@ 2026-11-18 17:16 ` Waiman Long
0 siblings, 0 replies; 14+ messages in thread
From: Waiman Long @ 2026-11-18 17:16 UTC (permalink / raw)
To: Frederic Weisbecker, Ridong
Cc: tj, peterz, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, vschneid, kprateek.nayak, hannes,
mkoutny, linux-kernel, cgroups, guopeng.zhang, mathieu.desnoyers,
Ridong Chen
On 11/18/26 9:20 AM, Frederic Weisbecker wrote:
> Le Tue, Nov 17, 2026 at 04:39:15PM +0800, Ridong a écrit :
>> From: Ridong Chen <chenridong@xiaomi.com>
>>
>> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
>> holding cpus_read_lock") calls housekeeping_update() after dropping
>> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
>> switched and freed outside of those locks. But readers holding either
>> lock may still access it without rcu_read_lock() as allowed by
>> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
>> for them:
>>
>> CPU A CPU B
>> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
>> mutex_unlock(&cpuset_mutex)
>> cpus_read_unlock()
>> mutex_lock(&cpuset_mutex)
>> p = housekeeping_cpumask(DOMAIN)
>> housekeeping_update()
>> rcu_assign_pointer()
>> synchronize_rcu()
>> kfree(old)
>> access p <- UAF
>>
>> Fix it by moving the pointer switch into housekeeping_publish(), which
>> is called before dropping the locks. Then CPU A either finishes before
>> CPU B switches the pointer, or only sees the new cpumask:
>>
>> CPU A CPU B
>> cpuset_update_sd_hk_unlock()
>> housekeeping_publish()
>> rcu_assign_pointer()
>> mutex_lock(&cpuset_mutex) <- wait
>> mutex_unlock(&cpuset_mutex)
>> cpus_read_unlock()
>> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
>> <- new cpumask synchronize_rcu()
>> kfree(old)
>>
>> The rest of housekeeping_update(), including the workqueue flushes,
>> still runs without those locks.
>>
>> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
>> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
> Ok that should work but, IIRC this whole locking puzzle is there because
> cpuset_handle_hotplug() can change isolated partitions. Why is it the case
> since cpuset.cpus shouldn't care about offline CPUs?
>
> I remember Waiman said it could be fixed in the long run. I don't remember
> the details though.
cpuset_handle_hotplug() has to remove the newly offlined CPU or to add
back the newly online CPUs to the effective_cpus of all the cpusets that
include the affected CPUs whether it is in an isolated or root partition
or not. In the worst case that the last online CPU in an isolated
partition is offline, we have to disable it. That is the main reason why
hotplug can affect isolated partitions. I don't remember saying it is
something that can be fixed long term. Perhaps, it is not something
related but not exactly this.
Cheers,
Longman
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 8:39 ` [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex Ridong
` (2 preceding siblings ...)
2026-11-18 14:20 ` Frederic Weisbecker
@ 2026-11-27 2:15 ` Ridong Chen
2026-11-27 13:14 ` Frederic Weisbecker
2026-11-27 21:07 ` Tejun Heo
2026-11-27 13:13 ` Frederic Weisbecker
4 siblings, 2 replies; 14+ messages in thread
From: Ridong Chen @ 2026-11-27 2:15 UTC (permalink / raw)
To: longman, frederic, tj, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny
Cc: linux-kernel, cgroups, guopeng.zhang, mathieu.desnoyers,
Ridong Chen
On 11/17/2026 4:39 PM, Ridong wrote:
> From: Ridong Chen<chenridong@xiaomi.com>
>
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") calls housekeeping_update() after dropping
> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> switched and freed outside of those locks. But readers holding either
> lock may still access it without rcu_read_lock() as allowed by
> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> for them:
>
> CPU A CPU B
> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> mutex_lock(&cpuset_mutex)
> p = housekeeping_cpumask(DOMAIN)
> housekeeping_update()
> rcu_assign_pointer()
> synchronize_rcu()
> kfree(old)
> access p <- UAF
>
> Fix it by moving the pointer switch into housekeeping_publish(), which
> is called before dropping the locks. Then CPU A either finishes before
> CPU B switches the pointer, or only sees the new cpumask:
>
> CPU A CPU B
> cpuset_update_sd_hk_unlock()
> housekeeping_publish()
> rcu_assign_pointer()
> mutex_lock(&cpuset_mutex) <- wait
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> <- new cpumask synchronize_rcu()
> kfree(old)
>
> The rest of housekeeping_update(), including the workqueue flushes,
> still runs without those locks.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Ridong Chen<chenridong@xiaomi.com>
Hi Frederic, Tejun,
There are two fixes for the HK_TYPE_DOMAIN UAF after commit
a84097e625f2, and neither is in linux-next yet:
[1] Waiman's v2, which takes cpus_read_lock and cpuset_mutex once
before kfree(old), so readers holding either lock are done
before the old cpumask is freed.
[2] This patch, which switches the pointer before dropping the
locks, so readers holding either lock only see the new cpumask.
Waiman said either one works. Frederic, since this is your
housekeeping code, which one would you prefer? Tejun, could you
apply the chosen one to cgroup/for-7.5?
If it is this one, I will send a v2 rebased onto for-7.5, as it now
conflicts with housekeeping_set_cpu() from commit 884e88175b95.
[1] https://lore.kernel.org/all/20261117051853.2429410-1-longman@redhat.com/
--
Best regards
Ridong
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-27 2:15 ` Ridong Chen
@ 2026-11-27 13:14 ` Frederic Weisbecker
2026-11-27 21:07 ` Tejun Heo
1 sibling, 0 replies; 14+ messages in thread
From: Frederic Weisbecker @ 2026-11-27 13:14 UTC (permalink / raw)
To: Ridong Chen
Cc: longman, tj, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny, linux-kernel, cgroups,
guopeng.zhang, mathieu.desnoyers, Ridong Chen
Le Fri, Nov 27, 2026 at 10:15:07AM +0800, Ridong Chen a écrit :
>
>
> On 11/17/2026 4:39 PM, Ridong wrote:
> > From: Ridong Chen<chenridong@xiaomi.com>
> >
> > Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> > holding cpus_read_lock") calls housekeeping_update() after dropping
> > cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> > switched and freed outside of those locks. But readers holding either
> > lock may still access it without rcu_read_lock() as allowed by
> > housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> > for them:
> >
> > CPU A CPU B
> > rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> > mutex_unlock(&cpuset_mutex)
> > cpus_read_unlock()
> > mutex_lock(&cpuset_mutex)
> > p = housekeeping_cpumask(DOMAIN)
> > housekeeping_update()
> > rcu_assign_pointer()
> > synchronize_rcu()
> > kfree(old)
> > access p <- UAF
> >
> > Fix it by moving the pointer switch into housekeeping_publish(), which
> > is called before dropping the locks. Then CPU A either finishes before
> > CPU B switches the pointer, or only sees the new cpumask:
> >
> > CPU A CPU B
> > cpuset_update_sd_hk_unlock()
> > housekeeping_publish()
> > rcu_assign_pointer()
> > mutex_lock(&cpuset_mutex) <- wait
> > mutex_unlock(&cpuset_mutex)
> > cpus_read_unlock()
> > p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> > <- new cpumask synchronize_rcu()
> > kfree(old)
> >
> > The rest of housekeeping_update(), including the workqueue flushes,
> > still runs without those locks.
> >
> > Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> > Signed-off-by: Ridong Chen<chenridong@xiaomi.com>
>
>
> Hi Frederic, Tejun,
>
> There are two fixes for the HK_TYPE_DOMAIN UAF after commit
> a84097e625f2, and neither is in linux-next yet:
>
> [1] Waiman's v2, which takes cpus_read_lock and cpuset_mutex once
> before kfree(old), so readers holding either lock are done
> before the old cpumask is freed.
>
> [2] This patch, which switches the pointer before dropping the
> locks, so readers holding either lock only see the new cpumask.
Yes the second one is clearer.
Thanks.
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-27 2:15 ` Ridong Chen
2026-11-27 13:14 ` Frederic Weisbecker
@ 2026-11-27 21:07 ` Tejun Heo
1 sibling, 0 replies; 14+ messages in thread
From: Tejun Heo @ 2026-11-27 21:07 UTC (permalink / raw)
To: Ridong Chen
Cc: longman, frederic, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny, linux-kernel, cgroups,
guopeng.zhang, mathieu.desnoyers, Ridong Chen
Hello, Ridong.
On Fri, Nov 27, 2026 at 10:15:07AM +0800, Ridong Chen wrote:
> If it is this one, I will send a v2 rebased onto for-7.5, as it now
> conflicts with housekeeping_set_cpu() from commit 884e88175b95.
Can you please send v2 based on cgroup/for-7.4-fixes instead?
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
2026-11-17 8:39 ` [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex Ridong
` (3 preceding siblings ...)
2026-11-27 2:15 ` Ridong Chen
@ 2026-11-27 13:13 ` Frederic Weisbecker
4 siblings, 0 replies; 14+ messages in thread
From: Frederic Weisbecker @ 2026-11-27 13:13 UTC (permalink / raw)
To: Ridong
Cc: longman, tj, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, hannes, mkoutny, linux-kernel, cgroups,
guopeng.zhang, mathieu.desnoyers, Ridong Chen
Le Tue, Nov 17, 2026 at 04:39:15PM +0800, Ridong a écrit :
> From: Ridong Chen <chenridong@xiaomi.com>
>
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without
> holding cpus_read_lock") calls housekeeping_update() after dropping
> cpus_read_lock and cpuset_mutex, so the HK_TYPE_DOMAIN cpumask is now
> switched and freed outside of those locks. But readers holding either
> lock may still access it without rcu_read_lock() as allowed by
> housekeeping_dereference_check(), and synchronize_rcu() doesn't wait
> for them:
>
> CPU A CPU B
> rebuild_sched_domains() cpuset_update_sd_hk_unlock()
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> mutex_lock(&cpuset_mutex)
> p = housekeeping_cpumask(DOMAIN)
> housekeeping_update()
> rcu_assign_pointer()
> synchronize_rcu()
> kfree(old)
> access p <- UAF
>
> Fix it by moving the pointer switch into housekeeping_publish(), which
> is called before dropping the locks. Then CPU A either finishes before
> CPU B switches the pointer, or only sees the new cpumask:
>
> CPU A CPU B
> cpuset_update_sd_hk_unlock()
> housekeeping_publish()
> rcu_assign_pointer()
> mutex_lock(&cpuset_mutex) <- wait
> mutex_unlock(&cpuset_mutex)
> cpus_read_unlock()
> p = housekeeping_cpumask(DOMAIN) housekeeping_update()
> <- new cpumask synchronize_rcu()
> kfree(old)
>
> The rest of housekeeping_update(), including the workqueue flushes,
> still runs without those locks.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 14+ messages in thread