From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796536600; b=DfZ6NxM3d3jzc+sepDLj2eqz/oT+DbIJCH4JTzMNDp8A69rsdY05wGLoJn+68NZEKIux MPmnvVREgvejxXlk6J3wlA2FZZjwxZmYS75Adt4lWYbP/NXEsnMKHMCLCePu2aEGfztyW mQZcoecBqBixUEjHjdiVUrgDEqrWzuaNpJuNnQnm5Ftaqq1n7C9G5Be9U2nAhS5H6/F6v o4n57zt+GK5+FfM8gyfslkszkV5MgTiv5d63gxRssePE0TOG5BTtBKb3Z5vEp+bJwb+ri 0EHZMTl1WN9aaSlVrGgmuvO71dTy6qj239Qx/RiZ5oegVHlxz196OyIQaD24zDd+dkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536600; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=A1wt3zwkkFdCgW3XHD1j3g99Uqo3FmUDO6zvsJqtZ5o=; b=n/1b32B3SAGmghDIyUdRbwMQ+naroua/Kgrc07Yvzg38s81FxGxdlEi3r58LqtN+VpNh /cr+1xVu7HBRjQDzxWcAA+0imrcVpo4gPySv7RsgMgaEXkzOQO0Qy/ztTELxlkP9jwUgy iWE3Z9/e4eMXHZlua56gZABX9UzUFpQyr5GIXMXTbF/viqUI0/TEF7GMHST53xg+013GQ GL3XRSoC+CTqdOjXy9eipZuW+ZbQP+o2Y0El/KypkvBbBi8CgxLcGELJRwUtiEEBTDh9a 03N2wZxOSBhZte4C1tjQLilMuTrsPgqg4RhlrNo1f4G+0TSkninzJNppEEtk/Jcg74Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BXNGLEUK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1235E606A31F for ; Sun, 6 Dec 2026 05:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BXNGLEUK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4094F1F0093B; Sun, 6 Dec 2026 05:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796536599; bh=A1wt3zwkkFdCgW3XHD1j3g99Uqo3FmUDO6zvsJqtZ5o=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BXNGLEUK0J1G2rQNQpzeA+bWs1nkspsrCGKxBJ1jQwWzdhHZCWRIWF7OGrmAfhDpz UJ2UveJW6KVf9u+H+l7fqND6yF2EeO1SGmZfGmv4H+FDZdSqfWHcw8th3GZXMx4bS+ 2wLnnjAtV4TLAyQefibcjYj2DsKF9PeKaxtDV/bmAkVmvPtzkKbNrcAUwFCvQ1WrrW f0KR8m8mWs2/MEEwns/gl/AolcrTc0a8aEvDrF94BYU7JJFI5bYMviNEVJX5gfj9g4 TS1AAsG9dtZsRuCXdtJ2Y7RkC0lno+roHfYpObSQ1FU1T05twbXqlL7JsqXOI4FMGr IDEGW5f59c+dA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 4/6] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Reply-To: sashiko-reviews@lists.linux.dev To: "Changwoo Min" Cc: sched-ext@lists.linux.dev In-Reply-To: <20261206053728.2026272-5-changwoo@igalia.com> References: <20261206053728.2026272-1-changwoo@igalia.com> <20261206053728.2026272-5-changwoo@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 05:56:36 +0000 X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] sched_ext: scx_qmap: unverified bpf_priv tag collision in lookup_task_ctx() -- commit 5c944365906adb946e34a37a4704476bce3c8842 Author: Changwoo Min sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv This commit caches each task's task_ctx arena pointer in p->scx.bpf_priv tagged with scx_bpf_sched_id(), so lookup_task_ctx() can avoid a task storage lookup on the fast path. > diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bp= f.c > index 3951f1f6e3c6a..90237a1ce38aa 100644 > --- a/tools/sched_ext/scx_qmap.bpf.c > +++ b/tools/sched_ext/scx_qmap.bpf.c [ ... ] > @@ -256,12 +257,49 @@ static s32 pick_direct_dispatch_cid(struct task_str= uct *p, s32 prev_cid, > */ > #define QMAP_TOUCH_ARENA() do { asm volatile("" :: "r"(&arena)); } while= (0) > =20 > +/* > + * p->scx.bpf_priv caches @p's task_ctx so that lookup_task_ctx() takes = a load > + * instead of a task storage lookup. The field holds whatever the sched = owning > + * @p stored, and a qmap sched also sees tasks of its sub-scheds, e.g. in > + * qmap_core_sched_before() and qmap_dump_task(). So the cached value ca= rries > + * this sched's id as a tag: > + * > + * task_ctx_key > + * 63-32 upper 32 bits of the arena's pointers > + * 31 1, TASK_CTX_TAG_BIT > + * 30-0 id from scx_bpf_sched_id(), 1 <=3D id < 2^31 > + * > + * p->scx.bpf_priv > + * 63 1, TASK_CTX_TAG_BIT > + * 62-32 id > + * 31-0 lower 32 bits of @p's task_ctx pointer > + * > + * The arena never crosses a 4G boundary, so all its pointers share the = upper > + * 32 bits. Ids are never reused, so a value left by another sched, incl= uding > + * one that has since unloaded, never matches. An arena pointer is a use= r space > + * address, whose most significant bit is always zero. Bit 31 of the tag= is the > + * most significant bit of p->scx.bpf_priv, and setting it to 1 makes the > + * cached value an invalid user space address, for foolproofing. > + * > + * qmap_enable() sets the value. The first call also sets task_ctx_key, = which > + * then never changes. qmap_exit_task() clears the value before freeing = the > + * task_ctx, as the kernel clears it only after ops.exit_task(). > + */ > +#define TASK_CTX_TAG_BIT (1U << 31) > + > +static u64 task_ctx_key; > + > static task_ctx_t *lookup_task_ctx(struct task_struct *p) > { > struct task_ctx_stor_val *v; > + u64 key =3D READ_ONCE(task_ctx_key); > + u64 priv =3D scx_bpf_task_priv(p); > =20 > QMAP_TOUCH_ARENA(); > =20 > + if (key && (u32)(priv >> 32) =3D=3D (u32)key) > + return (task_ctx_t *)((key & ~0xffffffffULL) | (u32)priv); [Severity: Low] Can lookup_task_ctx() return a bogus arena pointer when a non-qmap sub-scheduler writes an arbitrary u64 to p->scx.bpf_priv? p->scx.bpf_priv has no kernel-enforced tagging format, so a sub-scheduler can store a value whose upper 32 bits match TASK_CTX_TAG_BIT | id (for example, 0x80000001 when scx_qmap has id 1). When qmap_core_sched_before() runs on that task, lookup_task_ctx() reconstructs an unvalidated offset in scx_qmap's arena instead of returning NULL. Dereferencing it then reads unrelated arena memory (corrupting core-sched ordering) or faults to 0 on an unmapped page. The comment and commit message also overstate the guarantee, since non-reuse of scheduler ids only prevents collisions between schedulers using this tagging layout. Checking scx_task_sched_id(p) against scx_bpf_sched_id() under the rq lock (as documented on scx_bpf_task_set_priv()), or validating that the pointer lies within qa.task_ctxs, would avoid false matches. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206053728.2026= 272-1-changwoo@igalia.com?part=3D4