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:	Fri, 19 Aug 2011 23:08:59 +0200
From:	"Rafael J. Wysocki" <rjw@...k.pl>
To:	Tejun Heo <tj@...nel.org>
Cc:	menage@...gle.com, linux-kernel@...r.kernel.org, arnd@...db.de,
	oleg@...hat.com
Subject: Re: [PATCH 01/16] freezer: fix current->state restoration race in refrigerator()

On Friday, August 19, 2011, Tejun Heo wrote:
> refrigerator() saves current->state before entering frozen state and
> restores it before returning using __set_current_state(); however,
> this is racy, for example, please consider the following sequence.
> 
> 	set_current_state(TASK_INTERRUPTIBLE);
> 	try_to_sleep();

Did you mean try_to_freeze() here?

> 	if (kthread_should_stop())
> 		break;
> 	schedule();
> 
> If kthread_stop() races with ->state restoration, the restoration can
> restore ->state to TASK_INTERRUPTIBLE after kthread_stop() sets it to
> TASK_RUNNING but kthread_should_stop() may still see zero
> ->should_stop because there's no memory barrier between restoring
> TASK_INTERRUPTIBLE and kthread_should_stop() test.
> 
> This isn't restricted to kthread_should_stop().  current->state is
> often used in memory barrier based synchronization and silently
> restoring it w/o mb breaks them.
> 
> Use set_current_state() instead.
> 
> Signed-off-by: Tejun Heo <tj@...nel.org>
> ---
>  kernel/freezer.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/freezer.c b/kernel/freezer.c
> index 7b01de9..575f863 100644
> --- a/kernel/freezer.c
> +++ b/kernel/freezer.c
> @@ -58,7 +58,13 @@ void refrigerator(void)
>  	current->flags &= ~PF_FREEZING;
>  
>  	pr_debug("%s left refrigerator\n", current->comm);
> -	__set_current_state(save);
> +
> +	/*
> +	 * Restore saved task state before returning.  The mb'd version
> +	 * needs to be used; otherwise, it might silently break
> +	 * synchronization which depends on ordered task state change.
> +	 */
> +	set_current_state(save);

I think the change is correct.

>  }
>  EXPORT_SYMBOL(refrigerator);

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ