]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selinux: fix incorrect execmem checks on overlayfs
authorOndrej Mosnacek <omosnace@redhat.com>
Tue, 14 Jul 2026 12:57:59 +0000 (14:57 +0200)
committerPaul Moore <paul@paul-moore.com>
Tue, 14 Jul 2026 22:10:20 +0000 (18:10 -0400)
commit9fe595fad54d4ac6a402edb3f60bec859d52cea6
tree3239fe405d8bb8b3c2b71c416dc4345784c389e3
parenta13c140cc289c0b7b3770bce5b3ad42ab35074aa
selinux: fix incorrect execmem checks on overlayfs

The commit fixing the overlayfs mmap() and mprotect() access checks
failed to skip the execmem check in __file_map_prot_check() for the case
where the "mounter check" is being performed. This check should be
performed only against the credentials of the task that is calling
mmap()/mprotect(), since it doesn't pertain to the file itself, but
rather just gates the ability of the calling task to get an executable
memory mapping in general.

The purpose of the "mounter check" is to guard against using an
overlayfs mount to gain file access that would otherwise be denied to
the mounter. For execmem this is not relevant, as there is no further
file access granted based on it (notice that the file's context is not
used as the target in the check), so checking it also against the
mounter credentials would be incorrect.

Fix this by passing a boolean to [__]file_map_prot_check() and
selinux_mmap_file_common() that indicates if we are doing the "mounter
check" and skiping the execmem check in that case. Since this boolean
also indicates if we use current_cred() or the mounter cred as the
subject, also remove the "cred" argument from these functions and
determine it based on the boolean and the file struct.

Cc: stable@vger.kernel.org
Fixes: 82544d36b172 ("selinux: fix overlayfs mmap() and mprotect() access checks")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/hooks.c