Re: [PATCH] sched/isolation: Publish new HK_TYPE_DOMAIN cpumask under cpuset_mutex
From: Frederic Weisbecker
Date: Fri Nov 27 2026 - 08:14:59 EST
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@xxxxxxxxxx>
> >
> > 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@xxxxxxxxxx>
>
>
> 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