From: sashiko-bot@kernel.org
To: "Reinette Chatre" <reinette.chatre@intel.com>,
kees@kernel.org, mingo@redhat.com, peterz@infradead.org,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, david@kernel.org, ljs@kernel.org,
liam@infradead.org, vbabka@kernel.org, rppt@kernel.org,
surenb@google.com, mhocko@suse.com, tony.luck@intel.com,
ben.horgan@arm.com, bp@alien8.de, tglx@linutronix.de,
dave.hansen@linux.intel.com, Dave.Martin@arm.com,
james.morse@arm.com, babu.moger@amd.com, fustini@kernel.org,
jedrzej.wasiukiewicz@intel.com
Cc: fenghuay@nvidia.com, peternewman@google.com, yu.c.chen@intel.com,
x86@kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v2 4/4] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer
Date: Sat, 05 Dec 2026 19:16:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-251857@kernel.org> (raw)
In-Reply-To: <78cea45bb6a09a092bf1ca48b582843fdac627e7.1796411500.git.reinette.chatre@intel.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] selftests/resctrl: cleanup() signals stale reaped PIDs as root
- [Low] selftests/resctrl: cleanup() resets INT and TERM traps to
default
- [Low] selftests/resctrl: signal race leaks untracked forker before
FORKERS append
- [Low] selftests/resctrl: arming cleanup() before mkdir causes TOCTOU
rmdir
--
commit 2ab03f3eb3449ef47dd2b5c82faf9532afafebbe
Author: Jedrzej Wasiukiewicz <jedrzej.wasiukiewicz@intel.com>
NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer
This commit adds a standalone reproducer script under
tools/testing/selftests/resctrl/ that races removing a resctrl monitor group
against concurrent forks and checks whether any task retains the removed
RMID when new monitor groups exhaust the RMID pool.
> diff --git a/tools/testing/selftests/resctrl/stray_tasks_repro.sh b/tools/testing/selftests/resctrl/stray_tasks_repro.sh
> new file mode 100755
> index 0000000000000..42f65d7d7bb4d
> --- /dev/null
> +++ b/tools/testing/selftests/resctrl/stray_tasks_repro.sh
> @@ -0,0 +1,122 @@
[ ... ]
> +[ ! -e $C ] || { echo "$C already exists, remove it first"; exit 1; }
> +
> +FORKERS=() # PIDs of the forker processes
> +KIDS="" # PIDs of their children
> +
> +# Runs on every exit, including Ctrl-C: stop all test processes and remove the
> +# test groups.
> +cleanup() {
> + trap - EXIT INT TERM
> + [ -n "$KIDS" ] || [ ${#FORKERS[@]} -eq 0 ] ||
> + KIDS=$(pgrep -P "$(IFS=,; echo "${FORKERS[*]}")")
> + [ ${#FORKERS[@]} -eq 0 ] || kill "${FORKERS[@]}" 2>/dev/null
> + [ -z "$KIDS" ] || kill $KIDS 2>/dev/null
> + sleep 1
> + rmdir $C/mon_groups/* 2>/dev/null
> + rmdir $C 2>/dev/null
> +}
[Severity: Low]
Should cleanup() clear EXIT and ignore INT and TERM (trap - EXIT; trap '' INT
TERM) instead of resetting them to default with trap - EXIT INT TERM?
A second Ctrl-C or SIGTERM arriving during the 1-second sleep aborts cleanup()
before rmdir removes $C and its monitor groups, leaving the RMID pool
exhausted until manually cleaned up. If interrupted before killing FORKERS,
the 8 background fork loops also stay running.
> +trap cleanup EXIT
> +trap 'exit 130' INT TERM
> +
> +mkdir $C $M || { echo "cannot create $C and $M"; exit 1; }
[Severity: Low]
Can arming the EXIT trap before mkdir $C succeeds delete an unrelated control
group?
If /sys/fs/resctrl/c is created concurrently between the [ ! -e $C ] check and
mkdir $C $M, mkdir fails and runs exit 1, invoking cleanup(). Because
resctrl's rdtgroup_rmdir_ctrl() removes non-empty control groups and moves
their tasks to the default group, cleanup() would tear down that group.
Creating $C before installing the EXIT trap, or gating rmdir in cleanup() on
mkdir $C succeeding, would avoid this.
> +# 8 forkers. Each joins c, then m, and then forks in a loop: a sleeping child
> +# that lives 20 s, plus a very short one that keeps the fork rate high.
> +for i in 1 2 3 4 5 6 7 8; do
> + ( echo $BASHPID > $C/tasks; echo $BASHPID > $M/tasks
> + while :; do sleep 20 & sleep 0.0003; done ) &
> + FORKERS+=($!)
> +done
[Severity: Low]
Can a signal arriving between starting a background subshell and appending $!
to FORKERS leak an infinite fork loop?
In bash, pending trapped signals run between commands:
( ... ) & (subshell spawned, $! set)
<SIGINT / SIGTERM>
exit 130 -> cleanup()
kill "${FORKERS[@]}" <-- new subshell not yet in FORKERS
Because non-interactive bash ignores SIGINT in asynchronous subshells and
SIGTERM to the script is not forwarded to children, the untracked subshell
keeps spawning sleeping processes indefinitely.
Terminating children of $$ in cleanup() or deferring signals around the spawn
loop would close this window.
[ ... ]
> +# Remember the children for cleanup, then stop the forkers. The children stay.
> +KIDS=$(pgrep -P "$(IFS=,; echo "${FORKERS[*]}")")
> +kill "${FORKERS[@]}" 2>/dev/null
> +sleep 2 # let forks that are still in flight finish
[Severity: Low]
Can cleanup() send SIGTERM as root to unrelated processes via stale PIDs in
FORKERS and KIDS?
Here KIDS captures short-lived sleep 0.0003 children that exit and get reaped
almost immediately, and FORKERS is killed without waiting or clearing
FORKERS=(). During sleep 2 and the mkdir loop, bash reaps the FORKERS jobs
and returns their PIDs to the kernel.
On exit, cleanup() runs as root and calls kill "${FORKERS[@]}" again (and
pgrep -P on those PIDs if KIDS was empty) along with kill $KIDS. If the PID
allocator wraps around during that window, especially when running the script
in a loop, cleanup() can terminate unrelated processes.
Waiting on FORKERS and clearing FORKERS=() after killing them, or running the
workload in a dedicated process group, would avoid signaling reaped PIDs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796411500.git.reinette.chatre@intel.com?part=4
next prev parent reply other threads:[~2026-12-05 19:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:15 [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 1/4] arm64: mpam: Remove unneeded include of linux/arm_mpam.h Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 2/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 3/4] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 4/4] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre
2026-12-05 19:16 ` sashiko-bot [this message]
2026-12-04 21:07 ` [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Luck, Tony
2026-12-04 23:00 ` Reinette Chatre
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-251857@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=ben.horgan@arm.com \
--cc=bp@alien8.de \
--cc=bsegall@google.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=fenghuay@nvidia.com \
--cc=fustini@kernel.org \
--cc=james.morse@arm.com \
--cc=jedrzej.wasiukiewicz@intel.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=peternewman@google.com \
--cc=peterz@infradead.org \
--cc=reinette.chatre@intel.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
--cc=yu.c.chen@intel.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