From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52CA93BFAEA for ; Tue, 16 Jun 2026 14:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781621658; cv=none; b=ZJZZFYXLtFDoMWmYrUyA5dyDMRrdMFsre/6GflIufhZ7sNH9NpPFxfqVH6TY01J7Kv0qm5+2s0HN6bd3A9UatQvKsWBSUIXYaG7BL3zr/ELFDTVJJqSkRTUgEOHo8KcsckNlV18lpn/waVzqufqvBMABe01xJZKQAWgmFYkL8ko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781621658; c=relaxed/simple; bh=lm0Gp9EGRlkOdWvio5EQyJxz/IG548KsvdlPVCXtor8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g/Ugjhjht6EmYPD/PYgVprCQ+t/QYyeXTyefWNfWEedBsqAvmNnHE/bKLKXiiuCBHiIW7QyByqh3oEbE95e1m0ChKXHxeGQIp8saCof0FYJH7uZpcpYO5u56U3uPN5i0WO7TnTb/TZNRZBj0wRnWfyPjRVHWW08DesnGFV0pHYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=surriel.com; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b=A+Gh4rdE; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=surriel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b="A+Gh4rdE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=9KSBFBqKZvKuDrUhymdgvncPVnYWOg/orTvndJtKOhc=; b=A+Gh4rdEAUshcHYCBi9pQ1E4yj Ud6Lq1U2dFQ6qlaflvroOR3SdfDVqWptQ//3J7VyPFS5am9yPr44m9FxCW+UDBHMn/IdEuwh+ivgf QtIBzwagNRlBOUJo8P6y+4Rx6MSwwBnx4dfJW81UDsWYAgpAyN1A8+MhWvro/1lNsimLQiDe8LB4X 1EpzGDl5WoXGk0SlFtJXeo51uDx6lIMcjwcL67EW+2VzzbgNgex0NiHMCDb6R9s0Gu761y5/NQVqQ x+BM0usKMFlUmBHGbPYfMJiTrDZYq0nB/34sCc0Bj51Qq01L7HA1mQafaASwiZWC5x1Kd6pt1g30o uWme/vtA==; Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1wZVAx-000000002wD-2shR; Tue, 16 Jun 2026 10:54:03 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, Rik van Riel , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Thomas Gleixner , Mathieu Desnoyers , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Subject: [PATCH] sched/mmcid: fix OOB clear_bit when CID is MM_CID_UNSET in fixup path Date: Tue, 16 Jun 2026 10:53:43 -0400 Message-ID: <20260616145343.1491887-1-riel@surriel.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In mm_cid_fixup_cpus_to_tasks(), when rq->curr has the target mm and mm_cid.active is set, the CID is checked with cid_in_transit() before setting the transition bit. In per-CPU mode a newly forked or exec'd task can be running with mm_cid.cid == MM_CID_UNSET because CIDs are assigned lazily on schedule-in. With cid_in_transit() the guard passes for MM_CID_UNSET (no transit bit), converts it to MM_CID_UNSET | MM_CID_TRANSIT and stores it back; later mm_cid_schedout() feeds this to clear_bit() with MM_CID_UNSET as the bit number, triggering an out-of-bounds write. Symptoms: this is genuine memory corruption, but a bounded out-of-bounds write, not an arbitrary one. MM_CID_UNSET is the fixed sentinel BIT(31), so once the bad value reaches mm_cid_schedout() the cid_from_transit_cid() strip leaves MM_CID_UNSET, which fails the "cid < max_cids" convergence test and falls into mm_drop_cid() -> clear_bit(MM_CID_UNSET, mm_cidmask(mm)). The cid bitmap is embedded in the mm_struct slab object (after cpu_bitmap and mm_cpus_allowed) and is only num_possible_cpus() bits wide, so clearing bit 31 is a deterministic OOB bit-clear at a fixed offset of 2^31 / 8 == 256 MiB past the bitmap base. The address is not attacker-influenced (fixed sentinel -> fixed offset) and the op only clears a single bit; what sits 256 MiB further along the direct map is whatever kernel object happens to live there, so this corrupts one bit of unpredictable kernel memory -- it is not an arbitrary-address or arbitrary-value write. It triggers only in per-CPU CID mode, when a CPU is running an active task of the target mm whose cid is still MM_CID_UNSET -- the fork()/execve() window before that task's next schedule-in assigns it a real CID -- and a per-CPU -> per-task fixup walks over it (the mode fallback driven by a thread exit, sched_mm_cid_exit(), or by the deferred max_cids recompute in mm_cid_work_fn()). In practice syzkaller surfaced it as a KASAN use-after-free reported in __schedule -> mm_cid_switch_to, where the offending clear_bit() is inlined via mm_cid_schedout() -> mm_drop_cid(). Switch to cid_on_task() which excludes MM_CID_UNSET, MM_CID_ONCPU, and MM_CID_TRANSIT, so we only set the transition bit on a genuine task-owned CID. Fixes: fbd0e71dc370 ("sched/mmcid: Provide CID ownership mode fixup functions") Assisted-by: Claude:claude-opus-4-8 syzkaller Signed-off-by: Rik van Riel Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Thomas Gleixner Cc: Mathieu Desnoyers Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider Cc: K Prateek Nayak Cc: linux-kernel@vger.kernel.org --- kernel/sched/core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 8b791e9e9f67..4c8b6ca254ce 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10909,8 +10909,19 @@ static void mm_cid_fixup_cpus_to_tasks(struct mm_struct *mm) } else if (rq->curr->mm == mm && rq->curr->mm_cid.active) { unsigned int cid = rq->curr->mm_cid.cid; - /* Ensure it has the transition bit set */ - if (!cid_in_transit(cid)) { + /* + * Only a genuine task-owned CID needs the transition + * bit. A running active task can legitimately have + * MM_CID_UNSET here: in per-CPU mode CIDs are assigned + * lazily on schedule-in, so fork()/execve() leave the + * task active with no owned CID until its next + * schedule-in. cid_on_task() excludes the + * MM_CID_UNSET/ONCPU/TRANSIT bits, so we never turn + * e.g. MM_CID_UNSET into MM_CID_UNSET|MM_CID_TRANSIT, + * which mm_cid_schedout() would later feed to + * clear_bit() as an out-of-bounds bit number. + */ + if (cid_on_task(cid)) { cid = cid_to_transit_cid(cid); rq->curr->mm_cid.cid = cid; pcp->cid = cid; -- 2.53.0-Meta