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: <3479054.QJadu78ljV@camazotz>
Date: Wed, 17 Apr 2024 15:03:05 -0500
From: Elizabeth Figura <zfigura@...eweavers.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Arnd Bergmann <arnd@...db.de>,
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
 Jonathan Corbet <corbet@....net>, Shuah Khan <shuah@...nel.org>,
 linux-kernel@...r.kernel.org, linux-api@...r.kernel.org,
 wine-devel@...ehq.org,
 André Almeida <andrealmeid@...lia.com>,
 Wolfram Sang <wsa@...nel.org>, Arkadiusz Hiler <ahiler@...eweavers.com>,
 Andy Lutomirski <luto@...nel.org>, linux-doc@...r.kernel.org,
 linux-kselftest@...r.kernel.org, Randy Dunlap <rdunlap@...radead.org>,
 Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
 Waiman Long <longman@...hat.com>, Boqun Feng <boqun.feng@...il.com>
Subject: Re: [PATCH v4 02/27] ntsync: Introduce NTSYNC_IOC_WAIT_ALL.

On Wednesday, 17 April 2024 06:37:03 CDT Peter Zijlstra wrote:
> On Mon, Apr 15, 2024 at 08:08:12PM -0500, Elizabeth Figura wrote:
> > +	if (atomic_read(&sem->all_hint) > 0) {
> > +		spin_lock(&dev->wait_all_lock);
> > +		spin_lock_nest_lock(&sem->lock, &dev->wait_all_lock);
> >  
> > +		prev_count = sem->u.sem.count;
> > +		ret = post_sem_state(sem, args);
> > +		if (!ret) {
> > +			try_wake_all_obj(dev, sem);
> > +			try_wake_any_sem(sem);
> > +		}
> >  
> > +		spin_unlock(&sem->lock);
> > +		spin_unlock(&dev->wait_all_lock);
> > +	} else {
> > +		spin_lock(&sem->lock);
> > +
> > +		prev_count = sem->u.sem.count;
> > +		ret = post_sem_state(sem, args);
> > +		if (!ret)
> > +			try_wake_any_sem(sem);
> > +
> > +		spin_unlock(&sem->lock);
> > +	}
> >  
> >  	if (!ret && put_user(prev_count, user_args))
> >  		ret = -EFAULT;
> 
> vs.
> 
> > +	/* queue ourselves */
> > +
> > +	spin_lock(&dev->wait_all_lock);
> > +
> > +	for (i = 0; i < args.count; i++) {
> > +		struct ntsync_q_entry *entry = &q->entries[i];
> > +		struct ntsync_obj *obj = entry->obj;
> > +
> > +		atomic_inc(&obj->all_hint);
> > +
> > +		/*
> > +		 * obj->all_waiters is protected by dev->wait_all_lock rather
> > +		 * than obj->lock, so there is no need to acquire obj->lock
> > +		 * here.
> > +		 */
> > +		list_add_tail(&entry->node, &obj->all_waiters);
> > +	}
> 
> This looks racy, consider:
> 
> 	atomic_read(all_hints) /* 0 */
> 
> 				spin_lock(wait_all_lock)
> 				atomic_inc(all_hint)	/* 1 */
> 				list_add_tail()
> 
> 	spin_lock(sem->lock)
> 	/* try_wake_all_obj() missing */
> 
> 
> 
> 
> I've not yet thought about if this is harmful or not, but if not, it
> definitely needs a comment.
> 
> Anyway, I need a break, maybe more this evening.

Ach. I wrote this with the idea that the race isn't meaningful, but
looking at it again you're right—there is a harmful race here.

I think it should be fixable by moving the atomic_read inside the lock,
though.



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ