aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2011-04-28 16:04:24 -0400
committerEric Paris <eparis@redhat.com>2011-04-28 16:09:59 -0400
commit2875fa00830be62431f5ac22d8f85d57f9fa3033 (patch)
tree541fdb15e39711fb1ad901223d823421c7b77526 /security/selinux
parenta8d05c81fb238bbb18878ccfae7599ca79448dd3 (diff)
SELinux: introduce path_has_perm
We currently have inode_has_perm and dentry_has_perm. dentry_has_perm just calls inode_has_perm with additional audit data. But dentry_has_perm can take either a dentry or a path. Split those to make the code obvious and to fix the previous problem where I thought dentry_has_perm always had a valid dentry and mnt. Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/hooks.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index a6dd2bed8d7b..9f426b8a12b5 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1499,16 +1499,29 @@ static int inode_has_perm(const struct cred *cred,
1499 the dentry to help the auditing code to more easily generate the 1499 the dentry to help the auditing code to more easily generate the
1500 pathname if needed. */ 1500 pathname if needed. */
1501static inline int dentry_has_perm(const struct cred *cred, 1501static inline int dentry_has_perm(const struct cred *cred,
1502 struct vfsmount *mnt,
1503 struct dentry *dentry, 1502 struct dentry *dentry,
1504 u32 av) 1503 u32 av)
1505{ 1504{
1506 struct inode *inode = dentry->d_inode; 1505 struct inode *inode = dentry->d_inode;
1507 struct common_audit_data ad; 1506 struct common_audit_data ad;
1508 1507
1508 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1509 ad.u.dentry = dentry;
1510 return inode_has_perm(cred, inode, av, &ad, 0);
1511}
1512
1513/* Same as inode_has_perm, but pass explicit audit data containing
1514 the path to help the auditing code to more easily generate the
1515 pathname if needed. */
1516static inline int path_has_perm(const struct cred *cred,
1517 struct path *path,
1518 u32 av)
1519{
1520 struct inode *inode = path->dentry->d_inode;
1521 struct common_audit_data ad;
1522
1509 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1523 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1510 ad.u.path.mnt = mnt; 1524 ad.u.path = *path;
1511 ad.u.path.dentry = dentry;
1512 return inode_has_perm(cred, inode, av, &ad, 0); 1525 return inode_has_perm(cred, inode, av, &ad, 0);
1513} 1526}
1514 1527
@@ -1896,7 +1909,7 @@ static int selinux_quota_on(struct dentry *dentry)
1896{ 1909{
1897 const struct cred *cred = current_cred(); 1910 const struct cred *cred = current_cred();
1898 1911
1899 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON); 1912 return dentry_has_perm(cred, dentry, FILE__QUOTAON);
1900} 1913}
1901 1914
1902static int selinux_syslog(int type) 1915static int selinux_syslog(int type)
@@ -2496,8 +2509,7 @@ static int selinux_mount(char *dev_name,
2496 return superblock_has_perm(cred, path->mnt->mnt_sb, 2509 return superblock_has_perm(cred, path->mnt->mnt_sb,
2497 FILESYSTEM__REMOUNT, NULL); 2510 FILESYSTEM__REMOUNT, NULL);
2498 else 2511 else
2499 return dentry_has_perm(cred, path->mnt, path->dentry, 2512 return path_has_perm(cred, path, FILE__MOUNTON);
2500 FILE__MOUNTON);
2501} 2513}
2502 2514
2503static int selinux_umount(struct vfsmount *mnt, int flags) 2515static int selinux_umount(struct vfsmount *mnt, int flags)
@@ -2630,14 +2642,14 @@ static int selinux_inode_readlink(struct dentry *dentry)
2630{ 2642{
2631 const struct cred *cred = current_cred(); 2643 const struct cred *cred = current_cred();
2632 2644
2633 return dentry_has_perm(cred, NULL, dentry, FILE__READ); 2645 return dentry_has_perm(cred, dentry, FILE__READ);
2634} 2646}
2635 2647
2636static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *nameidata) 2648static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *nameidata)
2637{ 2649{
2638 const struct cred *cred = current_cred(); 2650 const struct cred *cred = current_cred();
2639 2651
2640 return dentry_has_perm(cred, NULL, dentry, FILE__READ); 2652 return dentry_has_perm(cred, dentry, FILE__READ);
2641} 2653}
2642 2654
2643static int selinux_inode_permission(struct inode *inode, int mask, unsigned flags) 2655static int selinux_inode_permission(struct inode *inode, int mask, unsigned flags)
@@ -2680,16 +2692,20 @@ static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
2680 2692
2681 if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | 2693 if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2682 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET)) 2694 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET))
2683 return dentry_has_perm(cred, NULL, dentry, FILE__SETATTR); 2695 return dentry_has_perm(cred, dentry, FILE__SETATTR);
2684 2696
2685 return dentry_has_perm(cred, NULL, dentry, FILE__WRITE); 2697 return dentry_has_perm(cred, dentry, FILE__WRITE);
2686} 2698}
2687 2699
2688static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) 2700static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
2689{ 2701{
2690 const struct cred *cred = current_cred(); 2702 const struct cred *cred = current_cred();
2703 struct path path;
2704
2705 path.dentry = dentry;
2706 path.mnt = mnt;
2691 2707
2692 return dentry_has_perm(cred, mnt, dentry, FILE__GETATTR); 2708 return path_has_perm(cred, &path, FILE__GETATTR);
2693} 2709}
2694 2710
2695static int selinux_inode_setotherxattr(struct dentry *dentry, const char *name) 2711static int selinux_inode_setotherxattr(struct dentry *dentry, const char *name)
@@ -2710,7 +2726,7 @@ static int selinux_inode_setotherxattr(struct dentry *dentry, const char *name)
2710 2726
2711 /* Not an attribute we recognize, so just check the 2727 /* Not an attribute we recognize, so just check the
2712 ordinary setattr permission. */ 2728 ordinary setattr permission. */
2713 return dentry_has_perm(cred, NULL, dentry, FILE__SETATTR); 2729 return dentry_has_perm(cred, dentry, FILE__SETATTR);
2714} 2730}
2715 2731
2716static int selinux_inode_setxattr(struct dentry *dentry, const char *name, 2732static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
@@ -2797,14 +2813,14 @@ static int selinux_inode_getxattr(struct dentry *dentry, const char *name)
2797{ 2813{
2798 const struct cred *cred = current_cred(); 2814 const struct cred *cred = current_cred();
2799 2815
2800 return dentry_has_perm(cred, NULL, dentry, FILE__GETATTR); 2816 return dentry_has_perm(cred, dentry, FILE__GETATTR);
2801} 2817}
2802 2818
2803static int selinux_inode_listxattr(struct dentry *dentry) 2819static int selinux_inode_listxattr(struct dentry *dentry)
2804{ 2820{
2805 const struct cred *cred = current_cred(); 2821 const struct cred *cred = current_cred();
2806 2822
2807 return dentry_has_perm(cred, NULL, dentry, FILE__GETATTR); 2823 return dentry_has_perm(cred, dentry, FILE__GETATTR);
2808} 2824}
2809 2825
2810static int selinux_inode_removexattr(struct dentry *dentry, const char *name) 2826static int selinux_inode_removexattr(struct dentry *dentry, const char *name)