diff mbox series

selinux: add FILE__WATCH_MOUNTNS

Message ID 20250224154836.958915-1-mszeredi@redhat.com (mailing list archive)
State Under Review
Delegated to: Paul Moore
Headers show
Series selinux: add FILE__WATCH_MOUNTNS | expand

Commit Message

Miklos Szeredi Feb. 24, 2025, 3:48 p.m. UTC
Watching mount namespaces for changes (mount, umount, move mount) was added
by previous patches.

This patch adds the file/watch_mountns permission that can be applied to
nsfs files (/proc/$$/ns/mnt), making it possible to allow or deny watching
a particular namespace for changes.

Suggested-by: Paul Moore <paul@paul-moore.com>
Link: https://lore.kernel.org/all/CAHC9VhTOmCjCSE2H0zwPOmpFopheexVb6jyovz92ZtpKtoVv6A@mail.gmail.com/
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 security/selinux/hooks.c            | 3 +++
 security/selinux/include/classmap.h | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

Comments

Paul Moore Feb. 26, 2025, 8:19 p.m. UTC | #1
On Feb 24, 2025 Miklos Szeredi <mszeredi@redhat.com> wrote:
> 
> Watching mount namespaces for changes (mount, umount, move mount) was added
> by previous patches.
> 
> This patch adds the file/watch_mountns permission that can be applied to
> nsfs files (/proc/$$/ns/mnt), making it possible to allow or deny watching
> a particular namespace for changes.
> 
> Suggested-by: Paul Moore <paul@paul-moore.com>
> Link: https://lore.kernel.org/all/CAHC9VhTOmCjCSE2H0zwPOmpFopheexVb6jyovz92ZtpKtoVv6A@mail.gmail.com/
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> ---
>  security/selinux/hooks.c            | 3 +++
>  security/selinux/include/classmap.h | 2 +-
>  2 files changed, 4 insertions(+), 1 deletion(-)

Thanks Miklos, this looks good to me.  VFS folks / Christian, can you
merge this into the associated FSNOTIFY_OBJ_TYPE_MNTNS branch you are
targeting for linux-next?

Acked-by: Paul Moore <paul@paul-moore.com>

--
paul-moore.com
Christian Brauner Feb. 27, 2025, 8:16 a.m. UTC | #2
On Mon, 24 Feb 2025 16:48:36 +0100, Miklos Szeredi wrote:
> Watching mount namespaces for changes (mount, umount, move mount) was added
> by previous patches.
> 
> This patch adds the file/watch_mountns permission that can be applied to
> nsfs files (/proc/$$/ns/mnt), making it possible to allow or deny watching
> a particular namespace for changes.
> 
> [...]

Applied to the vfs-6.15.mount branch of the vfs/vfs.git tree.
Patches in the vfs-6.15.mount branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.15.mount

[1/1] selinux: add FILE__WATCH_MOUNTNS
      https://git.kernel.org/vfs/vfs/c/7d90fb525319
Stephen Smalley Feb. 27, 2025, 3:22 p.m. UTC | #3
On Wed, Feb 26, 2025 at 3:19 PM Paul Moore <paul@paul-moore.com> wrote:
>
> On Feb 24, 2025 Miklos Szeredi <mszeredi@redhat.com> wrote:
> >
> > Watching mount namespaces for changes (mount, umount, move mount) was added
> > by previous patches.
> >
> > This patch adds the file/watch_mountns permission that can be applied to
> > nsfs files (/proc/$$/ns/mnt), making it possible to allow or deny watching
> > a particular namespace for changes.
> >
> > Suggested-by: Paul Moore <paul@paul-moore.com>
> > Link: https://lore.kernel.org/all/CAHC9VhTOmCjCSE2H0zwPOmpFopheexVb6jyovz92ZtpKtoVv6A@mail.gmail.com/
> > Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> > ---
> >  security/selinux/hooks.c            | 3 +++
> >  security/selinux/include/classmap.h | 2 +-
> >  2 files changed, 4 insertions(+), 1 deletion(-)
>
> Thanks Miklos, this looks good to me.  VFS folks / Christian, can you
> merge this into the associated FSNOTIFY_OBJ_TYPE_MNTNS branch you are
> targeting for linux-next?
>
> Acked-by: Paul Moore <paul@paul-moore.com>

I'm not objecting to this patch, but just for awareness, this adds the
permission for all file-related classes, including dir(ectory), and we
are almost out of space in the access vector at which point we'll need
to introduce a file2 class or similar (as with process2).
Paul Moore Feb. 27, 2025, 4:48 p.m. UTC | #4
On Thu, Feb 27, 2025 at 10:22 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
> On Wed, Feb 26, 2025 at 3:19 PM Paul Moore <paul@paul-moore.com> wrote:
> > On Feb 24, 2025 Miklos Szeredi <mszeredi@redhat.com> wrote:
> > >
> > > Watching mount namespaces for changes (mount, umount, move mount) was added
> > > by previous patches.
> > >
> > > This patch adds the file/watch_mountns permission that can be applied to
> > > nsfs files (/proc/$$/ns/mnt), making it possible to allow or deny watching
> > > a particular namespace for changes.
> > >
> > > Suggested-by: Paul Moore <paul@paul-moore.com>
> > > Link: https://lore.kernel.org/all/CAHC9VhTOmCjCSE2H0zwPOmpFopheexVb6jyovz92ZtpKtoVv6A@mail.gmail.com/
> > > Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> > > ---
> > >  security/selinux/hooks.c            | 3 +++
> > >  security/selinux/include/classmap.h | 2 +-
> > >  2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > Thanks Miklos, this looks good to me.  VFS folks / Christian, can you
> > merge this into the associated FSNOTIFY_OBJ_TYPE_MNTNS branch you are
> > targeting for linux-next?
> >
> > Acked-by: Paul Moore <paul@paul-moore.com>
>
> I'm not objecting to this patch, but just for awareness, this adds the
> permission for all file-related classes, including dir(ectory), and we
> are almost out of space in the access vector at which point we'll need
> to introduce a file2 class or similar (as with process2).

Yes, I've been paying closer attention to this over the past several
years as we start to nudge the permission count limits.  However, as
you mentioned, this isn't a new concern and we've successfully dealt
with it in the past.
diff mbox series

Patch

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 7b867dfec88b..212cdead2b52 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3395,6 +3395,9 @@  static int selinux_path_notify(const struct path *path, u64 mask,
 	case FSNOTIFY_OBJ_TYPE_INODE:
 		perm = FILE__WATCH;
 		break;
+	case FSNOTIFY_OBJ_TYPE_MNTNS:
+		perm = FILE__WATCH_MOUNTNS;
+		break;
 	default:
 		return -EINVAL;
 	}
diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h
index 03e82477dce9..f9b5ca92a825 100644
--- a/security/selinux/include/classmap.h
+++ b/security/selinux/include/classmap.h
@@ -8,7 +8,7 @@ 
 	COMMON_FILE_SOCK_PERMS, "unlink", "link", "rename", "execute",   \
 		"quotaon", "mounton", "audit_access", "open", "execmod", \
 		"watch", "watch_mount", "watch_sb", "watch_with_perm",   \
-		"watch_reads"
+		"watch_reads", "watch_mountns"
 
 #define COMMON_SOCK_PERMS                                              \
 	COMMON_FILE_SOCK_PERMS, "bind", "connect", "listen", "accept", \