All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selinux: reject writable opens of status file, drop mmap write checks
@ 2026-09-11 13:51 Stephen Smalley
  2026-09-11 14:09 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Smalley @ 2026-09-11 13:51 UTC (permalink / raw)
  To: selinux
  Cc: paul, omosnacek, Stephen Smalley, ljs, jannh, jack, cgzones,
	brauner

Similar to what
https://lore.kernel.org/selinux/aqPUqU3eZeFrykj3@gremlin/ does for the
policy file, update the .open handler for the status file to reject
writable opens, and update the .mmap handler to stop clearing
VM_MAYWRITE and checking for VM_WRITE. As a side effect, I believe
this will also prevent the issue previously reported with libselinux
users like systemd seg-faulting on the mmap'd status file if it is
truncated.

Link: https://lore.kernel.org/selinux/aqPUqU3eZeFrykj3@gremlin/
Link: https://lore.kernel.org/selinux/CAJ2a_Df6GOirF8TnNWTqNMpdWLHgjT9_v7G-PiL4e7LU2nr1PA@mail.gmail.com/
cc: ljs@kernel.org
cc: jannh@google.com
cc: jack@suse.cz
cc: cgzones@googlemail.com
cc: brauner@kernel.org
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
---
 security/selinux/selinuxfs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 292302eb60f3..3657778de82d 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -219,6 +219,9 @@ static int sel_open_handle_status(struct inode *inode, struct file *filp)
 	if (!status)
 		return -ENOMEM;
 
+	if (filp->f_mode & FMODE_WRITE)
+		return -EACCES;
+
 	filp->private_data = status;
 
 	return 0;
@@ -247,11 +250,6 @@ static int sel_mmap_handle_status(struct file *filp,
 	/* only allows one page from the head */
 	if (vma->vm_pgoff > 0 || size != PAGE_SIZE)
 		return -EIO;
-	/* disallow writable mapping */
-	if (vma->vm_flags & VM_WRITE)
-		return -EPERM;
-	/* disallow mprotect() turns it into writable */
-	vm_flags_clear(vma, VM_MAYWRITE);
 
 	return remap_pfn_range(vma, vma->vm_start,
 			       page_to_pfn(status),
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-11 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 13:51 [PATCH] selinux: reject writable opens of status file, drop mmap write checks Stephen Smalley
2026-09-11 14:09 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.