[PATCH RFC 11/19] selinux: revalidate inherited files before taking exec_update_lock
bot+bpf-ci at kernel.org
bot+bpf-ci at kernel.org
Tue Nov 24 23:49:11 UTC 2026
> selinux: revalidate inherited files before taking exec_update_lock
TL;DR: Moving flush_unauthorized_files() earlier changes the comm logged in
SELinux AVC denials to the pre-exec name instead of the new program's; asks
whether that is intended and, if so, to note it in the commit message.
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
[ ... ]
> +/*
> + * Close files for which the new task SID is not authorized. Called before
> + * exec_update_lock is taken as closing files may block in the filesystem.
> + */
> +static void selinux_bprm_revalidate_files(const struct linux_binprm *bprm)
> +{
> + const struct cred_security_struct *new_crsec = selinux_cred(bprm->cred);
> +
> + if (new_crsec->sid == new_crsec->osid)
> + return;
> +
> + flush_unauthorized_files(bprm->cred, current->files);
> +}
Moving this call changes what the resulting AVC denial records contain.
Denials from flush_unauthorized_files() go through match_file() ->
file_has_perm() -> avc_has_perm() and are formatted by
dump_common_audit_data(), which logs the program name from current->comm:
audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
audit_log_untrustedstring(ab, get_task_comm(comm, current));
Previously this ran from selinux_bprm_committing_creds() in
begin_new_exec(), after __set_task_comm(me, kbasename(bprm->filename), true),
so the record carried the new program's comm together with the new
scontext.
The new hook is called right after close_cloexec_files(), well before
__set_task_comm(), so a denial for a revoked fd or controlling tty now
reports the pre-exec comm (for a fork+exec, the parent's name such as "sh")
while scontext is already the new domain.
Is this change in the logged comm intended? The commit message does not
mention it. If it is acceptable, could it be noted in the changelog?
---
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/45508356147
More information about the Linux-security-module-archive
mailing list