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]
Date:   Wed, 16 Mar 2022 09:23:19 +0100
From:   Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To:     Oleg Nesterov <oleg@...hat.com>
Cc:     linux-kernel@...r.kernel.org, Ben Segall <bsegall@...gle.com>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        Dietmar Eggemann <dietmar.eggemann@....com>,
        Ingo Molnar <mingo@...hat.com>,
        Juri Lelli <juri.lelli@...hat.com>,
        Mel Gorman <mgorman@...e.de>,
        Peter Zijlstra <peterz@...radead.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Vincent Guittot <vincent.guittot@...aro.org>
Subject: Re: [PATCH] ptrace: fix ptrace vs tasklist_lock race on PREEMPT_RT.

On 2022-03-15 15:29:46 [+0100], Oleg Nesterov wrote:
> > > > --- a/kernel/sched/core.c
> > > > +++ b/kernel/sched/core.c
> > > > @@ -3239,7 +3239,8 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state
> > > >  		 * is actually now running somewhere else!
> > > >  		 */
> > > >  		while (task_running(rq, p)) {
> > > > -			if (match_state && unlikely(READ_ONCE(p->__state) != match_state))
> > > > +			if (match_state &&
> > > > +			    unlikely(!task_state_match_eq(p, match_state)))
> > > >  				return 0;
> > >
> > > So wait_task_inactive() can return 0 but the task can run after that, right?
> > > This is not what we want...
> >
> > Without checking both states you may never observe the requested state
> > because it is set to TASK_RTLOCK_WAIT while waiting for a lock. Other
> > than that, it may run briefly because it tries to acquire a lock or just
> > acquired and this shouldn't be different from a task spinning on a lock.
> 
> I don't understand. wait_task_inactive() is used to ensure that this task
> doesn't and can't run again, until debugger resumes these tracee.
> 
> Now. Unless I missed something, the tracee can leave CPU with saved_state
> = TRACED (so task_state_match_eq() returns T) and wait_task_inactive() will
> return. Then later the tracee will park in schedule again, yes.
> 
> But, for example, what if debugger clears TIF_BLOCKSTEP in between, while
> the tracee is running? Can't this race with __switch_to_xtra() ?

If you describe like that, then it appears better to only look at
->state. Otherwise, yes, you would see the expected state in
->saved_state and the task might still be on the CPU. Even if it is not
actually running/ on the runqueue, it could be the case if the lock has
been made available shortly after.

> Oleg.

Sebastian

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ