On Tue, Nov 24, 2026 at 6:49 PM <[email protected]> wrote: > > > 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.
While the "comm=" field in the audit record isn't a perfect tool, in practice it proves to be rather useful and changing this behavior will likely confuse users and admins. We really need to make sure that current->comm is set to the new value prior to calling into the new LSM hook. -- paul-moore.com
