vfs: re-introduce MAY_CHDIR
Subsystems (6)
PATCH 1/5 vfs: re-introduce MAY_CHDIR
Currently MAY_ACCESS means that filesystems must check the permissions right then and not rely on cached results or the results of future operations on the object. This can be because of a call to sys_access() or because of a call to chdir() which needs to check search without relying on any future operations inside that dir. I plan to use MAY_ACCESS for other purposes in the security system, so I split the MAY_ACCESS and the MAY_CHDIR cases.
---
fs/fuse/dir.c | 2 +- fs/nfs/dir.c | 2 +- fs/open.c | 6 +++--- include/linux/fs.h | 1 + 4 files changed, 6 insertions(+), 5 deletions(-)
fs/fuse/dir.c +1 -1
@@ -1016,7 +1016,7 @@ static int fuse_permission(struct inode *inode, int mask)exist. So if permissions are revoked this won't be noticed immediately, only after the attribute timeout has expired */ - }else if (mask &MAY_ACCESS ) { + }else if (mask & (MAY_ACCESS |MAY_CHDIR )) { err =fuse_access (inode, mask); }else if ((mask &MAY_EXEC ) &&S_ISREG (inode->i_mode)) {if (!(inode->i_mode &S_IXUGO )) {
fs/nfs/dir.c +1 -1
@@ -1953,7 +1953,7 @@ int nfs_permission(struct inode *inode, int mask)if ((mask & (MAY_READ |MAY_WRITE |MAY_EXEC )) ==0 ) goto out;/* Is this sys_access() ? */ -if (mask &MAY_ACCESS ) +if (mask & (MAY_ACCESS |MAY_CHDIR )) goto force_lookup;switch (inode->i_mode &S_IFMT ) {
fs/open.c +3 -3
@@ -367,7 +367,7 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)if (error) goto out; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_ACCESS ); + error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR );if (error) goto dput_and_out;
@@ -396,7 +396,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)if (!S_ISDIR (inode->i_mode)) goto out_putf; - error =inode_permission (inode,MAY_EXEC |MAY_ACCESS ); + error =inode_permission (inode,MAY_EXEC |MAY_CHDIR );if (!error)set_fs_pwd (current->fs, &file->f_path); out_putf:
@@ -414,7 +414,7 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)if (error) goto out; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_ACCESS ); + error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR );if (error) goto dput_and_out;
include/linux/fs.h +1 -0
@@ -53,6 +53,7 @@ struct inodes_stat_t {#define MAY_APPEND 8#define MAY_ACCESS 16#define MAY_OPEN 32 +#define MAY_CHDIR 64/* * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/5 security: make LSMs explicitly mask off permissions
SELinux needs to pass the MAY_ACCESS flag so it can handle auditting correctly. Presently the masking of MAY_* flags is done in the VFS. In order to allow LSMs to decide what flags they care about and what flags they don't just pass them all and the each LSM mask off what they don't need. This patch should contain no functional changes to either the VFS or any LSM.
---
fs/namei.c | 3 +-- security/selinux/hooks.c | 2 ++ security/smack/smack_lsm.c | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-)
fs/namei.c +1 -2
@@ -282,8 +282,7 @@ int inode_permission(struct inode *inode, int mask)if (retval)return retval; -return security_inode_permission (inode, - mask & (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND )); +return security_inode_permission (inode, mask); }/**
security/selinux/hooks.c +2 -0
@@ -2648,6 +2648,8 @@ static int selinux_inode_permission(struct inode *inode, int mask) {const struct cred *cred =current_cred (); + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND ); +if (!mask) {/* No permission to check. Existence test. */ return 0 ;
security/smack/smack_lsm.c +2 -0
@@ -598,6 +598,8 @@ static int smack_inode_rename(struct inode *old_inode,static int smack_inode_permission (struct inode *inode,int mask) {struct smk_audit_info ad; + + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND );/* * No permission to check. Existence test. Yup, it's there. */
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 3/5 SELinux: special dontaudit for access checks
In reply to Eric ParisCurrently there are a number of applications (nautilus being the main one) which calls access() on files in order to determine how they should be displayed. It is normal and expected that nautilus will want to see if files are executable or if they are really read/write-able. access() should return the real permission. SELinux policy checks are done in access() and can result in lots of AVC denials as policy denies RWX on files which DAC allows. Currently SELinux must dontaudit actual attempts to read/write/execute a file in order to silence these messages (and not flood the logs.) But dontaudit rules like that can hide real attacks. This patch addes a new common file permission audit_access. This permission is special in that it is meaningless and should never show up in an allow rule. Instead the only place this permission has meaning is in a dontaudit rule like so:
dontaudit nautilus_t sbin_t:file audit_access
With such a rule if nautilus just checks access() we will still get denied and thus userspace will still get the correct answer but we will not log the denial. If nautilus attempted to actually perform one of the forbidden actions (rather than just querying access(2) about it) we would still log a denial. This type of dontaudit rule should be used sparingly, as it could be a method for an attacker to probe the system permissions without detection.
---
include/linux/lsm_audit.h | 5 +++++ security/selinux/avc.c | 24 ++++++++++++++++++++++-- security/selinux/hooks.c | 20 +++++++++++++++----- security/selinux/include/classmap.h | 2 +- 4 files changed, 43 insertions(+), 8 deletions(-)
include/linux/lsm_audit.h +5 -0
@@ -90,6 +90,11 @@ struct common_audit_data {u32 requested;u32 audited;u32 denied; +/* +* auditdeny is a bit tricky and unintuitive. See the +* comments in avc.c for it's meaning and usage. +*/ +u32 auditdeny;struct av_decision *avd;int result; } selinux_audit_data;
security/selinux/avc.c +22 -2
@@ -488,9 +488,29 @@ void avc_audit(u32 ssid, u32 tsid,struct common_audit_data stack_data;u32 denied, audited; denied = requested & ~avd->allowed; -if (denied) +if (denied) { audited = denied & avd->auditdeny; -else if (result) +/* +* a->selinux_audit_data.auditdeny is TRICKY! Setting a bit in +* this field means that ANY denials should NOT be audited if +* the policy contains an explicit dontaudit rule for that +* permission. Take notice that this is unrelated to the +* actual permissions that were denied. As an example lets +* assume: +* +* denied == READ +* avd.auditdeny & ACCESS == 0 (not set means explicit rule) +* selinux_audit_data.auditdeny & ACCESS == 1 +* +* We will NOT audit the denial even though the denied +* permission was READ and the auditdeny checks were for +* ACCESS +*/ +if (a && + a->selinux_audit_data.auditdeny && + !(a->selinux_audit_data.auditdeny & avd->auditdeny)) + audited =0 ; + }else if (result) audited = denied = requested;else audited = requested & avd->auditallow;
security/selinux/hooks.c +15 -5
@@ -2647,16 +2647,26 @@ static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *nastatic int selinux_inode_permission (struct inode *inode,int mask) {const struct cred *cred =current_cred (); +struct common_audit_data ad; +u32 perms; +bool from_access; + from_access = mask &MAY_ACCESS ; mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND ); -if (!mask) { -/* No permission to check. Existence test. */ +/* No permission to check. Existence test. */ +if (!mask)return 0 ; - } -return inode_has_perm (cred, inode, -file_mask_to_av (inode->i_mode, mask),NULL ); +COMMON_AUDIT_DATA_INIT (&ad,FS ); + ad.u.fs.inode = inode; + +if (from_access) + ad.selinux_audit_data.auditdeny |=FILE__AUDIT_ACCESS ; + + perms =file_mask_to_av (inode->i_mode, mask); + +return inode_has_perm (cred, inode, perms, &ad); }static int selinux_inode_setattr (struct dentry *dentry,struct iattr *iattr)
security/selinux/include/classmap.h +1 -1
@@ -2,7 +2,7 @@ "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append"#define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \ - "rename", "execute", "swapon", "quotaon", "mounton" + "rename", "execute", "swapon", "quotaon", "mounton", "audit_access"#define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \ "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom", \
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 4/5 selinux: place open in the common file perms
In reply to Eric Pariskernel can dynamically remap perms. Drop the open lookup table and put open in the common file perms.
---
security/selinux/hooks.c | 24 +++--------------------- security/selinux/include/classmap.h | 15 ++++++++------- 2 files changed, 11 insertions(+), 28 deletions(-)
security/selinux/hooks.c +3 -21
@@ -1776,27 +1776,9 @@ static inline u32 open_file_to_av(struct file *file) {u32 av =file_to_av (file); -if (selinux_policycap_openperm) { -mode_t mode = file->f_path.dentry->d_inode->i_mode; -/* -* lnk files and socks do not really have an 'open' -*/ -if (S_ISREG (mode)) - av |=FILE__OPEN ; -else if (S_ISCHR (mode)) - av |=CHR_FILE__OPEN ; -else if (S_ISBLK (mode)) - av |=BLK_FILE__OPEN ; -else if (S_ISFIFO (mode)) - av |=FIFO_FILE__OPEN ; -else if (S_ISDIR (mode)) - av |=DIR__OPEN ; -else if (S_ISSOCK (mode)) - av |=SOCK_FILE__OPEN ; -else -printk (KERN_ERR "SELinux: WARNING: inside %s with " -"unknown mode:%o\n" , __func__, mode); - } +if (selinux_policycap_openperm) + av |=FILE__OPEN ; +return av; }
security/selinux/include/classmap.h +8 -7
@@ -2,7 +2,8 @@ "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append"#define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \ - "rename", "execute", "swapon", "quotaon", "mounton", "audit_access" + "rename", "execute", "swapon", "quotaon", "mounton", "audit_access", \ + "open"#define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \ "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom", \
@@ -43,22 +44,22 @@ struct security_class_mapping secclass_map[] = { "quotaget", NULL } }, {"file" , { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", "open", NULL } }, + "execute_no_trans", "entrypoint", "execmod", NULL } }, {"dir" , { COMMON_FILE_PERMS, "add_name", "remove_name", - "reparent", "search", "rmdir", "open", NULL } }, + "reparent", "search", "rmdir", NULL } }, { "fd", { "use", NULL } }, { "lnk_file", { COMMON_FILE_PERMS, NULL } }, { "chr_file", { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", "open", NULL } }, + "execute_no_trans", "entrypoint", "execmod", NULL } }, { "blk_file", - { COMMON_FILE_PERMS, "open", NULL } }, + { COMMON_FILE_PERMS, NULL } }, { "sock_file", - { COMMON_FILE_PERMS, "open", NULL } }, + { COMMON_FILE_PERMS, NULL } }, { "fifo_file", - { COMMON_FILE_PERMS, "open", NULL } }, + { COMMON_FILE_PERMS, NULL } }, { "socket", { COMMON_SOCK_PERMS, NULL } }, { "tcp_socket",
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 5/5 SELinux: Move execmod to the common perms
In reply to Eric Parisexecmod "could" show up on non regular files and non chr files. The current implementation would actually make these checks against non-existant bits since the code assumes the execmod permission is same for all file types. To make this line up for chr files we had to define execute_no_trans and entrypoint permissions. These permissions are unreachable and only existed to to make FILE__EXECMOD and CHR_FILE__EXECMOD the same. This patch drops those needless perms as well.
---
security/selinux/include/classmap.h | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
security/selinux/include/classmap.h +3 -4
@@ -3,7 +3,7 @@#define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \ "rename", "execute", "swapon", "quotaon", "mounton", "audit_access", \ - "open" + "open", "execmod"#define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \ "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom", \
@@ -44,7 +44,7 @@ struct security_class_mapping secclass_map[] = { "quotaget", NULL } }, {"file" , { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", NULL } }, + "execute_no_trans", "entrypoint", NULL } }, {"dir" , { COMMON_FILE_PERMS, "add_name", "remove_name", "reparent", "search", "rmdir", NULL } },
@@ -52,8 +52,7 @@ struct security_class_mapping secclass_map[] = { {"lnk_file" , { COMMON_FILE_PERMS, NULL } }, {"chr_file" , - { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", NULL } }, + { COMMON_FILE_PERMS, NULL } }, { "blk_file", { COMMON_FILE_PERMS, NULL } }, { "sock_file",
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 2/5] security: make LSMs explicitly mask off permissions
In reply to Eric ParisQuoted 8 lines · Eric Paris
SELinux needs to pass the
MAY_ACCESSflag so it can handle auditting correctly. Presently the masking of MAY_* flags is done in the VFS. In order to allow LSMs to decide what flags they care about and what flags they don't just pass them all and the each LSM mask off what they don't need. This patch should contain no functional changes to either the VFS or any LSM.Signed-off-by Eric Paris <[email protected]>
Quoted 47 lines
---
fs/namei.c | 3 +-- security/selinux/hooks.c | 2 ++ security/smack/smack_lsm.c | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-)fs/namei.c +1
-2@@ -282,8 +282,7 @@ int inode_permission(struct inode *inode, int mask)if (retval)return retval; -return security_inode_permission (inode, - mask & (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND )); +return security_inode_permission (inode, mask); }/** security/selinux/hooks.c +2
-0@@ -2648,6 +2648,8 @@ static int selinux_inode_permission(struct inode *inode, int mask) {const struct cred *cred =current_cred (); + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND ); +if (!mask) {/* No permission to check. Existence test. */ return 0 ;security/smack/smack_lsm.c +2
-0@@ -598,6 +598,8 @@ static int smack_inode_rename(struct inode *old_inode,static int smack_inode_permission (struct inode *inode,int mask) {struct smk_audit_info ad; + + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND );/* * No permission to check. Existence test. Yup, it's there. */
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 5/5] SELinux: Move execmod to the common perms
In reply to Eric ParisQuoted 9 lines · Eric Paris
execmod "could" show up on non regular files and non chr files. The current implementation would actually make these checks against non-existant bits since the code assumes the execmod permission is same for all file types. To make this line up for chr files we had to define
execute_no_transand entrypoint permissions. These permissions are unreachable and only existed to to makeFILE__EXECMODandCHR_FILE__EXECMODthe same. This patch drops those needless perms as well.Signed-off-by Eric Paris <[email protected]>
for the entire series. Although I think I already did that before.
Quoted 37 lines
---
security/selinux/include/classmap.h | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)security/selinux/include/classmap.h +3
-4@@ -3,7 +3,7 @@#define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \ "rename", "execute", "swapon", "quotaon", "mounton", "audit_access", \ - "open" + "open", "execmod"#define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \ "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom", \@@ -44,7 +44,7 @@ struct security_class_mapping secclass_map[] = { "quotaget", NULL } }, {"file" , { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", NULL } }, + "execute_no_trans", "entrypoint", NULL } }, {"dir" , { COMMON_FILE_PERMS, "add_name", "remove_name", "reparent", "search", "rmdir", NULL } },@@ -52,8 +52,7 @@ struct security_class_mapping secclass_map[] = { {"lnk_file" , { COMMON_FILE_PERMS, NULL } }, {"chr_file" , - { COMMON_FILE_PERMS, - "execute_no_trans", "entrypoint", "execmod", NULL } }, + { COMMON_FILE_PERMS, NULL } }, { "blk_file", { COMMON_FILE_PERMS, NULL } }, { "sock_file",
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
James Morris
maintainerRe: [PATCH 5/5] SELinux: Move execmod to the common perms
Quoted 9 lines · Stephen Smalley
Quoted 8 lines · Eric Paris
execmod "could" show up on non regular files and non chr files. The current implementation would actually make these checks against non-existant bits since the code assumes the execmod permission is same for all file types. To make this line up for chr files we had to define
execute_no_transand entrypoint permissions. These permissions are unreachable and only existed to to makeFILE__EXECMODandCHR_FILE__EXECMODthe same. This patch drops those needless perms as well.
Quoted 4 lines
Quoted 1 line
Signed-off-by Eric Paris <[email protected]>for the entire series. Although I think I already did that before.
Thanks, all applied.
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 2/5] security: make LSMs explicitly mask off permissions
In reply to Eric ParisQuoted 9 lines · Eric Paris
SELinux needs to pass the
MAY_ACCESSflag so it can handle auditting correctly. Presently the masking of MAY_* flags is done in the VFS. In order to allow LSMs to decide what flags they care about and what flags they don't just pass them all and the each LSM mask off what they don't need. This patch should contain no functional changes to either the VFS or any LSM.Signed-off-by Eric Paris <[email protected]>
I hate to introduce this much instability, but if you can't trust Eric, who can yo trust?
Quoted 50 lines
---
fs/namei.c | 3 +-- security/selinux/hooks.c | 2 ++ security/smack/smack_lsm.c | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-)fs/namei.c +1
-2@@ -282,8 +282,7 @@ int inode_permission(struct inode *inode, int mask)if (retval)return retval; -return security_inode_permission (inode, - mask & (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND )); +return security_inode_permission (inode, mask); }/** security/selinux/hooks.c +2
-0@@ -2648,6 +2648,8 @@ static int selinux_inode_permission(struct inode *inode, int mask) {const struct cred *cred =current_cred (); + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND ); +if (!mask) {/* No permission to check. Existence test. */ return 0 ;security/smack/smack_lsm.c +2
-1@@ -598,6 +598,8 @@ static int smack_inode_rename(struct inode *old_inode,static int smack_inode_permission (struct inode *inode,int mask) {struct smk_audit_info ad; + + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC |MAY_APPEND );/* * No permission to check. Existence test. Yup, it's there. */ --
Quoted 6 lines
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.