lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1ea13066-aa98-ead2-f50f-f62d030ce3c5@huawei.com>
Date:   Thu, 17 Mar 2022 10:41:57 +0800
From:   Zhang Qiao <zhangqiao22@...wei.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Michal Koutný <mkoutny@...e.com>
CC:     <linux-kernel@...r.kernel.org>, <stable@...r.kernel.org>,
        Zhao Gongyi <zhaogongyi@...wei.com>,
        Waiman Long <longman@...hat.com>, Tejun Heo <tj@...nel.org>,
        Juri Lelli <juri.lelli@...hat.com>
Subject: Re: [PATCH 4.19 01/34] cgroup/cpuset: Fix a race between
 cpuset_attach() and cpu hotplug



在 2022/3/16 22:27, Greg Kroah-Hartman 写道:
> On Mon, Mar 14, 2022 at 12:19:41PM +0100, Michal Koutný wrote:
>> Hello.
>>
>> In my opinion there are two approaches:
>> a) drop this backport (given other races present),
> 
> I have no problem with that, want to send a revert patch?
> 
>> b) swap the locks compatible with v4.19 as this patch proposes.
>>
>> On Mon, Mar 14, 2022 at 05:11:50PM +0800, Zhang Qiao <zhangqiao22@...wei.com> wrote:
>>> +       /*
>>> +        * It should hold cpus lock because a cpu offline event can
>>> +        * cause set_cpus_allowed_ptr() failed.
>>> +        */
>>> +       cpus_read_lock();
>>
>> Maybe just a nit, the old kernels before commit c5c63b9a6a2e ("cgroup:
>> Replace deprecated CPU-hotplug functions.") v5.15-rc1~159^2~5
>> would be more consistent with get_online_cpus() here (but they're
>> equivalent functionally so the locking order is correct).
> 
> A fixed up patch would also be appreciated :)
> 

Fixed up patch as follows, replace cpus_read_lock() with get_online_cpus().

thanks.

--------


[PATCH] cpuset: Fix unsafe lock order between cpuset lock and cpuslock

The backport commit 4eec5fe1c680a ("cgroup/cpuset: Fix a race
between cpuset_attach() and cpu hotplug") looks suspicious since
it comes before commit d74b27d63a8b ("cgroup/cpuset: Change
cpuset_rwsem and hotplug lock order") v5.4-rc1~176^2~30 when
the locking order was: cpuset lock, cpus lock.

Fix it with the correct locking order and reduce the cpus locking
range because only set_cpus_allowed_ptr() needs the protection of
cpus lock.

Fixes: 4eec5fe1c680a ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
Reported-by: Michal Koutný <mkoutny@...e.com>
Signed-off-by: Zhang Qiao <zhangqiao22@...wei.com>
---
 kernel/cgroup/cpuset.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index d43d25acc..4e1c4232e 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1528,9 +1528,13 @@ static void cpuset_attach(struct cgroup_taskset *tset)
        cgroup_taskset_first(tset, &css);
        cs = css_cs(css);

-       cpus_read_lock();
        mutex_lock(&cpuset_mutex);

+       /*
+        * It should hold cpus lock because a cpu offline event can
+        * cause set_cpus_allowed_ptr() failed.
+        */
+       get_online_cpus();
        /* prepare for attach */
        if (cs == &top_cpuset)
                cpumask_copy(cpus_attach, cpu_possible_mask);
@@ -1549,6 +1553,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
                cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
                cpuset_update_task_spread_flag(cs, task);
        }
+       put_online_cpus();

        /*
         * Change mm for all threadgroup leaders. This is expensive and may
@@ -1584,7 +1589,6 @@ static void cpuset_attach(struct cgroup_taskset *tset)
                wake_up(&cpuset_attach_wq);

        mutex_unlock(&cpuset_mutex);
-       cpus_read_unlock();
 }

 /* The various types of files and directories in a cpuset file system */
--
2.18.0


> thanks,
> 
> greg k-h
> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ