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: <tip-c5ae366e12b2bd56fc7d7e9d484836bec9ddc110@git.kernel.org>
Date:   Tue, 20 Jun 2017 06:26:51 -0700
From:   tip-bot for Daniel Axtens <tipbot@...or.com>
To:     linux-tip-commits@...r.kernel.org
Cc:     peterz@...radead.org, khlebnikov@...dex-team.ru,
        bsegall@...gle.com, mingo@...nel.org, efault@....de, hpa@...or.com,
        linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
        dja@...ens.net, tglx@...utronix.de
Subject: [tip:sched/core] sched/fair: WARN() and refuse to set buddy when
 !se->on_rq

Commit-ID:  c5ae366e12b2bd56fc7d7e9d484836bec9ddc110
Gitweb:     http://git.kernel.org/tip/c5ae366e12b2bd56fc7d7e9d484836bec9ddc110
Author:     Daniel Axtens <dja@...ens.net>
AuthorDate: Thu, 11 May 2017 06:11:39 +1000
Committer:  Ingo Molnar <mingo@...nel.org>
CommitDate: Tue, 20 Jun 2017 12:26:52 +0200

sched/fair: WARN() and refuse to set buddy when !se->on_rq

If we set a next or last buddy for a se that is not on_rq, we will
end up taking a NULL pointer dereference in wakeup_preempt_entity
via pick_next_task_fair.

Detect when we would be about to do that, throw a warning and
then refuse to actually set it.

This has been suggested at least twice:

  https://marc.info/?l=linux-kernel&m=146651668921468&w=2
  https://lkml.org/lkml/2016/6/16/663

I recently had to debug a problem with these (we hadn't backported
Konstantin's patches in this area) and this would have saved a lot
of time/pain.

Just do it.

Signed-off-by: Daniel Axtens <dja@...ens.net>
Cc: Ben Segall <bsegall@...gle.com>
Cc: Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Mike Galbraith <efault@....de>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Link: http://lkml.kernel.org/r/20170510201139.16236-1-dja@axtens.net
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
 kernel/sched/fair.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 396bca9..cb3a3da 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6164,8 +6164,11 @@ static void set_last_buddy(struct sched_entity *se)
 	if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
 		return;
 
-	for_each_sched_entity(se)
+	for_each_sched_entity(se) {
+		if (SCHED_WARN_ON(!se->on_rq))
+			return;
 		cfs_rq_of(se)->last = se;
+	}
 }
 
 static void set_next_buddy(struct sched_entity *se)
@@ -6173,8 +6176,11 @@ static void set_next_buddy(struct sched_entity *se)
 	if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
 		return;
 
-	for_each_sched_entity(se)
+	for_each_sched_entity(se) {
+		if (SCHED_WARN_ON(!se->on_rq))
+			return;
 		cfs_rq_of(se)->next = se;
+	}
 }
 
 static void set_skip_buddy(struct sched_entity *se)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ