mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Peng Wang" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Vincent Guittot <vincent.guittot@linaro.org>,
	Cruz Zhao <CruzZhao@linux.alibaba.com>,
	Peng Wang <peng_wang@linux.alibaba.com>,
	Ingo Molnar <mingo@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/urgent] sched/fair: Clear ->h_load_next when unregistering a cgroup
Date: Wed, 03 Dec 2025 16:52:15 -0000	[thread overview]
Message-ID: <176478073513.498.15089394378873483436.tip-bot2@tip-bot2> (raw)
In-Reply-To: =?utf-8?q?=3Cbf93d41ff9f2da19ef2c1cfb505362e0b48c39de=2E1761290?= =?utf-8?q?330=2Egit=2Epeng=5Fwang=40linux=2Ealibaba=2Ecom=3E?=

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     f85fd15b0da76f08e2d5bb4179c54993f7e07853
Gitweb:        https://git.kernel.org/tip/f85fd15b0da76f08e2d5bb4179c54993f7e07853
Author:        Peng Wang <peng_wang@linux.alibaba.com>
AuthorDate:    Fri, 24 Oct 2025 15:23:16 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 03 Dec 2025 17:44:01 +01:00

sched/fair: Clear ->h_load_next when unregistering a cgroup

An invalid pointer dereference bug was reported on ARM64 CPUs, and has
not yet been seen on x86. A partial oops looks like:

 Call trace:
  update_cfs_rq_h_load+0x80/0xb0
  wake_affine+0x158/0x168
  select_task_rq_fair+0x364/0x3a8
  try_to_wake_up+0x154/0x648
  wake_up_q+0x68/0xd0
  futex_wake_op+0x280/0x4c8
  do_futex+0x198/0x1c0
  __arm64_sys_futex+0x11c/0x198

See: https://lore.kernel.org/all/20251013071820.1531295-1-CruzZhao@linux.alibaba.com/

We found that the task_group corresponding to the problematic se
is not in the parent task_group’s children list, indicating that
h_load_next points to an invalid address. Consider the following
cgroup and task hierarchy:

         A
        / \
       /   \
      B     E
     / \    |
    /   \   t2
   C     D
   |     |
   t0    t1

Here follows a timing sequence that may be responsible for triggering
the problem:

  CPU X                   CPU Y                   CPU Z
  wakeup t0
  set list A->B->C
  traverse A->B->C
  t0 exits
  destroy C
                          wakeup t2
                          set list A->E           wakeup t1
                                                  set list A->B->D
                          traverse A->B->C
                          panic

CPU Z sets ->h_load_next list to A->B->D, but due to weaker memory
ordering on ARM64, Y may observe A->B before it sees B->D, then in this
time window, it can traverse A->B->C and reach an invalid se.

We can avoid stale pointer accesses by clearing ->h_load_next when
unregistering a cgroup.

Fixes: 685207963be9 ("sched: Move h_load calculation to task_h_load()")
Suggested-by: Vincent Guittot <vincent.guittot@linaro.org>
Co-developed-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Signed-off-by: Peng Wang <peng_wang@linux.alibaba.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://patch.msgid.link/bf93d41ff9f2da19ef2c1cfb505362e0b48c39de.1761290330.git.peng_wang@linux.alibaba.com
---
 kernel/sched/fair.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 769d7b7..00a32c9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -13687,6 +13687,8 @@ void unregister_fair_sched_group(struct task_group *tg)
 		struct rq *rq = cpu_rq(cpu);
 
 		if (se) {
+			struct cfs_rq *parent_cfs_rq = cfs_rq_of(se);
+
 			if (se->sched_delayed) {
 				guard(rq_lock_irqsave)(rq);
 				if (se->sched_delayed) {
@@ -13696,6 +13698,13 @@ void unregister_fair_sched_group(struct task_group *tg)
 				list_del_leaf_cfs_rq(cfs_rq);
 			}
 			remove_entity_load_avg(se);
+
+			/*
+			 * Clear parent's h_load_next if it points to the
+			 * sched_entity being freed, to avoid stale pointer.
+			 */
+			if (READ_ONCE(parent_cfs_rq->h_load_next) == se)
+				WRITE_ONCE(parent_cfs_rq->h_load_next, NULL);
 		}
 
 		/*

             reply	other threads:[~2025-12-03 16:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03 16:52 tip-bot2 for Peng Wang [this message]
2025-12-29 12:50 ` [tip:sched/urgent] " Cruz Zhao
2025-12-29 13:58   ` Vincent Guittot
2026-01-03  1:47     ` Krister Johansen
2026-01-12 17:32       ` Vincent Guittot
2026-01-15  8:27         ` Krister Johansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176478073513.498.15089394378873483436.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=CruzZhao@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peng_wang@linux.alibaba.com \
    --cc=vincent.guittot@linaro.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®