aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c258
1 files changed, 118 insertions, 140 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 0b06685787b9..fa2341b68331 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1420,16 +1420,13 @@ static int cred_has_capability(const struct cred *cred,
1420 int cap, int audit) 1420 int cap, int audit)
1421{ 1421{
1422 struct common_audit_data ad; 1422 struct common_audit_data ad;
1423 struct selinux_audit_data sad = {0,};
1424 struct av_decision avd; 1423 struct av_decision avd;
1425 u16 sclass; 1424 u16 sclass;
1426 u32 sid = cred_sid(cred); 1425 u32 sid = cred_sid(cred);
1427 u32 av = CAP_TO_MASK(cap); 1426 u32 av = CAP_TO_MASK(cap);
1428 int rc; 1427 int rc;
1429 1428
1430 COMMON_AUDIT_DATA_INIT(&ad, CAP); 1429 ad.type = LSM_AUDIT_DATA_CAP;
1431 ad.selinux_audit_data = &sad;
1432 ad.tsk = current;
1433 ad.u.cap = cap; 1430 ad.u.cap = cap;
1434 1431
1435 switch (CAP_TO_INDEX(cap)) { 1432 switch (CAP_TO_INDEX(cap)) {
@@ -1488,20 +1485,6 @@ static int inode_has_perm(const struct cred *cred,
1488 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags); 1485 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags);
1489} 1486}
1490 1487
1491static int inode_has_perm_noadp(const struct cred *cred,
1492 struct inode *inode,
1493 u32 perms,
1494 unsigned flags)
1495{
1496 struct common_audit_data ad;
1497 struct selinux_audit_data sad = {0,};
1498
1499 COMMON_AUDIT_DATA_INIT(&ad, INODE);
1500 ad.u.inode = inode;
1501 ad.selinux_audit_data = &sad;
1502 return inode_has_perm(cred, inode, perms, &ad, flags);
1503}
1504
1505/* Same as inode_has_perm, but pass explicit audit data containing 1488/* Same as inode_has_perm, but pass explicit audit data containing
1506 the dentry to help the auditing code to more easily generate the 1489 the dentry to help the auditing code to more easily generate the
1507 pathname if needed. */ 1490 pathname if needed. */
@@ -1511,11 +1494,9 @@ static inline int dentry_has_perm(const struct cred *cred,
1511{ 1494{
1512 struct inode *inode = dentry->d_inode; 1495 struct inode *inode = dentry->d_inode;
1513 struct common_audit_data ad; 1496 struct common_audit_data ad;
1514 struct selinux_audit_data sad = {0,};
1515 1497
1516 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1498 ad.type = LSM_AUDIT_DATA_DENTRY;
1517 ad.u.dentry = dentry; 1499 ad.u.dentry = dentry;
1518 ad.selinux_audit_data = &sad;
1519 return inode_has_perm(cred, inode, av, &ad, 0); 1500 return inode_has_perm(cred, inode, av, &ad, 0);
1520} 1501}
1521 1502
@@ -1528,11 +1509,9 @@ static inline int path_has_perm(const struct cred *cred,
1528{ 1509{
1529 struct inode *inode = path->dentry->d_inode; 1510 struct inode *inode = path->dentry->d_inode;
1530 struct common_audit_data ad; 1511 struct common_audit_data ad;
1531 struct selinux_audit_data sad = {0,};
1532 1512
1533 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1513 ad.type = LSM_AUDIT_DATA_PATH;
1534 ad.u.path = *path; 1514 ad.u.path = *path;
1535 ad.selinux_audit_data = &sad;
1536 return inode_has_perm(cred, inode, av, &ad, 0); 1515 return inode_has_perm(cred, inode, av, &ad, 0);
1537} 1516}
1538 1517
@@ -1551,13 +1530,11 @@ static int file_has_perm(const struct cred *cred,
1551 struct file_security_struct *fsec = file->f_security; 1530 struct file_security_struct *fsec = file->f_security;
1552 struct inode *inode = file->f_path.dentry->d_inode; 1531 struct inode *inode = file->f_path.dentry->d_inode;
1553 struct common_audit_data ad; 1532 struct common_audit_data ad;
1554 struct selinux_audit_data sad = {0,};
1555 u32 sid = cred_sid(cred); 1533 u32 sid = cred_sid(cred);
1556 int rc; 1534 int rc;
1557 1535
1558 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1536 ad.type = LSM_AUDIT_DATA_PATH;
1559 ad.u.path = file->f_path; 1537 ad.u.path = file->f_path;
1560 ad.selinux_audit_data = &sad;
1561 1538
1562 if (sid != fsec->sid) { 1539 if (sid != fsec->sid) {
1563 rc = avc_has_perm(sid, fsec->sid, 1540 rc = avc_has_perm(sid, fsec->sid,
@@ -1587,7 +1564,6 @@ static int may_create(struct inode *dir,
1587 struct superblock_security_struct *sbsec; 1564 struct superblock_security_struct *sbsec;
1588 u32 sid, newsid; 1565 u32 sid, newsid;
1589 struct common_audit_data ad; 1566 struct common_audit_data ad;
1590 struct selinux_audit_data sad = {0,};
1591 int rc; 1567 int rc;
1592 1568
1593 dsec = dir->i_security; 1569 dsec = dir->i_security;
@@ -1596,9 +1572,8 @@ static int may_create(struct inode *dir,
1596 sid = tsec->sid; 1572 sid = tsec->sid;
1597 newsid = tsec->create_sid; 1573 newsid = tsec->create_sid;
1598 1574
1599 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1575 ad.type = LSM_AUDIT_DATA_DENTRY;
1600 ad.u.dentry = dentry; 1576 ad.u.dentry = dentry;
1601 ad.selinux_audit_data = &sad;
1602 1577
1603 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, 1578 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1604 DIR__ADD_NAME | DIR__SEARCH, 1579 DIR__ADD_NAME | DIR__SEARCH,
@@ -1643,7 +1618,6 @@ static int may_link(struct inode *dir,
1643{ 1618{
1644 struct inode_security_struct *dsec, *isec; 1619 struct inode_security_struct *dsec, *isec;
1645 struct common_audit_data ad; 1620 struct common_audit_data ad;
1646 struct selinux_audit_data sad = {0,};
1647 u32 sid = current_sid(); 1621 u32 sid = current_sid();
1648 u32 av; 1622 u32 av;
1649 int rc; 1623 int rc;
@@ -1651,9 +1625,8 @@ static int may_link(struct inode *dir,
1651 dsec = dir->i_security; 1625 dsec = dir->i_security;
1652 isec = dentry->d_inode->i_security; 1626 isec = dentry->d_inode->i_security;
1653 1627
1654 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1628 ad.type = LSM_AUDIT_DATA_DENTRY;
1655 ad.u.dentry = dentry; 1629 ad.u.dentry = dentry;
1656 ad.selinux_audit_data = &sad;
1657 1630
1658 av = DIR__SEARCH; 1631 av = DIR__SEARCH;
1659 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); 1632 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
@@ -1688,7 +1661,6 @@ static inline int may_rename(struct inode *old_dir,
1688{ 1661{
1689 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec; 1662 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1690 struct common_audit_data ad; 1663 struct common_audit_data ad;
1691 struct selinux_audit_data sad = {0,};
1692 u32 sid = current_sid(); 1664 u32 sid = current_sid();
1693 u32 av; 1665 u32 av;
1694 int old_is_dir, new_is_dir; 1666 int old_is_dir, new_is_dir;
@@ -1699,8 +1671,7 @@ static inline int may_rename(struct inode *old_dir,
1699 old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode); 1671 old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
1700 new_dsec = new_dir->i_security; 1672 new_dsec = new_dir->i_security;
1701 1673
1702 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1674 ad.type = LSM_AUDIT_DATA_DENTRY;
1703 ad.selinux_audit_data = &sad;
1704 1675
1705 ad.u.dentry = old_dentry; 1676 ad.u.dentry = old_dentry;
1706 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, 1677 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
@@ -1986,7 +1957,6 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
1986 struct task_security_struct *new_tsec; 1957 struct task_security_struct *new_tsec;
1987 struct inode_security_struct *isec; 1958 struct inode_security_struct *isec;
1988 struct common_audit_data ad; 1959 struct common_audit_data ad;
1989 struct selinux_audit_data sad = {0,};
1990 struct inode *inode = bprm->file->f_path.dentry->d_inode; 1960 struct inode *inode = bprm->file->f_path.dentry->d_inode;
1991 int rc; 1961 int rc;
1992 1962
@@ -2032,8 +2002,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2032 return rc; 2002 return rc;
2033 } 2003 }
2034 2004
2035 COMMON_AUDIT_DATA_INIT(&ad, PATH); 2005 ad.type = LSM_AUDIT_DATA_PATH;
2036 ad.selinux_audit_data = &sad;
2037 ad.u.path = bprm->file->f_path; 2006 ad.u.path = bprm->file->f_path;
2038 2007
2039 if ((bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) || 2008 if ((bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) ||
@@ -2123,8 +2092,6 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm)
2123static inline void flush_unauthorized_files(const struct cred *cred, 2092static inline void flush_unauthorized_files(const struct cred *cred,
2124 struct files_struct *files) 2093 struct files_struct *files)
2125{ 2094{
2126 struct common_audit_data ad;
2127 struct selinux_audit_data sad = {0,};
2128 struct file *file, *devnull = NULL; 2095 struct file *file, *devnull = NULL;
2129 struct tty_struct *tty; 2096 struct tty_struct *tty;
2130 struct fdtable *fdt; 2097 struct fdtable *fdt;
@@ -2136,21 +2103,17 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2136 spin_lock(&tty_files_lock); 2103 spin_lock(&tty_files_lock);
2137 if (!list_empty(&tty->tty_files)) { 2104 if (!list_empty(&tty->tty_files)) {
2138 struct tty_file_private *file_priv; 2105 struct tty_file_private *file_priv;
2139 struct inode *inode;
2140 2106
2141 /* Revalidate access to controlling tty. 2107 /* Revalidate access to controlling tty.
2142 Use inode_has_perm on the tty inode directly rather 2108 Use path_has_perm on the tty path directly rather
2143 than using file_has_perm, as this particular open 2109 than using file_has_perm, as this particular open
2144 file may belong to another process and we are only 2110 file may belong to another process and we are only
2145 interested in the inode-based check here. */ 2111 interested in the inode-based check here. */
2146 file_priv = list_first_entry(&tty->tty_files, 2112 file_priv = list_first_entry(&tty->tty_files,
2147 struct tty_file_private, list); 2113 struct tty_file_private, list);
2148 file = file_priv->file; 2114 file = file_priv->file;
2149 inode = file->f_path.dentry->d_inode; 2115 if (path_has_perm(cred, &file->f_path, FILE__READ | FILE__WRITE))
2150 if (inode_has_perm_noadp(cred, inode,
2151 FILE__READ | FILE__WRITE, 0)) {
2152 drop_tty = 1; 2116 drop_tty = 1;
2153 }
2154 } 2117 }
2155 spin_unlock(&tty_files_lock); 2118 spin_unlock(&tty_files_lock);
2156 tty_kref_put(tty); 2119 tty_kref_put(tty);
@@ -2160,10 +2123,6 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2160 no_tty(); 2123 no_tty();
2161 2124
2162 /* Revalidate access to inherited open files. */ 2125 /* Revalidate access to inherited open files. */
2163
2164 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2165 ad.selinux_audit_data = &sad;
2166
2167 spin_lock(&files->file_lock); 2126 spin_lock(&files->file_lock);
2168 for (;;) { 2127 for (;;) {
2169 unsigned long set, i; 2128 unsigned long set, i;
@@ -2500,7 +2459,6 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2500{ 2459{
2501 const struct cred *cred = current_cred(); 2460 const struct cred *cred = current_cred();
2502 struct common_audit_data ad; 2461 struct common_audit_data ad;
2503 struct selinux_audit_data sad = {0,};
2504 int rc; 2462 int rc;
2505 2463
2506 rc = superblock_doinit(sb, data); 2464 rc = superblock_doinit(sb, data);
@@ -2511,8 +2469,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2511 if (flags & MS_KERNMOUNT) 2469 if (flags & MS_KERNMOUNT)
2512 return 0; 2470 return 0;
2513 2471
2514 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2472 ad.type = LSM_AUDIT_DATA_DENTRY;
2515 ad.selinux_audit_data = &sad;
2516 ad.u.dentry = sb->s_root; 2473 ad.u.dentry = sb->s_root;
2517 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); 2474 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2518} 2475}
@@ -2521,10 +2478,8 @@ static int selinux_sb_statfs(struct dentry *dentry)
2521{ 2478{
2522 const struct cred *cred = current_cred(); 2479 const struct cred *cred = current_cred();
2523 struct common_audit_data ad; 2480 struct common_audit_data ad;
2524 struct selinux_audit_data sad = {0,};
2525 2481
2526 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2482 ad.type = LSM_AUDIT_DATA_DENTRY;
2527 ad.selinux_audit_data = &sad;
2528 ad.u.dentry = dentry->d_sb->s_root; 2483 ad.u.dentry = dentry->d_sb->s_root;
2529 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); 2484 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2530} 2485}
@@ -2684,14 +2639,35 @@ static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *na
2684 return dentry_has_perm(cred, dentry, FILE__READ); 2639 return dentry_has_perm(cred, dentry, FILE__READ);
2685} 2640}
2686 2641
2642static noinline int audit_inode_permission(struct inode *inode,
2643 u32 perms, u32 audited, u32 denied,
2644 unsigned flags)
2645{
2646 struct common_audit_data ad;
2647 struct inode_security_struct *isec = inode->i_security;
2648 int rc;
2649
2650 ad.type = LSM_AUDIT_DATA_INODE;
2651 ad.u.inode = inode;
2652
2653 rc = slow_avc_audit(current_sid(), isec->sid, isec->sclass, perms,
2654 audited, denied, &ad, flags);
2655 if (rc)
2656 return rc;
2657 return 0;
2658}
2659
2687static int selinux_inode_permission(struct inode *inode, int mask) 2660static int selinux_inode_permission(struct inode *inode, int mask)
2688{ 2661{
2689 const struct cred *cred = current_cred(); 2662 const struct cred *cred = current_cred();
2690 struct common_audit_data ad;
2691 struct selinux_audit_data sad = {0,};
2692 u32 perms; 2663 u32 perms;
2693 bool from_access; 2664 bool from_access;
2694 unsigned flags = mask & MAY_NOT_BLOCK; 2665 unsigned flags = mask & MAY_NOT_BLOCK;
2666 struct inode_security_struct *isec;
2667 u32 sid;
2668 struct av_decision avd;
2669 int rc, rc2;
2670 u32 audited, denied;
2695 2671
2696 from_access = mask & MAY_ACCESS; 2672 from_access = mask & MAY_ACCESS;
2697 mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND); 2673 mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
@@ -2700,22 +2676,34 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2700 if (!mask) 2676 if (!mask)
2701 return 0; 2677 return 0;
2702 2678
2703 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2679 validate_creds(cred);
2704 ad.selinux_audit_data = &sad;
2705 ad.u.inode = inode;
2706 2680
2707 if (from_access) 2681 if (unlikely(IS_PRIVATE(inode)))
2708 ad.selinux_audit_data->auditdeny |= FILE__AUDIT_ACCESS; 2682 return 0;
2709 2683
2710 perms = file_mask_to_av(inode->i_mode, mask); 2684 perms = file_mask_to_av(inode->i_mode, mask);
2711 2685
2712 return inode_has_perm(cred, inode, perms, &ad, flags); 2686 sid = cred_sid(cred);
2687 isec = inode->i_security;
2688
2689 rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, &avd);
2690 audited = avc_audit_required(perms, &avd, rc,
2691 from_access ? FILE__AUDIT_ACCESS : 0,
2692 &denied);
2693 if (likely(!audited))
2694 return rc;
2695
2696 rc2 = audit_inode_permission(inode, perms, audited, denied, flags);
2697 if (rc2)
2698 return rc2;
2699 return rc;
2713} 2700}
2714 2701
2715static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) 2702static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
2716{ 2703{
2717 const struct cred *cred = current_cred(); 2704 const struct cred *cred = current_cred();
2718 unsigned int ia_valid = iattr->ia_valid; 2705 unsigned int ia_valid = iattr->ia_valid;
2706 __u32 av = FILE__WRITE;
2719 2707
2720 /* ATTR_FORCE is just used for ATTR_KILL_S[UG]ID. */ 2708 /* ATTR_FORCE is just used for ATTR_KILL_S[UG]ID. */
2721 if (ia_valid & ATTR_FORCE) { 2709 if (ia_valid & ATTR_FORCE) {
@@ -2729,7 +2717,10 @@ static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
2729 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET)) 2717 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET))
2730 return dentry_has_perm(cred, dentry, FILE__SETATTR); 2718 return dentry_has_perm(cred, dentry, FILE__SETATTR);
2731 2719
2732 return dentry_has_perm(cred, dentry, FILE__WRITE); 2720 if (ia_valid & ATTR_SIZE)
2721 av |= FILE__OPEN;
2722
2723 return dentry_has_perm(cred, dentry, av);
2733} 2724}
2734 2725
2735static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) 2726static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
@@ -2771,7 +2762,6 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2771 struct inode_security_struct *isec = inode->i_security; 2762 struct inode_security_struct *isec = inode->i_security;
2772 struct superblock_security_struct *sbsec; 2763 struct superblock_security_struct *sbsec;
2773 struct common_audit_data ad; 2764 struct common_audit_data ad;
2774 struct selinux_audit_data sad = {0,};
2775 u32 newsid, sid = current_sid(); 2765 u32 newsid, sid = current_sid();
2776 int rc = 0; 2766 int rc = 0;
2777 2767
@@ -2785,8 +2775,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2785 if (!inode_owner_or_capable(inode)) 2775 if (!inode_owner_or_capable(inode))
2786 return -EPERM; 2776 return -EPERM;
2787 2777
2788 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2778 ad.type = LSM_AUDIT_DATA_DENTRY;
2789 ad.selinux_audit_data = &sad;
2790 ad.u.dentry = dentry; 2779 ad.u.dentry = dentry;
2791 2780
2792 rc = avc_has_perm(sid, isec->sid, isec->sclass, 2781 rc = avc_has_perm(sid, isec->sid, isec->sclass,
@@ -2796,8 +2785,25 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2796 2785
2797 rc = security_context_to_sid(value, size, &newsid); 2786 rc = security_context_to_sid(value, size, &newsid);
2798 if (rc == -EINVAL) { 2787 if (rc == -EINVAL) {
2799 if (!capable(CAP_MAC_ADMIN)) 2788 if (!capable(CAP_MAC_ADMIN)) {
2789 struct audit_buffer *ab;
2790 size_t audit_size;
2791 const char *str;
2792
2793 /* We strip a nul only if it is at the end, otherwise the
2794 * context contains a nul and we should audit that */
2795 str = value;
2796 if (str[size - 1] == '\0')
2797 audit_size = size - 1;
2798 else
2799 audit_size = size;
2800 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
2801 audit_log_format(ab, "op=setxattr invalid_context=");
2802 audit_log_n_untrustedstring(ab, value, audit_size);
2803 audit_log_end(ab);
2804
2800 return rc; 2805 return rc;
2806 }
2801 rc = security_context_to_sid_force(value, size, &newsid); 2807 rc = security_context_to_sid_force(value, size, &newsid);
2802 } 2808 }
2803 if (rc) 2809 if (rc)
@@ -2977,7 +2983,7 @@ static int selinux_file_permission(struct file *file, int mask)
2977 2983
2978 if (sid == fsec->sid && fsec->isid == isec->sid && 2984 if (sid == fsec->sid && fsec->isid == isec->sid &&
2979 fsec->pseqno == avc_policy_seqno()) 2985 fsec->pseqno == avc_policy_seqno())
2980 /* No change since dentry_open check. */ 2986 /* No change since file_open check. */
2981 return 0; 2987 return 0;
2982 2988
2983 return selinux_revalidate_file_permission(file, mask); 2989 return selinux_revalidate_file_permission(file, mask);
@@ -3236,15 +3242,13 @@ static int selinux_file_receive(struct file *file)
3236 return file_has_perm(cred, file, file_to_av(file)); 3242 return file_has_perm(cred, file, file_to_av(file));
3237} 3243}
3238 3244
3239static int selinux_dentry_open(struct file *file, const struct cred *cred) 3245static int selinux_file_open(struct file *file, const struct cred *cred)
3240{ 3246{
3241 struct file_security_struct *fsec; 3247 struct file_security_struct *fsec;
3242 struct inode *inode;
3243 struct inode_security_struct *isec; 3248 struct inode_security_struct *isec;
3244 3249
3245 inode = file->f_path.dentry->d_inode;
3246 fsec = file->f_security; 3250 fsec = file->f_security;
3247 isec = inode->i_security; 3251 isec = file->f_path.dentry->d_inode->i_security;
3248 /* 3252 /*
3249 * Save inode label and policy sequence number 3253 * Save inode label and policy sequence number
3250 * at open-time so that selinux_file_permission 3254 * at open-time so that selinux_file_permission
@@ -3262,7 +3266,7 @@ static int selinux_dentry_open(struct file *file, const struct cred *cred)
3262 * new inode label or new policy. 3266 * new inode label or new policy.
3263 * This check is not redundant - do not remove. 3267 * This check is not redundant - do not remove.
3264 */ 3268 */
3265 return inode_has_perm_noadp(cred, inode, open_file_to_av(file), 0); 3269 return path_has_perm(cred, &file->f_path, open_file_to_av(file));
3266} 3270}
3267 3271
3268/* task security operations */ 3272/* task security operations */
@@ -3381,12 +3385,10 @@ static int selinux_kernel_module_request(char *kmod_name)
3381{ 3385{
3382 u32 sid; 3386 u32 sid;
3383 struct common_audit_data ad; 3387 struct common_audit_data ad;
3384 struct selinux_audit_data sad = {0,};
3385 3388
3386 sid = task_sid(current); 3389 sid = task_sid(current);
3387 3390
3388 COMMON_AUDIT_DATA_INIT(&ad, KMOD); 3391 ad.type = LSM_AUDIT_DATA_KMOD;
3389 ad.selinux_audit_data = &sad;
3390 ad.u.kmod_name = kmod_name; 3392 ad.u.kmod_name = kmod_name;
3391 3393
3392 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM, 3394 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
@@ -3759,15 +3761,13 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
3759{ 3761{
3760 struct sk_security_struct *sksec = sk->sk_security; 3762 struct sk_security_struct *sksec = sk->sk_security;
3761 struct common_audit_data ad; 3763 struct common_audit_data ad;
3762 struct selinux_audit_data sad = {0,};
3763 struct lsm_network_audit net = {0,}; 3764 struct lsm_network_audit net = {0,};
3764 u32 tsid = task_sid(task); 3765 u32 tsid = task_sid(task);
3765 3766
3766 if (sksec->sid == SECINITSID_KERNEL) 3767 if (sksec->sid == SECINITSID_KERNEL)
3767 return 0; 3768 return 0;
3768 3769
3769 COMMON_AUDIT_DATA_INIT(&ad, NET); 3770 ad.type = LSM_AUDIT_DATA_NET;
3770 ad.selinux_audit_data = &sad;
3771 ad.u.net = &net; 3771 ad.u.net = &net;
3772 ad.u.net->sk = sk; 3772 ad.u.net->sk = sk;
3773 3773
@@ -3847,7 +3847,6 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3847 char *addrp; 3847 char *addrp;
3848 struct sk_security_struct *sksec = sk->sk_security; 3848 struct sk_security_struct *sksec = sk->sk_security;
3849 struct common_audit_data ad; 3849 struct common_audit_data ad;
3850 struct selinux_audit_data sad = {0,};
3851 struct lsm_network_audit net = {0,}; 3850 struct lsm_network_audit net = {0,};
3852 struct sockaddr_in *addr4 = NULL; 3851 struct sockaddr_in *addr4 = NULL;
3853 struct sockaddr_in6 *addr6 = NULL; 3852 struct sockaddr_in6 *addr6 = NULL;
@@ -3874,8 +3873,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3874 snum, &sid); 3873 snum, &sid);
3875 if (err) 3874 if (err)
3876 goto out; 3875 goto out;
3877 COMMON_AUDIT_DATA_INIT(&ad, NET); 3876 ad.type = LSM_AUDIT_DATA_NET;
3878 ad.selinux_audit_data = &sad;
3879 ad.u.net = &net; 3877 ad.u.net = &net;
3880 ad.u.net->sport = htons(snum); 3878 ad.u.net->sport = htons(snum);
3881 ad.u.net->family = family; 3879 ad.u.net->family = family;
@@ -3909,8 +3907,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3909 if (err) 3907 if (err)
3910 goto out; 3908 goto out;
3911 3909
3912 COMMON_AUDIT_DATA_INIT(&ad, NET); 3910 ad.type = LSM_AUDIT_DATA_NET;
3913 ad.selinux_audit_data = &sad;
3914 ad.u.net = &net; 3911 ad.u.net = &net;
3915 ad.u.net->sport = htons(snum); 3912 ad.u.net->sport = htons(snum);
3916 ad.u.net->family = family; 3913 ad.u.net->family = family;
@@ -3945,7 +3942,6 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3945 if (sksec->sclass == SECCLASS_TCP_SOCKET || 3942 if (sksec->sclass == SECCLASS_TCP_SOCKET ||
3946 sksec->sclass == SECCLASS_DCCP_SOCKET) { 3943 sksec->sclass == SECCLASS_DCCP_SOCKET) {
3947 struct common_audit_data ad; 3944 struct common_audit_data ad;
3948 struct selinux_audit_data sad = {0,};
3949 struct lsm_network_audit net = {0,}; 3945 struct lsm_network_audit net = {0,};
3950 struct sockaddr_in *addr4 = NULL; 3946 struct sockaddr_in *addr4 = NULL;
3951 struct sockaddr_in6 *addr6 = NULL; 3947 struct sockaddr_in6 *addr6 = NULL;
@@ -3971,8 +3967,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3971 perm = (sksec->sclass == SECCLASS_TCP_SOCKET) ? 3967 perm = (sksec->sclass == SECCLASS_TCP_SOCKET) ?
3972 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT; 3968 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3973 3969
3974 COMMON_AUDIT_DATA_INIT(&ad, NET); 3970 ad.type = LSM_AUDIT_DATA_NET;
3975 ad.selinux_audit_data = &sad;
3976 ad.u.net = &net; 3971 ad.u.net = &net;
3977 ad.u.net->dport = htons(snum); 3972 ad.u.net->dport = htons(snum);
3978 ad.u.net->family = sk->sk_family; 3973 ad.u.net->family = sk->sk_family;
@@ -4064,12 +4059,10 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
4064 struct sk_security_struct *sksec_other = other->sk_security; 4059 struct sk_security_struct *sksec_other = other->sk_security;
4065 struct sk_security_struct *sksec_new = newsk->sk_security; 4060 struct sk_security_struct *sksec_new = newsk->sk_security;
4066 struct common_audit_data ad; 4061 struct common_audit_data ad;
4067 struct selinux_audit_data sad = {0,};
4068 struct lsm_network_audit net = {0,}; 4062 struct lsm_network_audit net = {0,};
4069 int err; 4063 int err;
4070 4064
4071 COMMON_AUDIT_DATA_INIT(&ad, NET); 4065 ad.type = LSM_AUDIT_DATA_NET;
4072 ad.selinux_audit_data = &sad;
4073 ad.u.net = &net; 4066 ad.u.net = &net;
4074 ad.u.net->sk = other; 4067 ad.u.net->sk = other;
4075 4068
@@ -4098,11 +4091,9 @@ static int selinux_socket_unix_may_send(struct socket *sock,
4098 struct sk_security_struct *ssec = sock->sk->sk_security; 4091 struct sk_security_struct *ssec = sock->sk->sk_security;
4099 struct sk_security_struct *osec = other->sk->sk_security; 4092 struct sk_security_struct *osec = other->sk->sk_security;
4100 struct common_audit_data ad; 4093 struct common_audit_data ad;
4101 struct selinux_audit_data sad = {0,};
4102 struct lsm_network_audit net = {0,}; 4094 struct lsm_network_audit net = {0,};
4103 4095
4104 COMMON_AUDIT_DATA_INIT(&ad, NET); 4096 ad.type = LSM_AUDIT_DATA_NET;
4105 ad.selinux_audit_data = &sad;
4106 ad.u.net = &net; 4097 ad.u.net = &net;
4107 ad.u.net->sk = other->sk; 4098 ad.u.net->sk = other->sk;
4108 4099
@@ -4140,12 +4131,10 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4140 struct sk_security_struct *sksec = sk->sk_security; 4131 struct sk_security_struct *sksec = sk->sk_security;
4141 u32 sk_sid = sksec->sid; 4132 u32 sk_sid = sksec->sid;
4142 struct common_audit_data ad; 4133 struct common_audit_data ad;
4143 struct selinux_audit_data sad = {0,};
4144 struct lsm_network_audit net = {0,}; 4134 struct lsm_network_audit net = {0,};
4145 char *addrp; 4135 char *addrp;
4146 4136
4147 COMMON_AUDIT_DATA_INIT(&ad, NET); 4137 ad.type = LSM_AUDIT_DATA_NET;
4148 ad.selinux_audit_data = &sad;
4149 ad.u.net = &net; 4138 ad.u.net = &net;
4150 ad.u.net->netif = skb->skb_iif; 4139 ad.u.net->netif = skb->skb_iif;
4151 ad.u.net->family = family; 4140 ad.u.net->family = family;
@@ -4175,7 +4164,6 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4175 u16 family = sk->sk_family; 4164 u16 family = sk->sk_family;
4176 u32 sk_sid = sksec->sid; 4165 u32 sk_sid = sksec->sid;
4177 struct common_audit_data ad; 4166 struct common_audit_data ad;
4178 struct selinux_audit_data sad = {0,};
4179 struct lsm_network_audit net = {0,}; 4167 struct lsm_network_audit net = {0,};
4180 char *addrp; 4168 char *addrp;
4181 u8 secmark_active; 4169 u8 secmark_active;
@@ -4200,8 +4188,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4200 if (!secmark_active && !peerlbl_active) 4188 if (!secmark_active && !peerlbl_active)
4201 return 0; 4189 return 0;
4202 4190
4203 COMMON_AUDIT_DATA_INIT(&ad, NET); 4191 ad.type = LSM_AUDIT_DATA_NET;
4204 ad.selinux_audit_data = &sad;
4205 ad.u.net = &net; 4192 ad.u.net = &net;
4206 ad.u.net->netif = skb->skb_iif; 4193 ad.u.net->netif = skb->skb_iif;
4207 ad.u.net->family = family; 4194 ad.u.net->family = family;
@@ -4539,7 +4526,6 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4539 char *addrp; 4526 char *addrp;
4540 u32 peer_sid; 4527 u32 peer_sid;
4541 struct common_audit_data ad; 4528 struct common_audit_data ad;
4542 struct selinux_audit_data sad = {0,};
4543 struct lsm_network_audit net = {0,}; 4529 struct lsm_network_audit net = {0,};
4544 u8 secmark_active; 4530 u8 secmark_active;
4545 u8 netlbl_active; 4531 u8 netlbl_active;
@@ -4557,8 +4543,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4557 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0) 4543 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0)
4558 return NF_DROP; 4544 return NF_DROP;
4559 4545
4560 COMMON_AUDIT_DATA_INIT(&ad, NET); 4546 ad.type = LSM_AUDIT_DATA_NET;
4561 ad.selinux_audit_data = &sad;
4562 ad.u.net = &net; 4547 ad.u.net = &net;
4563 ad.u.net->netif = ifindex; 4548 ad.u.net->netif = ifindex;
4564 ad.u.net->family = family; 4549 ad.u.net->family = family;
@@ -4648,7 +4633,6 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4648 struct sock *sk = skb->sk; 4633 struct sock *sk = skb->sk;
4649 struct sk_security_struct *sksec; 4634 struct sk_security_struct *sksec;
4650 struct common_audit_data ad; 4635 struct common_audit_data ad;
4651 struct selinux_audit_data sad = {0,};
4652 struct lsm_network_audit net = {0,}; 4636 struct lsm_network_audit net = {0,};
4653 char *addrp; 4637 char *addrp;
4654 u8 proto; 4638 u8 proto;
@@ -4657,8 +4641,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4657 return NF_ACCEPT; 4641 return NF_ACCEPT;
4658 sksec = sk->sk_security; 4642 sksec = sk->sk_security;
4659 4643
4660 COMMON_AUDIT_DATA_INIT(&ad, NET); 4644 ad.type = LSM_AUDIT_DATA_NET;
4661 ad.selinux_audit_data = &sad;
4662 ad.u.net = &net; 4645 ad.u.net = &net;
4663 ad.u.net->netif = ifindex; 4646 ad.u.net->netif = ifindex;
4664 ad.u.net->family = family; 4647 ad.u.net->family = family;
@@ -4683,7 +4666,6 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4683 u32 peer_sid; 4666 u32 peer_sid;
4684 struct sock *sk; 4667 struct sock *sk;
4685 struct common_audit_data ad; 4668 struct common_audit_data ad;
4686 struct selinux_audit_data sad = {0,};
4687 struct lsm_network_audit net = {0,}; 4669 struct lsm_network_audit net = {0,};
4688 char *addrp; 4670 char *addrp;
4689 u8 secmark_active; 4671 u8 secmark_active;
@@ -4730,8 +4712,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4730 secmark_perm = PACKET__SEND; 4712 secmark_perm = PACKET__SEND;
4731 } 4713 }
4732 4714
4733 COMMON_AUDIT_DATA_INIT(&ad, NET); 4715 ad.type = LSM_AUDIT_DATA_NET;
4734 ad.selinux_audit_data = &sad;
4735 ad.u.net = &net; 4716 ad.u.net = &net;
4736 ad.u.net->netif = ifindex; 4717 ad.u.net->netif = ifindex;
4737 ad.u.net->family = family; 4718 ad.u.net->family = family;
@@ -4849,13 +4830,11 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4849{ 4830{
4850 struct ipc_security_struct *isec; 4831 struct ipc_security_struct *isec;
4851 struct common_audit_data ad; 4832 struct common_audit_data ad;
4852 struct selinux_audit_data sad = {0,};
4853 u32 sid = current_sid(); 4833 u32 sid = current_sid();
4854 4834
4855 isec = ipc_perms->security; 4835 isec = ipc_perms->security;
4856 4836
4857 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4837 ad.type = LSM_AUDIT_DATA_IPC;
4858 ad.selinux_audit_data = &sad;
4859 ad.u.ipc_id = ipc_perms->key; 4838 ad.u.ipc_id = ipc_perms->key;
4860 4839
4861 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad); 4840 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
@@ -4876,7 +4855,6 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4876{ 4855{
4877 struct ipc_security_struct *isec; 4856 struct ipc_security_struct *isec;
4878 struct common_audit_data ad; 4857 struct common_audit_data ad;
4879 struct selinux_audit_data sad = {0,};
4880 u32 sid = current_sid(); 4858 u32 sid = current_sid();
4881 int rc; 4859 int rc;
4882 4860
@@ -4886,8 +4864,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4886 4864
4887 isec = msq->q_perm.security; 4865 isec = msq->q_perm.security;
4888 4866
4889 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4867 ad.type = LSM_AUDIT_DATA_IPC;
4890 ad.selinux_audit_data = &sad;
4891 ad.u.ipc_id = msq->q_perm.key; 4868 ad.u.ipc_id = msq->q_perm.key;
4892 4869
4893 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4870 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4908,13 +4885,11 @@ static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4908{ 4885{
4909 struct ipc_security_struct *isec; 4886 struct ipc_security_struct *isec;
4910 struct common_audit_data ad; 4887 struct common_audit_data ad;
4911 struct selinux_audit_data sad = {0,};
4912 u32 sid = current_sid(); 4888 u32 sid = current_sid();
4913 4889
4914 isec = msq->q_perm.security; 4890 isec = msq->q_perm.security;
4915 4891
4916 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4892 ad.type = LSM_AUDIT_DATA_IPC;
4917 ad.selinux_audit_data = &sad;
4918 ad.u.ipc_id = msq->q_perm.key; 4893 ad.u.ipc_id = msq->q_perm.key;
4919 4894
4920 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4895 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4954,7 +4929,6 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4954 struct ipc_security_struct *isec; 4929 struct ipc_security_struct *isec;
4955 struct msg_security_struct *msec; 4930 struct msg_security_struct *msec;
4956 struct common_audit_data ad; 4931 struct common_audit_data ad;
4957 struct selinux_audit_data sad = {0,};
4958 u32 sid = current_sid(); 4932 u32 sid = current_sid();
4959 int rc; 4933 int rc;
4960 4934
@@ -4975,8 +4949,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4975 return rc; 4949 return rc;
4976 } 4950 }
4977 4951
4978 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4952 ad.type = LSM_AUDIT_DATA_IPC;
4979 ad.selinux_audit_data = &sad;
4980 ad.u.ipc_id = msq->q_perm.key; 4953 ad.u.ipc_id = msq->q_perm.key;
4981 4954
4982 /* Can this process write to the queue? */ 4955 /* Can this process write to the queue? */
@@ -5001,15 +4974,13 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
5001 struct ipc_security_struct *isec; 4974 struct ipc_security_struct *isec;
5002 struct msg_security_struct *msec; 4975 struct msg_security_struct *msec;
5003 struct common_audit_data ad; 4976 struct common_audit_data ad;
5004 struct selinux_audit_data sad = {0,};
5005 u32 sid = task_sid(target); 4977 u32 sid = task_sid(target);
5006 int rc; 4978 int rc;
5007 4979
5008 isec = msq->q_perm.security; 4980 isec = msq->q_perm.security;
5009 msec = msg->security; 4981 msec = msg->security;
5010 4982
5011 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4983 ad.type = LSM_AUDIT_DATA_IPC;
5012 ad.selinux_audit_data = &sad;
5013 ad.u.ipc_id = msq->q_perm.key; 4984 ad.u.ipc_id = msq->q_perm.key;
5014 4985
5015 rc = avc_has_perm(sid, isec->sid, 4986 rc = avc_has_perm(sid, isec->sid,
@@ -5025,7 +4996,6 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
5025{ 4996{
5026 struct ipc_security_struct *isec; 4997 struct ipc_security_struct *isec;
5027 struct common_audit_data ad; 4998 struct common_audit_data ad;
5028 struct selinux_audit_data sad = {0,};
5029 u32 sid = current_sid(); 4999 u32 sid = current_sid();
5030 int rc; 5000 int rc;
5031 5001
@@ -5035,8 +5005,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
5035 5005
5036 isec = shp->shm_perm.security; 5006 isec = shp->shm_perm.security;
5037 5007
5038 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5008 ad.type = LSM_AUDIT_DATA_IPC;
5039 ad.selinux_audit_data = &sad;
5040 ad.u.ipc_id = shp->shm_perm.key; 5009 ad.u.ipc_id = shp->shm_perm.key;
5041 5010
5042 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5011 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5057,13 +5026,11 @@ static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
5057{ 5026{
5058 struct ipc_security_struct *isec; 5027 struct ipc_security_struct *isec;
5059 struct common_audit_data ad; 5028 struct common_audit_data ad;
5060 struct selinux_audit_data sad = {0,};
5061 u32 sid = current_sid(); 5029 u32 sid = current_sid();
5062 5030
5063 isec = shp->shm_perm.security; 5031 isec = shp->shm_perm.security;
5064 5032
5065 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5033 ad.type = LSM_AUDIT_DATA_IPC;
5066 ad.selinux_audit_data = &sad;
5067 ad.u.ipc_id = shp->shm_perm.key; 5034 ad.u.ipc_id = shp->shm_perm.key;
5068 5035
5069 return avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5036 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5121,7 +5088,6 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5121{ 5088{
5122 struct ipc_security_struct *isec; 5089 struct ipc_security_struct *isec;
5123 struct common_audit_data ad; 5090 struct common_audit_data ad;
5124 struct selinux_audit_data sad = {0,};
5125 u32 sid = current_sid(); 5091 u32 sid = current_sid();
5126 int rc; 5092 int rc;
5127 5093
@@ -5131,8 +5097,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5131 5097
5132 isec = sma->sem_perm.security; 5098 isec = sma->sem_perm.security;
5133 5099
5134 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5100 ad.type = LSM_AUDIT_DATA_IPC;
5135 ad.selinux_audit_data = &sad;
5136 ad.u.ipc_id = sma->sem_perm.key; 5101 ad.u.ipc_id = sma->sem_perm.key;
5137 5102
5138 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5103 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5153,13 +5118,11 @@ static int selinux_sem_associate(struct sem_array *sma, int semflg)
5153{ 5118{
5154 struct ipc_security_struct *isec; 5119 struct ipc_security_struct *isec;
5155 struct common_audit_data ad; 5120 struct common_audit_data ad;
5156 struct selinux_audit_data sad = {0,};
5157 u32 sid = current_sid(); 5121 u32 sid = current_sid();
5158 5122
5159 isec = sma->sem_perm.security; 5123 isec = sma->sem_perm.security;
5160 5124
5161 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5125 ad.type = LSM_AUDIT_DATA_IPC;
5162 ad.selinux_audit_data = &sad;
5163 ad.u.ipc_id = sma->sem_perm.key; 5126 ad.u.ipc_id = sma->sem_perm.key;
5164 5127
5165 return avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5128 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5339,8 +5302,23 @@ static int selinux_setprocattr(struct task_struct *p,
5339 } 5302 }
5340 error = security_context_to_sid(value, size, &sid); 5303 error = security_context_to_sid(value, size, &sid);
5341 if (error == -EINVAL && !strcmp(name, "fscreate")) { 5304 if (error == -EINVAL && !strcmp(name, "fscreate")) {
5342 if (!capable(CAP_MAC_ADMIN)) 5305 if (!capable(CAP_MAC_ADMIN)) {
5306 struct audit_buffer *ab;
5307 size_t audit_size;
5308
5309 /* We strip a nul only if it is at the end, otherwise the
5310 * context contains a nul and we should audit that */
5311 if (str[size - 1] == '\0')
5312 audit_size = size - 1;
5313 else
5314 audit_size = size;
5315 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
5316 audit_log_format(ab, "op=fscreate invalid_context=");
5317 audit_log_n_untrustedstring(ab, value, audit_size);
5318 audit_log_end(ab);
5319
5343 return error; 5320 return error;
5321 }
5344 error = security_context_to_sid_force(value, size, 5322 error = security_context_to_sid_force(value, size,
5345 &sid); 5323 &sid);
5346 } 5324 }
@@ -5600,7 +5578,7 @@ static struct security_operations selinux_ops = {
5600 .file_send_sigiotask = selinux_file_send_sigiotask, 5578 .file_send_sigiotask = selinux_file_send_sigiotask,
5601 .file_receive = selinux_file_receive, 5579 .file_receive = selinux_file_receive,
5602 5580
5603 .dentry_open = selinux_dentry_open, 5581 .file_open = selinux_file_open,
5604 5582
5605 .task_create = selinux_task_create, 5583 .task_create = selinux_task_create,
5606 .cred_alloc_blank = selinux_cred_alloc_blank, 5584 .cred_alloc_blank = selinux_cred_alloc_blank,