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: <20231031121821.GE35651@noisy.programming.kicks-ass.net>
Date:   Tue, 31 Oct 2023 13:18:21 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Frederic Weisbecker <frederic@...nel.org>
Cc:     Waiman Long <longman@...hat.com>, Ingo Molnar <mingo@...hat.com>,
        Juri Lelli <juri.lelli@...hat.com>,
        Vincent Guittot <vincent.guittot@...aro.org>,
        Dietmar Eggemann <dietmar.eggemann@....com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        Valentin Schneider <vschneid@...hat.com>,
        linux-kernel@...r.kernel.org, Phil Auld <pauld@...hat.com>,
        kernel test robot <oliver.sang@...el.com>,
        aubrey.li@...ux.intel.com, yu.c.chen@...el.com, paulmck@...nel.org,
        quic_neeraju@...cinc.com, joel@...lfernandes.org,
        josh@...htriplett.org, boqun.feng@...il.com,
        mathieu.desnoyers@...icios.com, jiangshanlai@...il.com,
        qiang.zhang1211@...il.com
Subject: Re: [PATCH] sched: Don't call any kfree*() API in
 do_set_cpus_allowed()

On Tue, Oct 31, 2023 at 11:52:38AM +0100, Frederic Weisbecker wrote:
> On Tue, Oct 31, 2023 at 09:53:08AM +0100, Peter Zijlstra wrote:
> > On Mon, Oct 30, 2023 at 08:14:18PM -0400, Waiman Long wrote:
> > > Commit 851a723e45d1 ("sched: Always clear user_cpus_ptr in
> > > do_set_cpus_allowed()") added a kfree() call to free any user
> > > provided affinity mask, if present. It was changed later to use
> > > kfree_rcu() in commit 9a5418bc48ba ("sched/core: Use kfree_rcu()
> > > in do_set_cpus_allowed()") to avoid a circular locking dependency
> > > problem.
> > > 
> > > It turns out that even kfree_rcu() isn't safe for avoiding
> > > circular locking problem. As reported by kernel test robot,
> > > the following circular locking dependency still exists:
> > > 
> > >   &rdp->nocb_lock --> rcu_node_0 --> &rq->__lock
> > > 
> > > So no kfree*() API can be used in do_set_cpus_allowed(). To prevent
> > > memory leakage, the unused user provided affinity mask is now saved in a
> > > lockless list to be reused later by subsequent sched_setaffinity() calls.
> > > 
> > > Without kfree_rcu(), the internal cpumask_rcuhead union can be removed
> > > too as a lockless list entry only holds a single pointer.
> > > 
> > > Fixes: 851a723e45d1 ("sched: Always clear user_cpus_ptr in do_set_cpus_allowed()")
> > 
> > Bah, or we fix RCU...  Paul, how insane is the below?
> 
> Makes sense. We can't remove &rdp->nocb_lock --> rcu_node_0 but we can (and
> should) indeed remove rcu_node_0 --> &rq->__lock
> 
> Just a detail below:
> 
> > @@ -2284,10 +2289,13 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp))
> >  		}
> >  		for_each_leaf_node_cpu_mask(rnp, cpu, rnp->qsmask) {
> >  			rdp = per_cpu_ptr(&rcu_data, cpu);
> > -			if (f(rdp)) {
> > +			ret = f(rdp);
> > +			if (ret > 0) {
> >  				mask |= rdp->grpmask;
> >  				rcu_disable_urgency_upon_qs(rdp);
> >  			}
> > +			if (ret < 0)
> > +				rsmask |= 1UL << (cpu - rnp->grplo);
> 
> I guess this can be simplified with rsmask |= rdp->grpmask;

Ah, I wasn't sure that was actually the same. I looked for a minute and
gave up :-)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ