Commit d4564b29 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Isaac Manjarres
Browse files

BACKPORT: FROMGIT: memfd,selinux: call security_inode_init_security_anon()

Prior to this change, no security hooks were called at the creation of a
memfd file. It means that, for SELinux as an example, it will receive
the default type of the filesystem that backs the in-memory inode. In
most cases, that would be tmpfs, but if MFD_HUGETLB is passed, it will
be hugetlbfs. Both can be considered implementation details of memfd.

It also means that it is not possible to differentiate between a file
coming from memfd_create and a file coming from a standard tmpfs mount
point.

Additionally, no permission is validated at creation, which differs from
the similar memfd_secret syscall.

Call security_inode_init_security_anon during creation. This ensures
that the file is setup similarly to other anonymous inodes. On SELinux,
it means that the file will receive the security context of its task.

The ability to limit fexecve on memfd has been of interest to avoid
potential pitfalls where /proc/self/exe or similar would be executed
[1][2]. Reuse the "execute_no_trans" and "entrypoint" access vectors,
similarly to the file class. These access vectors may not make sense for
the existing "anon_inode" class. Therefore, define and assign a new
class "memfd_file" to support such access vectors.

Guard these changes behind a new policy capability named "memfd_class".

[1] https://crbug.com/1305267
[2] https://lore.kernel.org/lkml/20221215001205.51969-1-jeffxu@google.com/



Signed-off-by: default avatarThiébaud Weksteen <tweek@google.com>
Reviewed-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
Tested-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
Acked-by: default avatarHugh Dickins <hughd@google.com>
[PM: subj tweak]
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
Bug: 455715706
Bug: 111903542
Change-Id: Ib9d8f160212988dca8daa50ee8a49d10b2131b93
(cherry picked from commit 094e94d13b606b820e3d1383e3a361f680ff023a
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/

 dev)
[isaacmanjarres: resolved merge conflict in mm/memfd.c due to lack
of refactoring patches that were merged after 6.12. Also reworked
memfd policy capability checks to avoid breaking the KMI.]
Signed-off-by: default avatarIsaac J. Manjarres <isaacmanjarres@google.com>
parent 76ff62b7
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment