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: <20160203072847.GA32026@gmail.com>
Date:	Wed, 3 Feb 2016 08:28:48 +0100
From:	Ingo Molnar <mingo@...nel.org>
To:	Byungchul Park <byungchul.park@....com>
Cc:	willy@...ux.intel.com, akpm@...ux-foundation.org,
	linux-kernel@...r.kernel.org, akinobu.mita@...il.com, jack@...e.cz,
	sergey.senozhatsky.work@...il.com, peter@...leysoftware.com,
	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH v2] lock/semaphore: Avoid an unnecessary deadlock within
 up()


* Byungchul Park <byungchul.park@....com> wrote:

>  void up(struct semaphore *sem)
>  {
>  	unsigned long flags;
> +	struct task_struct *p = NULL;
>  
>  	raw_spin_lock_irqsave(&sem->lock, flags);
>  	if (likely(list_empty(&sem->wait_list)))
>  		sem->count++;
>  	else
> -		__up(sem);
> +		p = __up(sem);
>  	raw_spin_unlock_irqrestore(&sem->lock, flags);
> +
> +	/*
> +	 * wake_up_process() needs not to be protected by a spinlock.
> +	 * Thus move it from the protected region to here. What is
> +	 * worse, this unnecessary protection can cause a deadlock by
> +	 * acquiring the same sem->lock within wake_up_process().
> +	 */
> +	if (unlikely(p))
> +		wake_up_process(p);

So I'm not sure this is completely race free, for cases where a semaphore is 
attached to a task and is managed/destroyed on task exit.

Since we don't have a guaranteed reference to 'p' here, the task might wake up 
(via a signal) and exit (and its task struct might be freed and the semaphore 
might be freed), after we unlocked the semaphore but before we wake the task up.

So why not move printk away from semaphores? Semaphores are classical constructs 
that have legacies and are somewhat non-obvious to use, compared to modern, 
simpler locking primitives. I'd not touch their implementation, unless we are 
absolutely sure this is a safe optimization.

Thanks,

	Ingo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ