All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v2 sched_ext/for-7.1-fixes] sched_ext: Fix ops->priv clobber on concurrent attach/detach
Date: Tue, 12 May 2026 00:21:50 +0000	[thread overview]
Message-ID: <20260512002151.569F4C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511061812.2459458-1-arighi@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Error paths in `scx_alloc_and_add_sched()` leave `ops->priv` as a dangling pointer, causing the new `-EBUSY` check to permanently brick the BPF map and exposing a Use-After-Free.
--

commit 451a33ccc662950a2e5e3da8cd4a0309ed7f2725
Author: Andrea Righi <arighi@nvidia.com>

sched_ext: Fix ops->priv clobber on concurrent attach/detach

This commit addresses a NULL pointer dereference caused by a race condition
during concurrent attach and detach operations. It adds a check to reject
attempts to reuse a kdata that is still bound to a previous scheduler
instance.

> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -6733,6 +6733,19 @@ static void scx_root_enable_workfn(struct kthread_work *work)
>  		goto err_unlock;
>  	}
>  
> +	/*
> +	 * @ops->priv binds @ops to its scx_sched instance. It is set here by
> +	 * scx_alloc_and_add_sched() and cleared at the tail of bpf_scx_unreg(),
> +	 * which runs after scx_root_disable() has dropped scx_enable_mutex. If
> +	 * it's still non-NULL here, a previous attachment on @ops has not
> +	 * finished tearing down; proceeding would let the in-flight unreg's
> +	 * RCU_INIT_POINTER(NULL) clobber the @ops->priv we are about to assign.
> +	 */
> +	if (rcu_access_pointer(ops->priv)) {
> +		ret = -EBUSY;
> +		goto err_unlock;
> +	}

If scx_alloc_and_add_sched() fails during a subsequent attachment attempt,
does this leave ops->priv pointing to freed memory?

Looking at scx_alloc_and_add_sched(), the BPF operations map is bound to
the new scheduler instance early:

    rcu_assign_pointer(ops->priv, sch);

If a later initialization step in that function fails, such as allocating
cgrp_path or failing kobject_init_and_add, the error paths free sch via
kfree(sch) or kobject_put(&sch->kobj). However, the error paths do not
reset ops->priv to NULL.

Because ops->priv retains the dangling pointer to the freed memory, will
the new check added here permanently block any future attachments by always
returning -EBUSY?

Could this dangling ops->priv pointer also be accessed by a BPF program
running a sched_ext kfunc like scx_bpf_kick_cpu, resulting in a
use-after-free when scx_prog_sched() retrieves and dereferences it?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511061812.2459458-1-arighi@nvidia.com?part=1

      parent reply	other threads:[~2026-05-12  0:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11  6:18 [PATCH v2 sched_ext/for-7.1-fixes] sched_ext: Fix ops->priv clobber on concurrent attach/detach Andrea Righi
2026-05-11  7:47 ` Tejun Heo
2026-05-11  7:52   ` Andrea Righi
2026-05-12  0:21 ` sashiko-bot [this message]

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=20260512002151.569F4C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=sashiko@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.