From: Aaron Tomlin <atomlin@atomlin.com>
To: tsbogend@alpha.franken.de, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com, andrii@kernel.org,
ast@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com,
memxor@gmail.com, mingo@redhat.com, peterz@infradead.org,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
stephen.smalley.work@gmail.com, casey@schaufler-ca.com,
longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org,
mkoutny@suse.com
Cc: ihor.solodrai@linux.dev, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
chenridong@huaweicloud.com, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, kprateek.nayak@amd.com, omosnace@redhat.com,
kees@kernel.org, atomlin@atomlin.com, neelx@suse.com,
sean@ashe.io, chjohnst@gmail.com, steve@abita.co,
mproche@gmail.com, nick.lange@gmail.com, cgroups@vger.kernel.org,
linux-mips@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 0/2] security: Expand task_setscheduler LSM hook
Date: Wed, 18 Nov 2026 23:07:03 -0500 [thread overview]
Message-ID: <20261119040705.684987-1-atomlin@atomlin.com> (raw)
This series expands the task_setscheduler LSM hook to accept nullable
pointers to the requested sched_attr and cpumask alongside the target
task_struct. For sched_setaffinity(), passing the raw user-supplied
affinity mask allows LSMs such as the BPF LSM to audit or filter the
mask as requested by userspace before __sched_setaffinity() intersects
it with the task's allowed cpuset CPUs, which seccomp filters cannot
inspect behind user pointers and scheduler tracepoints only observe
post-intersection. Similarly, __sched_setscheduler() passes a local
sched_attr populated with the resolved scheduling policy and effective
SCHED_FLAG_RESET_ON_FORK state so parameter-only updates expose the
effective values rather than internal sentinels or caller defaults, and
cpuset task migrations and CLONE_INTO_CGROUP pass the destination
cpuset's effective_cpus mask (note that direct writes to cpuset.cpus
update task affinity via cpuset_update_tasks_cpumask() without invoking
this hook).
Because BPF_LSM_MAC trampolines place the previous return value in
context argument slot nr_args, expanding task_setscheduler from one
parameter to three shifts ret from slot 1 to slot 3; existing
two-argument BPF_PROG(name, struct task_struct *p, int ret) programs on
lsm/task_setscheduler will therefore be rejected by the verifier until
updated to the expanded signature. Patch 2 extends the BPF LSM
selftests to verify the hook's runtime arguments and -EPERM mediation
across sched_setscheduler(), sched_setparam(), sched_setattr() with
SCHED_FLAG_KEEP_POLICY, sched_setaffinity(), and
/proc/[pid]/timerslack_ns, alongside verifier checks for the __nullable
annotations.
Changes since v5:
- Replaced the second paragraph of Patch 1's commit message with the
concrete rationale for inspecting the user-requested affinity mask
and scheduling attributes prior to cpuset intersection, and clarified
the scope of affinity mediation relative to cpuset.cpus writes
(Chris Down, Peter Zijlstra)
- In __sched_setscheduler(), synchronised SCHED_FLAG_RESET_ON_FORK in
lsm_attr.sched_flags with the resolved reset_on_fork value so
parameter-only updates accurately reflect the task's effective
reset-on-fork state (Chris Down)
- Clarified the kerneldoc for security_task_setscheduler() to document
what @in_mask represents for sched_setaffinity(), cpuset cgroup
migrations, and CLONE_INTO_CGROUP (Chris Down)
- Added Patch 2 to extend the BPF LSM runtime and verifier selftests
for the expanded task_setscheduler hook
- Link to v5: https://lore.kernel.org/lkml/20261105172210.76706-1-atomlin@atomlin.com/
Changes since v4:
- Rebased against v7.4-rc1
- In __sched_setscheduler(), populate a local copy of sched_attr with
the resolved scheduling policy before calling
security_task_setscheduler() so parameter-only updates (such as
sched_setparam() or sched_setattr() with SCHED_FLAG_KEEP_POLICY) pass
the effective policy rather than SETPARAM_POLICY (-1)
- Clarified the commit message to reflect that both the sched_attr and
cpumask parameters are introduced by this patch
- Link to v4: https://lore.kernel.org/all/20260720014156.459386-1-atomlin@atomlin.com/
Changes since v3:
- Expanded the task_setscheduler LSM hook to accept the 'sched_attr'
payload, enabling BPF and other LSMs to inspect scheduling attributes
(Peter Zijlstra)
- Updated all call sites for security_task_setscheduler() to correctly
pass the attr structure when available, or NULL otherwise
(Peter Zijlstra)
- Added the necessary forward declaration for struct sched_attr to
include/linux/security.h
- Link to v3: https://lore.kernel.org/lkml/20260526142838.774711-1-atomlin@atomlin.com/
Changes since v2:
- Dropped patch 1. This is to be addressed by the cgroup cpuset
maintainer (Waiman Long)
- Dropped patch 3. Will be submitted as a separate patch (Paul Moore)
- Link to v2: https://lore.kernel.org/lkml/20260509213803.968464-1-atomlin@atomlin.com/
Changes since v1:
- Reordered the allocation and user-copy of new_mask in the MIPS
architecture's mipsmt_sys_sched_setaffinity() to occur before the
LSM hook is invoked. This ensures the security modules evaluate a fully
populated mask rather than uninitialised memory, while cleanly handling
error unwinding
- Updated cpuset_can_fork() to pass the destination cpuset's effective CPU
mask instead of NULL
- Link to v1: https://lore.kernel.org/lkml/20260509164847.939294-1-atomlin@atomlin.com/
Aaron Tomlin (2):
security: Expand task_setscheduler LSM hook
selftests/bpf: Verify task_setscheduler LSM hook parameters
arch/mips/kernel/mips-mt-fpaff.c | 2 +-
fs/proc/base.c | 2 +-
include/linux/lsm_hook_defs.h | 4 +-
include/linux/security.h | 15 +-
kernel/cgroup/cpuset.c | 4 +-
kernel/sched/syscalls.c | 11 +-
security/commoncap.c | 9 +-
security/security.c | 21 ++-
security/selinux/hooks.c | 4 +-
security/smack/smack_lsm.c | 13 +-
.../selftests/bpf/prog_tests/test_lsm.c | 164 ++++++++++++++++++
tools/testing/selftests/bpf/progs/lsm.c | 51 ++++++
.../selftests/bpf/progs/verifier_lsm.c | 49 ++++++
13 files changed, 328 insertions(+), 21 deletions(-)
--
2.55.0
next reply other threads:[~2026-11-19 4:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 4:07 Aaron Tomlin [this message]
2026-11-19 4:07 ` [PATCH v6 1/2] " Aaron Tomlin
2026-11-19 4:07 ` [PATCH v6 2/2] selftests/bpf: Verify task_setscheduler LSM hook parameters Aaron Tomlin
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=20261119040705.684987-1-atomlin@atomlin.com \
--to=atomlin@atomlin.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=bsegall@google.com \
--cc=casey@schaufler-ca.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huaweicloud.com \
--cc=chjohnst@gmail.com \
--cc=daniel@iogearbox.net \
--cc=dietmar.eggemann@arm.com \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hannes@cmpxchg.org \
--cc=ihor.solodrai@linux.dev \
--cc=jmorris@namei.org \
--cc=jolsa@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=longman@redhat.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=mproche@gmail.com \
--cc=neelx@suse.com \
--cc=nick.lange@gmail.com \
--cc=omosnace@redhat.com \
--cc=paul@paul-moore.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sean@ashe.io \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=song@kernel.org \
--cc=stephen.smalley.work@gmail.com \
--cc=steve@abita.co \
--cc=tj@kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yonghong.song@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 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®