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: <20240704134716.GU11386@noisy.programming.kicks-ass.net>
Date: Thu, 4 Jul 2024 15:47:16 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: xu.xin16@....com.cn
Cc: mingo@...hat.com, juri.lelli@...hat.com, vincent.guittot@...aro.org,
	dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
	mgorman@...e.de, he.peilin@....com.cn, yang.yang29@....com.cn,
	tu.qiang35@....com.cn, jiang.kun2@....com.cn,
	zhang.yunkai@....com.cn, liu.chun2@....com.cn, fan.yu9@....com.cn,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH linux-next v2] sched/core: Add WARN() to check overflow
 in migrate_disable()

On Wed, Jul 03, 2024 at 08:53:25PM +0800, xu.xin16@....com.cn wrote:

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 8cc4975d6b2b..327010af6ce9 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2259,6 +2259,7 @@ void migrate_disable(void)
>  	struct task_struct *p = current;
> 
>  	if (p->migration_disabled) {
> +		WARN(p->migration_disabled == USHRT_MAX, "migration_disabled has encountered an overflow.");
>  		p->migration_disabled++;
>  		return;
>  	}

How about we do something like this?

---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7a5ea8fc8abb..06a559532ed6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2237,6 +2237,12 @@ void migrate_disable(void)
 
 	if (p->migration_disabled) {
 		p->migration_disabled++;
+#ifdef CONFIG_DEBUG_PREEMPT
+		/*
+		 * Warn about overflow half-way through the range.
+		 */
+		WARN_ON_ONCE((s16)p->migration_disabled < 0);
+#endif
 		return;
 	}
 
@@ -2254,14 +2260,20 @@ void migrate_enable(void)
 		.flags     = SCA_MIGRATE_ENABLE,
 	};
 
+#ifdef CONFIG_DEBUG_PREEMPT
+	/*
+	 * Check both overflow from migrate_disable() and superfluous
+	 * migrate_enable().
+	 */
+	if (WARN_ON_ONCE((s16)p->migration_disabled <= 0))
+		return;
+#endif
+
 	if (p->migration_disabled > 1) {
 		p->migration_disabled--;
 		return;
 	}
 
-	if (WARN_ON_ONCE(!p->migration_disabled))
-		return;
-
 	/*
 	 * Ensure stop_task runs either before or after this, and that
 	 * __set_cpus_allowed_ptr(SCA_MIGRATE_ENABLE) doesn't schedule().

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ