Quellcode durchsuchen

selinux: add a map permission check for mmap

Add a map permission check on mmap so that we can distinguish memory mapped
access (since it has different implications for revocation). When a file
is opened and then read or written via syscalls like read(2)/write(2),
we revalidate access on each read/write operation via
selinux_file_permission() and therefore can revoke access if the
process context, the file context, or the policy changes in such a
manner that access is no longer allowed. When a file is opened and then
memory mapped via mmap(2) and then subsequently read or written directly
in memory, we presently have no way to revalidate or revoke access.
The purpose of a separate map permission check on mmap(2) is to permit
policy to prohibit memory mapping of specific files for which we need
to ensure that every access is revalidated, particularly useful for
scenarios where we expect the file to be relabeled at runtime in order
to reflect state changes (e.g. cross-domain solution, assured pipeline
without data copying).

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Stephen Smalley vor 8 Jahren
Ursprung
Commit
3ba4bf5f1e
2 geänderte Dateien mit 13 neuen und 1 gelöschten Zeilen
  1. 12 0
      security/selinux/hooks.c
  2. 1 1
      security/selinux/include/classmap.h

+ 12 - 0
security/selinux/hooks.c

@@ -3557,6 +3557,18 @@ static int selinux_mmap_addr(unsigned long addr)
 static int selinux_mmap_file(struct file *file, unsigned long reqprot,
 static int selinux_mmap_file(struct file *file, unsigned long reqprot,
 			     unsigned long prot, unsigned long flags)
 			     unsigned long prot, unsigned long flags)
 {
 {
+	struct common_audit_data ad;
+	int rc;
+
+	if (file) {
+		ad.type = LSM_AUDIT_DATA_FILE;
+		ad.u.file = file;
+		rc = inode_has_perm(current_cred(), file_inode(file),
+				    FILE__MAP, &ad);
+		if (rc)
+			return rc;
+	}
+
 	if (selinux_checkreqprot)
 	if (selinux_checkreqprot)
 		prot = reqprot;
 		prot = reqprot;
 
 

+ 1 - 1
security/selinux/include/classmap.h

@@ -1,7 +1,7 @@
 #include <linux/capability.h>
 #include <linux/capability.h>
 
 
 #define COMMON_FILE_SOCK_PERMS "ioctl", "read", "write", "create", \
 #define COMMON_FILE_SOCK_PERMS "ioctl", "read", "write", "create", \
-    "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append"
+    "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append", "map"
 
 
 #define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \
 #define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \
     "rename", "execute", "quotaon", "mounton", "audit_access", \
     "rename", "execute", "quotaon", "mounton", "audit_access", \