[PATCH v6 2/2] selftests/bpf: Verify task_setscheduler LSM hook parameters

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Thu Nov 19 04:52:49 UTC 2026


> selftests/bpf: Verify task_setscheduler LSM hook parameters

TL;DR: Nit only, in the new task_setscheduler selftest: the restore_sched flag
and the saved_policy initializer look redundant, so the scheduler restore at
out: could be unconditional.

> diff --git a/tools/testing/selftests/bpf/prog_tests/test_lsm.c b/tools/testing/selftests/bpf/prog_tests/test_lsm.c
> --- a/tools/testing/selftests/bpf/prog_tests/test_lsm.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_lsm.c

[ ... ]

> +static int test_lsm_task_setscheduler(struct lsm *skel)
> +{

[ ... ]

> +	int cpu, saved_policy = -1;
> +	pid_t child_pid = -1, waited;
> +	bool restore_sched = false;
> +	bool restore_aff = false;
> +	int len, ret = -1;
> +
> +	saved_policy = sched_getscheduler(0);
> +	if (!ASSERT_GE(saved_policy, 0, "sched_getscheduler"))
> +		return -1;
> +	if (!ASSERT_OK(sched_getparam(0, &saved_param), "sched_getparam"))
> +		return -1;
> +	restore_sched = true;

this isn't a bug, but since every "goto out" happens after
"restore_sched = true", could the restore_sched flag (and the
"saved_policy = -1" initializer, which is overwritten by the next
statement) be dropped and the restore at out: done unconditionally?

[ ... ]

> +out:
> +	skel->bss->setsched_deny = 0;

[ ... ]

> +	if (restore_sched)
> +		sched_setscheduler(0, saved_policy, &saved_param);
> +	return ret;
> +}


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44458173002


More information about the Linux-security-module-archive mailing list