[RFC PATCH] selinux: implement move_mount hook

Stephen Smalley sds at tycho.nsa.gov
Mon Jan 13 16:18:00 UTC 2020

commit 2db154b3ea8e ("vfs: syscall: Add move_mount(2) to move mounts around")
introduced a new move_mount(2) system call and a corresponding new LSM
security_move_mount hook but did not implement this hook for any existing
LSM.  This creates a regression for SELinux with respect to consistent
checking of mounts; the existing selinux_mount hook checks mounton
permission to the mount point path.  Provide a SELinux hook
implementation for move_mount that applies this same check for
consistency.  We may wish to consider defining a new filesystem
move_mount permission and/or a new dir(ectory) move_mount permission
and checking it in this hook in the future.

Fixes: 2db154b3ea8e ("vfs: syscall: Add move_mount(2) to move mounts around")
Signed-off-by: Stephen Smalley <sds at tycho.nsa.gov>
 security/selinux/hooks.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 0606e107fca3..244874b103ff 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2766,6 +2766,19 @@ static int selinux_mount(const char *dev_name,
 		return path_has_perm(cred, path, FILE__MOUNTON);
+static int selinux_move_mount(const struct path *from_path,
+			      const struct path *to_path)
+	const struct cred *cred = current_cred();
+	/*
+	 *  TBD: Check new FILESYSTEM__MOVE_MOUNT permission to
+	 *  from_path->dentry->s_sb and/or new DIR__MOVE_MOUNT
+	 *  permission to from_path?
+	 */
+	return path_has_perm(cred, to_path, FILE__MOUNTON);
 static int selinux_umount(struct vfsmount *mnt, int flags)
 	const struct cred *cred = current_cred();
@@ -6943,6 +6956,8 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
 	LSM_HOOK_INIT(sb_set_mnt_opts, selinux_set_mnt_opts),
 	LSM_HOOK_INIT(sb_clone_mnt_opts, selinux_sb_clone_mnt_opts),
+	LSM_HOOK_INIT(move_mount, selinux_move_mount),
 	LSM_HOOK_INIT(dentry_init_security, selinux_dentry_init_security),
 	LSM_HOOK_INIT(dentry_create_files_as, selinux_dentry_create_files_as),

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