All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changwoo Min" <changwoo@igalia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v3 5/6] selftests/sched_ext: Test p->scx.bpf_priv across class changes
Date: Sun, 06 Dec 2026 05:59:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-252199@kernel.org> (raw)
In-Reply-To: <20261206053728.2026272-6-changwoo@igalia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/sched_ext: UAF dereferencing p->real_parent in
  is_target()
--

commit 126f4c58d88ef640789b0b03da1a002cdbbc0901
Author: Changwoo Min <changwoo@igalia.com>

selftests/sched_ext: Test p->scx.bpf_priv across class changes

This commit adds the task_bpf_priv sched_ext selftest to verify that
p->scx.bpf_priv persists across scheduling class changes, is cleared for
forked children and on scheduler unload, and rejects writes to other tasks.

> diff --git a/tools/testing/selftests/sched_ext/task_bpf_priv.bpf.c b/tools/testing/selftests/sched_ext/task_bpf_priv.bpf.c
> new file mode 100644
> index 0000000000000..8dec22de52888
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/task_bpf_priv.bpf.c

[ ... ]

> +/* Whether @p is the test task or its child */
> +static bool is_target(struct task_struct *p)
> +{
> +	return p->tgid == target_tgid || p->real_parent->tgid == target_tgid;
> +}

[Severity: Medium]
Can dereferencing p->real_parent here trigger a use-after-free?

Even with SCX_OPS_SWITCH_PARTIAL, sched_ext_dead() invokes ops.exit_task()
for every exiting task on the system.  Once release_task() unlinks an
exiting task in __unhash_process(), its real_parent pointer is no longer
updated by forget_original_parent(), so the parent can exit and be freed
before sched_ext_dead() runs:

CPU0 (exiting task B)             CPU1 (parent A)
do_exit()
  exit_notify()
    release_task(B)
      __unhash_process(B)
        /* unlinked; B->real_parent still points to A */
                                  do_exit()
                                    forget_original_parent(A)
                                      /* misses unlinked B */
                                  ...
                                  free_task(A)
  ...
  sched_ext_dead(B)
    task_bpf_priv_exit_task(B)
      is_target(B)
        B->real_parent->tgid      <-- use-after-free

Because struct task_struct::real_parent is listed in BTF_TYPE_SAFE_RCU,
the verifier emits an unguarded raw load rather than BPF_PROBE_MEM, so
reading from the freed task_struct triggers a KASAN slab-use-after-free or
a kernel page fault if the slab page has been unmapped.

Instead of dereferencing p->real_parent, task_bpf_priv_enable() could
record the child's tgid when cur != p && cur->tgid == target_tgid, and
is_target() could match p->tgid against target_tgid and that recorded
child tgid.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206053728.2026272-1-changwoo@igalia.com?part=5

  reply	other threads:[~2026-12-06  5:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  5:37 [PATCH v3 0/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06  5:37 ` [PATCH v3 1/6] sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id() Changwoo Min
2026-12-06  6:03   ` sashiko-bot
2026-12-06  5:37 ` [PATCH v3 2/6] selftests/sched_ext: Test " Changwoo Min
2026-12-06  5:37 ` [PATCH v3 3/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06  6:00   ` sashiko-bot
2026-12-06  5:37 ` [PATCH v3 4/6] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-06  5:56   ` sashiko-bot
2026-12-06  5:37 ` [PATCH v3 5/6] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-06  5:59   ` sashiko-bot [this message]
2026-12-06  5:37 ` [PATCH v3 6/6] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min
2026-12-06  6:06   ` sashiko-bot

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=sashiko-outbox-252199@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=changwoo@igalia.com \
    --cc=sashiko-reviews@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.