userfaultfd: open userfaultfds with O_RDONLY
Subsystems (4)
RFC PATCH 1/1 userfaultfd: open userfaultfds with O_RDONLY
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559
---
Resending as the last submission was ignored for over a year...
https://lore.kernel.org/lkml/[email protected]/T/
I marked this as RFC, because I'm not sure if this has any unwanted side effects. I only ran this patch through selinux-testsuite, which has a simple userfaultfd subtest, and a reproducer from the Bugzilla report.
Please tell me whether this makes sense and/or if it passes any userfaultfd tests you guys might have.
fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/userfaultfd.c +2 -2
@@ -989,7 +989,7 @@ static int resolve_userfault_fork(struct userfaultfd_ctx *new,int fd; fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, new, -O_RDWR | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode); +O_RDONLY | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode);if (fd <0 )return fd;
@@ -2090,7 +2090,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)mmgrab (ctx->mm); fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, ctx, -O_RDWR | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL ); +O_RDONLY | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL );if (fd <0 ) {mmdrop (ctx->mm);kmem_cache_free (userfaultfd_ctx_cachep, ctx);
Signature · 1 line
2.36.1
Quoted 8 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Quoted 7 lines
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>
Signature · 1 line
Peter Xu
Paul Moore
maintainerQuoted 13 lines · Peter Xu
Quoted 12 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559
Quoted 5 lines
Quoted 3 lines
Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>Acked-by Peter Xu <[email protected]>
Thanks Peter.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 26 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>---
Resending as the last submission was ignored for over a year...
https://lore.kernel.org/lkml/[email protected]/T/
I marked this as RFC, because I'm not sure if this has any unwanted side effects. I only ran this patch through selinux-testsuite, which has a simple userfaultfd subtest, and a reproducer from the Bugzilla report.
Quoted 5 lines
Please tell me whether this makes sense and/or if it passes any userfaultfd tests you guys might have.
fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
VFS folks, any objection to this patch? It seems reasonable to me and I'd really prefer this to go in via the vfs tree, but I'm not above merging this via the lsm/next tree to get someone in vfs land to pay attention to this ...
Quoted 24 lines
fs/userfaultfd.c +2
-3@@ -989,7 +989,7 @@ static int resolve_userfault_fork(struct userfaultfd_ctx *new,int fd; fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, new, -O_RDWR | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode); +O_RDONLY | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode);if (fd <0 )return fd;@@ -2090,7 +2090,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)mmgrab (ctx->mm); fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, ctx, -O_RDWR | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL ); +O_RDONLY | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL );if (fd <0 ) {mmdrop (ctx->mm);kmem_cache_free (userfaultfd_ctx_cachep, ctx); --2.36.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 30 lines · Paul Moore
Quoted 29 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>---
Resending as the last submission was ignored for over a year...
https://lore.kernel.org/lkml/[email protected]/T/
I marked this as RFC, because I'm not sure if this has any unwanted side effects. I only ran this patch through selinux-testsuite, which has a simple userfaultfd subtest, and a reproducer from the Bugzilla report.
Please tell me whether this makes sense and/or if it passes any userfaultfd tests you guys might have.
Quoted 7 lines
Quoted 2 lines
fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)VFS folks, any objection to this patch? It seems reasonable to me and I'd really prefer this to go in via the vfs tree, but I'm not above merging this via the lsm/next tree to get someone in vfs land to pay attention to this ...
Okay, final warning, if I don't see any objections to this when I make my patch sweep next week I'm going to go ahead and merge this via the LSM tree.
Quoted 27 lines
Quoted 23 lines
fs/userfaultfd.c +2
-3@@ -989,7 +989,7 @@ static int resolve_userfault_fork(struct userfaultfd_ctx *new,int fd; fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, new, -O_RDWR | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode); +O_RDONLY | (new->flags &UFFD_SHARED_FCNTL_FLAGS ), inode);if (fd <0 )return fd;@@ -2090,7 +2090,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)mmgrab (ctx->mm); fd =anon_inode_getfd_secure ("[userfaultfd]" , &userfaultfd_fops, ctx, -O_RDWR | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL ); +O_RDONLY | (flags &UFFD_SHARED_FCNTL_FLAGS ),NULL );if (fd <0 ) {mmdrop (ctx->mm);kmem_cache_free (userfaultfd_ctx_cachep, ctx); --Quoted 1 line
2.36.1
--
paul-moore.com
Signature · 1 line
paul-moore.com
Quoted 34 lines · Paul Moore
Quoted 33 lines · Paul Moore
Quoted 31 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>---
Resending as the last submission was ignored for over a year...
https://lore.kernel.org/lkml/[email protected]/T/
I marked this as RFC, because I'm not sure if this has any unwanted side effects. I only ran this patch through selinux-testsuite, which has a simple userfaultfd subtest, and a reproducer from the Bugzilla report.
Please tell me whether this makes sense and/or if it passes any userfaultfd tests you guys might have.
fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 4 lines
VFS folks, any objection to this patch? It seems reasonable to me and I'd really prefer this to go in via the vfs tree, but I'm not above merging this via the lsm/next tree to get someone in vfs land to pay attention to this ...
Okay, final warning, if I don't see any objections to this when I make my patch sweep next week I'm going to go ahead and merge this via the LSM tree.
Makes sense,
Quoted 40 lines · Christian Brauner
Quoted 39 lines · Paul Moore
Quoted 37 lines · Paul Moore
Quoted 26 lines · Ondrej Mosnacek
Since userfaultfd doesn't implement a write operation, it is more appropriate to open it read-only.
When userfaultfds are opened read-write like it is now, and such fd is passed from one process to another, SELinux will check both read and write permissions for the target process, even though it can't actually do any write operation on the fd later.
Inspired by the following bug report, which has hit the SELinux scenario described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559Reported-by Robert O'Callahan <[email protected]>Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Ondrej Mosnacek <[email protected]>---
Resending as the last submission was ignored for over a year...
https://lore.kernel.org/lkml/[email protected]/T/
I marked this as RFC, because I'm not sure if this has any unwanted side effects. I only ran this patch through selinux-testsuite, which has a simple userfaultfd subtest, and a reproducer from the Bugzilla report.
Quoted 5 lines
Please tell me whether this makes sense and/or if it passes any userfaultfd tests you guys might have.
fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)VFS folks, any objection to this patch? It seems reasonable to me and I'd really prefer this to go in via the vfs tree, but I'm not above merging this via the lsm/next tree to get someone in vfs land to pay attention to this ...
Quoted 6 lines
Quoted 3 lines
Okay, final warning, if I don't see any objections to this when I make my patch sweep next week I'm going to go ahead and merge this via the LSM tree.
Makes sense,
Merged into lsm/next, thanks all.
Signature · 1 line
paul-moore.com