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: <20180731123651.GW2494@hirez.programming.kicks-ass.net>
Date:   Tue, 31 Jul 2018 14:36:51 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     jiada_wang@...tor.com
Cc:     mingo@...hat.com, linux-kernel@...r.kernel.org,
        george_davis@...tor.com, erosca@...adit-jv.com
Subject: Re: [PATCH v2 1/1] sched/debug: fix potential deadlock when write to
 sched_features

On Tue, Jul 31, 2018 at 09:12:22PM +0900, jiada_wang@...tor.com wrote:
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 60caf1fb94e0..7b2997d4a349 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -87,21 +87,21 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
>  
>  #undef SCHED_FEAT
>  
> -static void sched_feat_disable(int i)
> +static void sched_feat_disable_cpuslocked(int i)
>  {
> -	static_key_disable(&sched_feat_keys[i]);
> +	static_key_disable_cpuslocked(&sched_feat_keys[i]);
>  }
>  
> -static void sched_feat_enable(int i)
> +static void sched_feat_enable_cpuslocked(int i)
>  {
> -	static_key_enable(&sched_feat_keys[i]);
> +	static_key_enable_cpuslocked(&sched_feat_keys[i]);
>  }
>  #else
> -static void sched_feat_disable(int i) { };
> -static void sched_feat_enable(int i) { };
> +static void sched_feat_disable_cpuslocked(int i) { };
> +static void sched_feat_enable_cpuslocked(int i) { };
>  #endif /* HAVE_JUMP_LABEL */
>  
> -static int sched_feat_set(char *cmp)
> +static int sched_feat_set_cpuslocked(char *cmp)
>  {
>  	int i;
>  	int neg = 0;
> @@ -117,10 +117,10 @@ static int sched_feat_set(char *cmp)
>  
>  	if (neg) {
>  		sysctl_sched_features &= ~(1UL << i);
> -		sched_feat_disable(i);
> +		sched_feat_disable_cpuslocked(i);
>  	} else {
>  		sysctl_sched_features |= (1UL << i);
> -		sched_feat_enable(i);
> +		sched_feat_enable_cpuslocked(i);
>  	}
>  
>  	return 0;
> @@ -146,9 +146,11 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
>  
>  	/* Ensure the static_key remains in a consistent state */
>  	inode = file_inode(filp);
> +	cpus_read_lock();
>  	inode_lock(inode);
> -	ret = sched_feat_set(cmp);
> +	ret = sched_feat_set_cpuslocked(cmp);
>  	inode_unlock(inode);
> +	cpus_read_unlock();
>  	if (ret < 0)
>  		return ret;
>  

I've made that..

---
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -89,12 +89,12 @@ struct static_key sched_feat_keys[__SCHE
 
 static void sched_feat_disable(int i)
 {
-	static_key_disable(&sched_feat_keys[i]);
+	static_key_disable_cpuslocked(&sched_feat_keys[i]);
 }
 
 static void sched_feat_enable(int i)
 {
-	static_key_enable(&sched_feat_keys[i]);
+	static_key_enable_cpuslocked(&sched_feat_keys[i]);
 }
 #else
 static void sched_feat_disable(int i) { };
@@ -146,9 +146,11 @@ sched_feat_write(struct file *filp, cons
 
 	/* Ensure the static_key remains in a consistent state */
 	inode = file_inode(filp);
+	cpus_read_lock();
 	inode_lock(inode);
 	ret = sched_feat_set(cmp);
 	inode_unlock(inode);
+	cpus_read_unlock();
 	if (ret < 0)
 		return ret;
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ