mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/2] security: Expand task_setscheduler LSM hook
@ 2026-11-19  4:07 Aaron Tomlin
  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
  0 siblings, 2 replies; 4+ messages in thread
From: Aaron Tomlin @ 2026-11-19  4:07 UTC (permalink / raw)
  To: tsbogend, paul, jmorris, serge, andrii, ast, daniel, eddyz87,
	memxor, mingo, peterz, juri.lelli, vincent.guittot,
	stephen.smalley.work, casey, longman, tj, hannes, mkoutny
  Cc: ihor.solodrai, martin.lau, song, yonghong.song, jolsa, emil,
	chenridong, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, kprateek.nayak, omosnace, kees, atomlin, neelx, sean,
	chjohnst, steve, mproche, nick.lange, cgroups, linux-mips,
	linux-fsdevel, linux-security-module, selinux, bpf,
	linux-kselftest, linux-kernel

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19  4:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  4:07 [PATCH v6 0/2] security: Expand task_setscheduler LSM hook Aaron Tomlin
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
2026-11-19  4:52   ` bot+bpf-ci

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®