From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>
Cc: David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH sched_ext/for-6.15-fixes] sched_ext: bpf_iter_scx_dsq_new() should always initialize iterator
Date: Tue, 6 May 2025 08:35:22 +0200 [thread overview]
Message-ID: <aBmtqqmP8JiIKKDB@gpd3> (raw)
In-Reply-To: <aBkt_4tEZATxf6-Q@slm.duckdns.org>
On Mon, May 05, 2025 at 11:30:39AM -1000, Tejun Heo wrote:
> From 3ca42b7aea35cbcfb8d1fdde09e10a54edf97b26 Mon Sep 17 00:00:00 2001
> From: Tejun Heo <tj@kernel.org>
> Date: Mon, 5 May 2025 11:28:21 -1000
>
> BPF programs may call next() and destroy() on BPF iterators even after new()
> returns an error value. bpf_iter_scx_dsq_new() could leave the iterator in
> an uninitialized state after an error return causing bpf_iter_scx_dsq_next()
> to dereference garbage data. Make bpf_iter_scx_dsq_new() always clear
> $kit->dsq so that next() and destroy() become noops.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Fixes: 650ba21b131e ("sched_ext: Implement DSQ iterator")
> Cc: stable@vger.kernel.org # v6.12+
> ---
> kernel/sched/ext.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 4e37b40ce280..f5133249fd4d 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -6827,6 +6827,12 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
> BUILD_BUG_ON(__alignof__(struct bpf_iter_scx_dsq_kern) !=
> __alignof__(struct bpf_iter_scx_dsq));
>
> + /*
> + * next() and destroy() will be called regardless of the return value.
> + * Always clear $kit->dsq.
Nit (feel free to ignore): we could mention that bpf_for_each() is the one
calling next() and destroy(), but overall looks good to me.
Acked-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
> + */
> + kit->dsq = NULL;
> +
> if (flags & ~__SCX_DSQ_ITER_USER_FLAGS)
> return -EINVAL;
>
> --
> 2.49.0
next prev parent reply other threads:[~2025-05-06 6:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 21:30 Tejun Heo
2025-05-06 6:35 ` Andrea Righi [this message]
2025-05-07 16:35 ` Tejun Heo
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=aBmtqqmP8JiIKKDB@gpd3 \
--to=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/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®