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-next>] [day] [month] [year] [list]
Message-ID: <20250709093829.3213647-1-quzicheng@huawei.com>
Date: Wed, 9 Jul 2025 09:38:29 +0000
From: Zicheng Qu <quzicheng@...wei.com>
To: <mingo@...hat.com>, <peterz@...radead.org>, <juri.lelli@...hat.com>,
	<vincent.guittot@...aro.org>, <dietmar.eggemann@....com>,
	<rostedt@...dmis.org>, <bsegall@...gle.com>, <mgorman@...e.de>,
	<vschneid@...hat.com>, <linux-kernel@...r.kernel.org>
CC: <tanghui20@...wei.com>, <zhangqiao22@...wei.com>,
	<judy.chenhui@...wei.com>, <quzicheng@...wei.com>
Subject: [PATCH] sched/fair: Fix overflow in vruntime_eligible() causing NULL return

In the vruntime_eligible() function, the original comparison:
	return avg >= (s64)(vruntime - cfs_rq->min_vruntime) * load;
could produce incorrect results due to integer overflow in the 'avg' or
s64 part.

This overflow causes the comparison to return false even when the
mathematical result should be true, leading all tasks to be falsely
deemed ineligible. Consequently, pick_eevdf() returns NULL, triggering a
kernel crash.

The best approach should be to dig deep into why overflow occurs, which
attributes lead to the overflow, whether it is normal, and how to avoid
it. Not pretty sure if this part of the modification will introduce new
issues, but it may be incorrect to simply spot a potentially
overflowing integer type and directly use the >= sign for comparison.
Therefore, drawing on the enqueue method in the rb tree, to avoid the
impact of overflow, the method of first performing subtraction and then
comparing with 0 is also adopted.

The following are the relevant attributes that cause the return of NULL:
crash> struct cfs_rq.avg_vruntime,avg_load,min_vruntime
ffff9ea77ecb4280
  avg_vruntime = -4392414779907141680,
  avg_load = 28644,
  min_vruntime = 239776551994501,

sched_entity: curr
crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag
0xffff9ea74510d800
  deadline = 86432035728535,
  min_vruntime = 86431486021988,
  vruntime = 86431531134184,
  load = {
    weight = 6066,
    inv_weight = 0
  },
  vlag = 86431823023195,

the sched_entity mapping to the root node in the cfs_rq
crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
sched_entity.run_node 0xffff9ea849fbc350
  deadline = 18446615868453340281,
  min_vruntime = 18446615868452621390,
  vruntime = 18446615868453018539,
  load = {
    weight = 9777152,
    inv_weight = 449829
  },
  vlag = -5599,

the sched_entity mapping to the leftmost node in the csf_rq, also the
left child of root node.
crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
sched_entity.run_node 0xffff9ea78d0280d0
  deadline = 18446615868452943132,
  min_vruntime = 18446615868452621390,
  vruntime = 18446615868452621390,
  load = {
    weight = 9777152,
    inv_weight = 449829
  },
  vlag = 444143,

the sched_entity mapping to the rightmost node in the csf_rq, also the
right child of root node.
crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
sched_entity.run_node 0xffff9ea783144350
  deadline = 515705106937888,
  min_vruntime = 515705106616146,
  vruntime = 515705106616146,
  load = {
    weight = 9777152,
    inv_weight = 449829
  },
  vlag = -260493,

Fixes: 147f3efaa241 ("sched/fair: Implement an EEVDF-like scheduling policy")
Signed-off-by: Zicheng Qu <quzicheng@...wei.com>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7a14da5396fb..bfa4090cef93 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -734,7 +734,7 @@ static int vruntime_eligible(struct cfs_rq *cfs_rq, u64 vruntime)
 		load += weight;
 	}
 
-	return avg >= (s64)(vruntime - cfs_rq->min_vruntime) * load;
+	return avg - (s64)(vruntime - cfs_rq->min_vruntime) * load >= 0;
 }
 
 int entity_eligible(struct cfs_rq *cfs_rq, struct sched_entity *se)
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ