diff options
author | Eric Paris <eparis@redhat.com> | 2011-04-25 12:54:27 -0400 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2011-04-25 18:13:15 -0400 |
commit | f48b7399840b453e7282b523f535561fe9638a2d (patch) | |
tree | 29eed009469d35473367708ea60b9c5b01fc0c5f /security/selinux | |
parent | 0dc1ba24f7fff659725eecbba2c9ad679a0954cd (diff) |
LSM: split LSM_AUDIT_DATA_FS into _PATH and _INODE
The lsm common audit code has wacky contortions making sure which pieces
of information are set based on if it was given a path, dentry, or
inode. Split this into path and inode to get rid of some of the code
complexity.
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/avc.c | 2 | ||||
-rw-r--r-- | security/selinux/hooks.c | 50 |
2 files changed, 26 insertions, 26 deletions
diff --git a/security/selinux/avc.c b/security/selinux/avc.c index 1d027e29ce8d..ce742f1778e1 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c | |||
@@ -531,7 +531,7 @@ int avc_audit(u32 ssid, u32 tsid, | |||
531 | * during retry. However this is logically just as if the operation | 531 | * during retry. However this is logically just as if the operation |
532 | * happened a little later. | 532 | * happened a little later. |
533 | */ | 533 | */ |
534 | if ((a->type == LSM_AUDIT_DATA_FS) && | 534 | if ((a->type == LSM_AUDIT_DATA_INODE) && |
535 | (flags & IPERM_FLAG_RCU)) | 535 | (flags & IPERM_FLAG_RCU)) |
536 | return -ECHILD; | 536 | return -ECHILD; |
537 | 537 | ||
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index ed5f29aa0a38..ad664d3056eb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -1488,8 +1488,8 @@ static int inode_has_perm(const struct cred *cred, | |||
1488 | 1488 | ||
1489 | if (!adp) { | 1489 | if (!adp) { |
1490 | adp = &ad; | 1490 | adp = &ad; |
1491 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1491 | COMMON_AUDIT_DATA_INIT(&ad, INODE); |
1492 | ad.u.fs.inode = inode; | 1492 | ad.u.inode = inode; |
1493 | } | 1493 | } |
1494 | 1494 | ||
1495 | return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags); | 1495 | return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags); |
@@ -1506,9 +1506,9 @@ static inline int dentry_has_perm(const struct cred *cred, | |||
1506 | struct inode *inode = dentry->d_inode; | 1506 | struct inode *inode = dentry->d_inode; |
1507 | struct common_audit_data ad; | 1507 | struct common_audit_data ad; |
1508 | 1508 | ||
1509 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1509 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1510 | ad.u.fs.path.mnt = mnt; | 1510 | ad.u.path.mnt = mnt; |
1511 | ad.u.fs.path.dentry = dentry; | 1511 | ad.u.path.dentry = dentry; |
1512 | return inode_has_perm(cred, inode, av, &ad, 0); | 1512 | return inode_has_perm(cred, inode, av, &ad, 0); |
1513 | } | 1513 | } |
1514 | 1514 | ||
@@ -1530,8 +1530,8 @@ static int file_has_perm(const struct cred *cred, | |||
1530 | u32 sid = cred_sid(cred); | 1530 | u32 sid = cred_sid(cred); |
1531 | int rc; | 1531 | int rc; |
1532 | 1532 | ||
1533 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1533 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1534 | ad.u.fs.path = file->f_path; | 1534 | ad.u.path = file->f_path; |
1535 | 1535 | ||
1536 | if (sid != fsec->sid) { | 1536 | if (sid != fsec->sid) { |
1537 | rc = avc_has_perm(sid, fsec->sid, | 1537 | rc = avc_has_perm(sid, fsec->sid, |
@@ -1569,8 +1569,8 @@ static int may_create(struct inode *dir, | |||
1569 | sid = tsec->sid; | 1569 | sid = tsec->sid; |
1570 | newsid = tsec->create_sid; | 1570 | newsid = tsec->create_sid; |
1571 | 1571 | ||
1572 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1572 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1573 | ad.u.fs.path.dentry = dentry; | 1573 | ad.u.path.dentry = dentry; |
1574 | 1574 | ||
1575 | rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, | 1575 | rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, |
1576 | DIR__ADD_NAME | DIR__SEARCH, | 1576 | DIR__ADD_NAME | DIR__SEARCH, |
@@ -1621,8 +1621,8 @@ static int may_link(struct inode *dir, | |||
1621 | dsec = dir->i_security; | 1621 | dsec = dir->i_security; |
1622 | isec = dentry->d_inode->i_security; | 1622 | isec = dentry->d_inode->i_security; |
1623 | 1623 | ||
1624 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1624 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1625 | ad.u.fs.path.dentry = dentry; | 1625 | ad.u.path.dentry = dentry; |
1626 | 1626 | ||
1627 | av = DIR__SEARCH; | 1627 | av = DIR__SEARCH; |
1628 | av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); | 1628 | av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); |
@@ -1667,9 +1667,9 @@ static inline int may_rename(struct inode *old_dir, | |||
1667 | old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode); | 1667 | old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode); |
1668 | new_dsec = new_dir->i_security; | 1668 | new_dsec = new_dir->i_security; |
1669 | 1669 | ||
1670 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1670 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1671 | 1671 | ||
1672 | ad.u.fs.path.dentry = old_dentry; | 1672 | ad.u.path.dentry = old_dentry; |
1673 | rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, | 1673 | rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, |
1674 | DIR__REMOVE_NAME | DIR__SEARCH, &ad); | 1674 | DIR__REMOVE_NAME | DIR__SEARCH, &ad); |
1675 | if (rc) | 1675 | if (rc) |
@@ -1685,7 +1685,7 @@ static inline int may_rename(struct inode *old_dir, | |||
1685 | return rc; | 1685 | return rc; |
1686 | } | 1686 | } |
1687 | 1687 | ||
1688 | ad.u.fs.path.dentry = new_dentry; | 1688 | ad.u.path.dentry = new_dentry; |
1689 | av = DIR__ADD_NAME | DIR__SEARCH; | 1689 | av = DIR__ADD_NAME | DIR__SEARCH; |
1690 | if (new_dentry->d_inode) | 1690 | if (new_dentry->d_inode) |
1691 | av |= DIR__REMOVE_NAME; | 1691 | av |= DIR__REMOVE_NAME; |
@@ -1991,8 +1991,8 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) | |||
1991 | return rc; | 1991 | return rc; |
1992 | } | 1992 | } |
1993 | 1993 | ||
1994 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 1994 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
1995 | ad.u.fs.path = bprm->file->f_path; | 1995 | ad.u.path = bprm->file->f_path; |
1996 | 1996 | ||
1997 | if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) | 1997 | if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) |
1998 | new_tsec->sid = old_tsec->sid; | 1998 | new_tsec->sid = old_tsec->sid; |
@@ -2120,7 +2120,7 @@ static inline void flush_unauthorized_files(const struct cred *cred, | |||
2120 | 2120 | ||
2121 | /* Revalidate access to inherited open files. */ | 2121 | /* Revalidate access to inherited open files. */ |
2122 | 2122 | ||
2123 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 2123 | COMMON_AUDIT_DATA_INIT(&ad, INODE); |
2124 | 2124 | ||
2125 | spin_lock(&files->file_lock); | 2125 | spin_lock(&files->file_lock); |
2126 | for (;;) { | 2126 | for (;;) { |
@@ -2468,8 +2468,8 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data) | |||
2468 | if (flags & MS_KERNMOUNT) | 2468 | if (flags & MS_KERNMOUNT) |
2469 | return 0; | 2469 | return 0; |
2470 | 2470 | ||
2471 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 2471 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
2472 | ad.u.fs.path.dentry = sb->s_root; | 2472 | ad.u.path.dentry = sb->s_root; |
2473 | return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); | 2473 | return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); |
2474 | } | 2474 | } |
2475 | 2475 | ||
@@ -2478,8 +2478,8 @@ static int selinux_sb_statfs(struct dentry *dentry) | |||
2478 | const struct cred *cred = current_cred(); | 2478 | const struct cred *cred = current_cred(); |
2479 | struct common_audit_data ad; | 2479 | struct common_audit_data ad; |
2480 | 2480 | ||
2481 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 2481 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
2482 | ad.u.fs.path.dentry = dentry->d_sb->s_root; | 2482 | ad.u.path.dentry = dentry->d_sb->s_root; |
2483 | return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); | 2483 | return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); |
2484 | } | 2484 | } |
2485 | 2485 | ||
@@ -2653,8 +2653,8 @@ static int selinux_inode_permission(struct inode *inode, int mask, unsigned flag | |||
2653 | if (!mask) | 2653 | if (!mask) |
2654 | return 0; | 2654 | return 0; |
2655 | 2655 | ||
2656 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 2656 | COMMON_AUDIT_DATA_INIT(&ad, INODE); |
2657 | ad.u.fs.inode = inode; | 2657 | ad.u.inode = inode; |
2658 | 2658 | ||
2659 | if (from_access) | 2659 | if (from_access) |
2660 | ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS; | 2660 | ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS; |
@@ -2732,8 +2732,8 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, | |||
2732 | if (!is_owner_or_cap(inode)) | 2732 | if (!is_owner_or_cap(inode)) |
2733 | return -EPERM; | 2733 | return -EPERM; |
2734 | 2734 | ||
2735 | COMMON_AUDIT_DATA_INIT(&ad, FS); | 2735 | COMMON_AUDIT_DATA_INIT(&ad, PATH); |
2736 | ad.u.fs.path.dentry = dentry; | 2736 | ad.u.path.dentry = dentry; |
2737 | 2737 | ||
2738 | rc = avc_has_perm(sid, isec->sid, isec->sclass, | 2738 | rc = avc_has_perm(sid, isec->sid, isec->sclass, |
2739 | FILE__RELABELFROM, &ad); | 2739 | FILE__RELABELFROM, &ad); |