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: <20200123164108.GQ2935@paulmck-ThinkPad-P72>
Date:   Thu, 23 Jan 2020 08:41:08 -0800
From:   "Paul E. McKenney" <paulmck@...nel.org>
To:     madhuparnabhowmik10@...il.com
Cc:     mingo@...hat.com, peterz@...radead.org, juri.lelli@...hat.com,
        vincent.guittot@...aro.org, ebiederm@...ssion.com,
        christian.brauner@...ntu.com, oleg@...hat.com,
        joel@...lfernandes.org, linux-kernel@...r.kernel.org,
        linux-kernel-mentees@...ts.linuxfoundation.org,
        frextrite@...il.com, rcu@...r.kernel.org
Subject: Re: [PATCH] sched.h: Annotate sighand_struct with __rcu

On Thu, Jan 23, 2020 at 08:23:05PM +0530, madhuparnabhowmik10@...il.com wrote:
> From: Madhuparna Bhowmik <madhuparnabhowmik10@...il.com>
> 
> This patch fixes the following sparse errors by annotating the
> sighand_struct with __rcu
> 
> kernel/fork.c:1511:9: error: incompatible types in comparison expression
> kernel/exit.c:100:19: error: incompatible types in comparison expression
> kernel/signal.c:1370:27: error: incompatible types in comparison expression
> 
> This fix introduces the following sparse error in signal.c due to
> checking the sighand pointer without rcu primitives:
> 
> kernel/signal.c:1386:21: error: incompatible types in comparison expression
> 
> This new sparse error is also addressed in this patch.
> 
> Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@...il.com>
> ---
>  include/linux/sched.h | 2 +-
>  kernel/signal.c       | 3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index b511e178a89f..7a351360ad54 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -918,7 +918,7 @@ struct task_struct {
>  
>  	/* Signal handlers: */
>  	struct signal_struct		*signal;
> -	struct sighand_struct		*sighand;
> +	struct sighand_struct __rcu		*sighand;
>  	sigset_t			blocked;
>  	sigset_t			real_blocked;
>  	/* Restored if set_restore_sigmask() was used: */
> diff --git a/kernel/signal.c b/kernel/signal.c
> index bcd46f547db3..1272def37462 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1383,7 +1383,8 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
>  		 * must see ->sighand == NULL.
>  		 */
>  		spin_lock_irqsave(&sighand->siglock, *flags);
> -		if (likely(sighand == tsk->sighand))
> +		if (likely(sighand == rcu_dereference_protected(tsk->sighand,
> +						lockdep_is_held(&sighand->siglock))))

Given that the return value is never dereferenced, you can use
rcu_access_pointer(), which may be used outside of an RCU read-side
critical section, and thus does not need the lockdep_is_held().  So this
change would save a line of code and would be a bit easier on the eyes.

							Thanx, Paul

>  			break;
>  		spin_unlock_irqrestore(&sighand->siglock, *flags);
>  	}
> -- 
> 2.17.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ