hooks.c (bbb20089a3275a19e475dbc21320c3742e3ca423) hooks.c (1ee65e37e904b959c24404139f5752edc66319d5)
1/*
2 * NSA Security-Enhanced Linux (SELinux) security module
3 *
4 * This file contains the SELinux hook function implementations.
5 *
6 * Authors: Stephen Smalley, <sds@epoch.ncsc.mil>
7 * Chris Vance, <cvance@nai.com>
8 * Wayne Salamon, <wsalamon@nai.com>
9 * James Morris <jmorris@redhat.com>
10 *
11 * Copyright (C) 2001,2002 Networks Associates Technology, Inc.
12 * Copyright (C) 2003-2008 Red Hat, Inc., James Morris <jmorris@redhat.com>
13 * Eric Paris <eparis@redhat.com>
14 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
15 * <dgoeddel@trustedcs.com>
1/*
2 * NSA Security-Enhanced Linux (SELinux) security module
3 *
4 * This file contains the SELinux hook function implementations.
5 *
6 * Authors: Stephen Smalley, <sds@epoch.ncsc.mil>
7 * Chris Vance, <cvance@nai.com>
8 * Wayne Salamon, <wsalamon@nai.com>
9 * James Morris <jmorris@redhat.com>
10 *
11 * Copyright (C) 2001,2002 Networks Associates Technology, Inc.
12 * Copyright (C) 2003-2008 Red Hat, Inc., James Morris <jmorris@redhat.com>
13 * Eric Paris <eparis@redhat.com>
14 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
15 * <dgoeddel@trustedcs.com>
16 * Copyright (C) 2006, 2007 Hewlett-Packard Development Company, L.P.
17 * Paul Moore <paul.moore@hp.com>
16 * Copyright (C) 2006, 2007, 2009 Hewlett-Packard Development Company, L.P.
17 * Paul Moore <paul.moore@hp.com>
18 * Copyright (C) 2007 Hitachi Software Engineering Co., Ltd.
19 * Yuichi Nakamura <ynakam@hitachisoft.jp>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License version 2,
23 * as published by the Free Software Foundation.
24 */
25

--- 1254 unchanged lines hidden (view full) ---

1280 rc = -ENOMEM;
1281 dput(dentry);
1282 goto out_unlock;
1283 }
1284 context[len] = '\0';
1285 rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX,
1286 context, len);
1287 if (rc == -ERANGE) {
18 * Copyright (C) 2007 Hitachi Software Engineering Co., Ltd.
19 * Yuichi Nakamura <ynakam@hitachisoft.jp>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License version 2,
23 * as published by the Free Software Foundation.
24 */
25

--- 1254 unchanged lines hidden (view full) ---

1280 rc = -ENOMEM;
1281 dput(dentry);
1282 goto out_unlock;
1283 }
1284 context[len] = '\0';
1285 rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX,
1286 context, len);
1287 if (rc == -ERANGE) {
1288 kfree(context);
1289
1288 /* Need a larger buffer. Query for the right size. */
1289 rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX,
1290 NULL, 0);
1291 if (rc < 0) {
1292 dput(dentry);
1293 goto out_unlock;
1294 }
1290 /* Need a larger buffer. Query for the right size. */
1291 rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX,
1292 NULL, 0);
1293 if (rc < 0) {
1294 dput(dentry);
1295 goto out_unlock;
1296 }
1295 kfree(context);
1296 len = rc;
1297 context = kmalloc(len+1, GFP_NOFS);
1298 if (!context) {
1299 rc = -ENOMEM;
1300 dput(dentry);
1301 goto out_unlock;
1302 }
1303 context[len] = '\0';

--- 169 unchanged lines hidden (view full) ---

1473#error Fix SELinux to handle capabilities > 63.
1474#endif
1475
1476/* Check whether a task is allowed to use a capability. */
1477static int task_has_capability(struct task_struct *tsk,
1478 const struct cred *cred,
1479 int cap, int audit)
1480{
1297 len = rc;
1298 context = kmalloc(len+1, GFP_NOFS);
1299 if (!context) {
1300 rc = -ENOMEM;
1301 dput(dentry);
1302 goto out_unlock;
1303 }
1304 context[len] = '\0';

--- 169 unchanged lines hidden (view full) ---

1474#error Fix SELinux to handle capabilities > 63.
1475#endif
1476
1477/* Check whether a task is allowed to use a capability. */
1478static int task_has_capability(struct task_struct *tsk,
1479 const struct cred *cred,
1480 int cap, int audit)
1481{
1481 struct avc_audit_data ad;
1482 struct common_audit_data ad;
1482 struct av_decision avd;
1483 u16 sclass;
1484 u32 sid = cred_sid(cred);
1485 u32 av = CAP_TO_MASK(cap);
1486 int rc;
1487
1483 struct av_decision avd;
1484 u16 sclass;
1485 u32 sid = cred_sid(cred);
1486 u32 av = CAP_TO_MASK(cap);
1487 int rc;
1488
1488 AVC_AUDIT_DATA_INIT(&ad, CAP);
1489 COMMON_AUDIT_DATA_INIT(&ad, CAP);
1489 ad.tsk = tsk;
1490 ad.u.cap = cap;
1491
1492 switch (CAP_TO_INDEX(cap)) {
1493 case 0:
1494 sclass = SECCLASS_CAPABILITY;
1495 break;
1496 case 1:

--- 22 unchanged lines hidden (view full) ---

1519}
1520
1521/* Check whether a task has a particular permission to an inode.
1522 The 'adp' parameter is optional and allows other audit
1523 data to be passed (e.g. the dentry). */
1524static int inode_has_perm(const struct cred *cred,
1525 struct inode *inode,
1526 u32 perms,
1490 ad.tsk = tsk;
1491 ad.u.cap = cap;
1492
1493 switch (CAP_TO_INDEX(cap)) {
1494 case 0:
1495 sclass = SECCLASS_CAPABILITY;
1496 break;
1497 case 1:

--- 22 unchanged lines hidden (view full) ---

1520}
1521
1522/* Check whether a task has a particular permission to an inode.
1523 The 'adp' parameter is optional and allows other audit
1524 data to be passed (e.g. the dentry). */
1525static int inode_has_perm(const struct cred *cred,
1526 struct inode *inode,
1527 u32 perms,
1527 struct avc_audit_data *adp)
1528 struct common_audit_data *adp)
1528{
1529 struct inode_security_struct *isec;
1529{
1530 struct inode_security_struct *isec;
1530 struct avc_audit_data ad;
1531 struct common_audit_data ad;
1531 u32 sid;
1532
1532 u32 sid;
1533
1534 validate_creds(cred);
1535
1533 if (unlikely(IS_PRIVATE(inode)))
1534 return 0;
1535
1536 sid = cred_sid(cred);
1537 isec = inode->i_security;
1538
1539 if (!adp) {
1540 adp = &ad;
1536 if (unlikely(IS_PRIVATE(inode)))
1537 return 0;
1538
1539 sid = cred_sid(cred);
1540 isec = inode->i_security;
1541
1542 if (!adp) {
1543 adp = &ad;
1541 AVC_AUDIT_DATA_INIT(&ad, FS);
1544 COMMON_AUDIT_DATA_INIT(&ad, FS);
1542 ad.u.fs.inode = inode;
1543 }
1544
1545 return avc_has_perm(sid, isec->sid, isec->sclass, perms, adp);
1546}
1547
1548/* Same as inode_has_perm, but pass explicit audit data containing
1549 the dentry to help the auditing code to more easily generate the
1550 pathname if needed. */
1551static inline int dentry_has_perm(const struct cred *cred,
1552 struct vfsmount *mnt,
1553 struct dentry *dentry,
1554 u32 av)
1555{
1556 struct inode *inode = dentry->d_inode;
1545 ad.u.fs.inode = inode;
1546 }
1547
1548 return avc_has_perm(sid, isec->sid, isec->sclass, perms, adp);
1549}
1550
1551/* Same as inode_has_perm, but pass explicit audit data containing
1552 the dentry to help the auditing code to more easily generate the
1553 pathname if needed. */
1554static inline int dentry_has_perm(const struct cred *cred,
1555 struct vfsmount *mnt,
1556 struct dentry *dentry,
1557 u32 av)
1558{
1559 struct inode *inode = dentry->d_inode;
1557 struct avc_audit_data ad;
1560 struct common_audit_data ad;
1558
1561
1559 AVC_AUDIT_DATA_INIT(&ad, FS);
1562 COMMON_AUDIT_DATA_INIT(&ad, FS);
1560 ad.u.fs.path.mnt = mnt;
1561 ad.u.fs.path.dentry = dentry;
1562 return inode_has_perm(cred, inode, av, &ad);
1563}
1564
1565/* Check whether a task can use an open file descriptor to
1566 access an inode in a given way. Check access to the
1567 descriptor itself, and then use dentry_has_perm to
1568 check a particular permission to the file.
1569 Access to the descriptor is implicitly granted if it
1570 has the same SID as the process. If av is zero, then
1571 access to the file is not checked, e.g. for cases
1572 where only the descriptor is affected like seek. */
1573static int file_has_perm(const struct cred *cred,
1574 struct file *file,
1575 u32 av)
1576{
1577 struct file_security_struct *fsec = file->f_security;
1578 struct inode *inode = file->f_path.dentry->d_inode;
1563 ad.u.fs.path.mnt = mnt;
1564 ad.u.fs.path.dentry = dentry;
1565 return inode_has_perm(cred, inode, av, &ad);
1566}
1567
1568/* Check whether a task can use an open file descriptor to
1569 access an inode in a given way. Check access to the
1570 descriptor itself, and then use dentry_has_perm to
1571 check a particular permission to the file.
1572 Access to the descriptor is implicitly granted if it
1573 has the same SID as the process. If av is zero, then
1574 access to the file is not checked, e.g. for cases
1575 where only the descriptor is affected like seek. */
1576static int file_has_perm(const struct cred *cred,
1577 struct file *file,
1578 u32 av)
1579{
1580 struct file_security_struct *fsec = file->f_security;
1581 struct inode *inode = file->f_path.dentry->d_inode;
1579 struct avc_audit_data ad;
1582 struct common_audit_data ad;
1580 u32 sid = cred_sid(cred);
1581 int rc;
1582
1583 u32 sid = cred_sid(cred);
1584 int rc;
1585
1583 AVC_AUDIT_DATA_INIT(&ad, FS);
1586 COMMON_AUDIT_DATA_INIT(&ad, FS);
1584 ad.u.fs.path = file->f_path;
1585
1586 if (sid != fsec->sid) {
1587 rc = avc_has_perm(sid, fsec->sid,
1588 SECCLASS_FD,
1589 FD__USE,
1590 &ad);
1591 if (rc)

--- 14 unchanged lines hidden (view full) ---

1606 struct dentry *dentry,
1607 u16 tclass)
1608{
1609 const struct cred *cred = current_cred();
1610 const struct task_security_struct *tsec = cred->security;
1611 struct inode_security_struct *dsec;
1612 struct superblock_security_struct *sbsec;
1613 u32 sid, newsid;
1587 ad.u.fs.path = file->f_path;
1588
1589 if (sid != fsec->sid) {
1590 rc = avc_has_perm(sid, fsec->sid,
1591 SECCLASS_FD,
1592 FD__USE,
1593 &ad);
1594 if (rc)

--- 14 unchanged lines hidden (view full) ---

1609 struct dentry *dentry,
1610 u16 tclass)
1611{
1612 const struct cred *cred = current_cred();
1613 const struct task_security_struct *tsec = cred->security;
1614 struct inode_security_struct *dsec;
1615 struct superblock_security_struct *sbsec;
1616 u32 sid, newsid;
1614 struct avc_audit_data ad;
1617 struct common_audit_data ad;
1615 int rc;
1616
1617 dsec = dir->i_security;
1618 sbsec = dir->i_sb->s_security;
1619
1620 sid = tsec->sid;
1621 newsid = tsec->create_sid;
1622
1618 int rc;
1619
1620 dsec = dir->i_security;
1621 sbsec = dir->i_sb->s_security;
1622
1623 sid = tsec->sid;
1624 newsid = tsec->create_sid;
1625
1623 AVC_AUDIT_DATA_INIT(&ad, FS);
1626 COMMON_AUDIT_DATA_INIT(&ad, FS);
1624 ad.u.fs.path.dentry = dentry;
1625
1626 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1627 DIR__ADD_NAME | DIR__SEARCH,
1628 &ad);
1629 if (rc)
1630 return rc;
1631

--- 27 unchanged lines hidden (view full) ---

1659
1660/* Check whether a task can link, unlink, or rmdir a file/directory. */
1661static int may_link(struct inode *dir,
1662 struct dentry *dentry,
1663 int kind)
1664
1665{
1666 struct inode_security_struct *dsec, *isec;
1627 ad.u.fs.path.dentry = dentry;
1628
1629 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1630 DIR__ADD_NAME | DIR__SEARCH,
1631 &ad);
1632 if (rc)
1633 return rc;
1634

--- 27 unchanged lines hidden (view full) ---

1662
1663/* Check whether a task can link, unlink, or rmdir a file/directory. */
1664static int may_link(struct inode *dir,
1665 struct dentry *dentry,
1666 int kind)
1667
1668{
1669 struct inode_security_struct *dsec, *isec;
1667 struct avc_audit_data ad;
1670 struct common_audit_data ad;
1668 u32 sid = current_sid();
1669 u32 av;
1670 int rc;
1671
1672 dsec = dir->i_security;
1673 isec = dentry->d_inode->i_security;
1674
1671 u32 sid = current_sid();
1672 u32 av;
1673 int rc;
1674
1675 dsec = dir->i_security;
1676 isec = dentry->d_inode->i_security;
1677
1675 AVC_AUDIT_DATA_INIT(&ad, FS);
1678 COMMON_AUDIT_DATA_INIT(&ad, FS);
1676 ad.u.fs.path.dentry = dentry;
1677
1678 av = DIR__SEARCH;
1679 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
1680 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, av, &ad);
1681 if (rc)
1682 return rc;
1683

--- 18 unchanged lines hidden (view full) ---

1702}
1703
1704static inline int may_rename(struct inode *old_dir,
1705 struct dentry *old_dentry,
1706 struct inode *new_dir,
1707 struct dentry *new_dentry)
1708{
1709 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1679 ad.u.fs.path.dentry = dentry;
1680
1681 av = DIR__SEARCH;
1682 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
1683 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, av, &ad);
1684 if (rc)
1685 return rc;
1686

--- 18 unchanged lines hidden (view full) ---

1705}
1706
1707static inline int may_rename(struct inode *old_dir,
1708 struct dentry *old_dentry,
1709 struct inode *new_dir,
1710 struct dentry *new_dentry)
1711{
1712 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1710 struct avc_audit_data ad;
1713 struct common_audit_data ad;
1711 u32 sid = current_sid();
1712 u32 av;
1713 int old_is_dir, new_is_dir;
1714 int rc;
1715
1716 old_dsec = old_dir->i_security;
1717 old_isec = old_dentry->d_inode->i_security;
1718 old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
1719 new_dsec = new_dir->i_security;
1720
1714 u32 sid = current_sid();
1715 u32 av;
1716 int old_is_dir, new_is_dir;
1717 int rc;
1718
1719 old_dsec = old_dir->i_security;
1720 old_isec = old_dentry->d_inode->i_security;
1721 old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
1722 new_dsec = new_dir->i_security;
1723
1721 AVC_AUDIT_DATA_INIT(&ad, FS);
1724 COMMON_AUDIT_DATA_INIT(&ad, FS);
1722
1723 ad.u.fs.path.dentry = old_dentry;
1724 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
1725 DIR__REMOVE_NAME | DIR__SEARCH, &ad);
1726 if (rc)
1727 return rc;
1728 rc = avc_has_perm(sid, old_isec->sid,
1729 old_isec->sclass, FILE__RENAME, &ad);

--- 25 unchanged lines hidden (view full) ---

1755
1756 return 0;
1757}
1758
1759/* Check whether a task can perform a filesystem operation. */
1760static int superblock_has_perm(const struct cred *cred,
1761 struct super_block *sb,
1762 u32 perms,
1725
1726 ad.u.fs.path.dentry = old_dentry;
1727 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
1728 DIR__REMOVE_NAME | DIR__SEARCH, &ad);
1729 if (rc)
1730 return rc;
1731 rc = avc_has_perm(sid, old_isec->sid,
1732 old_isec->sclass, FILE__RENAME, &ad);

--- 25 unchanged lines hidden (view full) ---

1758
1759 return 0;
1760}
1761
1762/* Check whether a task can perform a filesystem operation. */
1763static int superblock_has_perm(const struct cred *cred,
1764 struct super_block *sb,
1765 u32 perms,
1763 struct avc_audit_data *ad)
1766 struct common_audit_data *ad)
1764{
1765 struct superblock_security_struct *sbsec;
1766 u32 sid = cred_sid(cred);
1767
1768 sbsec = sb->s_security;
1769 return avc_has_perm(sid, sbsec->sid, SECCLASS_FILESYSTEM, perms, ad);
1770}
1771

--- 77 unchanged lines hidden (view full) ---

1849 printk(KERN_ERR "SELinux: WARNING: inside %s with "
1850 "unknown mode:%o\n", __func__, mode);
1851 }
1852 return av;
1853}
1854
1855/* Hook functions begin here. */
1856
1767{
1768 struct superblock_security_struct *sbsec;
1769 u32 sid = cred_sid(cred);
1770
1771 sbsec = sb->s_security;
1772 return avc_has_perm(sid, sbsec->sid, SECCLASS_FILESYSTEM, perms, ad);
1773}
1774

--- 77 unchanged lines hidden (view full) ---

1852 printk(KERN_ERR "SELinux: WARNING: inside %s with "
1853 "unknown mode:%o\n", __func__, mode);
1854 }
1855 return av;
1856}
1857
1858/* Hook functions begin here. */
1859
1857static int selinux_ptrace_may_access(struct task_struct *child,
1860static int selinux_ptrace_access_check(struct task_struct *child,
1858 unsigned int mode)
1859{
1860 int rc;
1861
1861 unsigned int mode)
1862{
1863 int rc;
1864
1862 rc = cap_ptrace_may_access(child, mode);
1865 rc = cap_ptrace_access_check(child, mode);
1863 if (rc)
1864 return rc;
1865
1866 if (mode == PTRACE_MODE_READ) {
1867 u32 sid = current_sid();
1868 u32 csid = task_sid(child);
1869 return avc_has_perm(sid, csid, SECCLASS_FILE, FILE__READ, NULL);
1870 }

--- 224 unchanged lines hidden (view full) ---

2095
2096/* binprm security operations */
2097
2098static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2099{
2100 const struct task_security_struct *old_tsec;
2101 struct task_security_struct *new_tsec;
2102 struct inode_security_struct *isec;
1866 if (rc)
1867 return rc;
1868
1869 if (mode == PTRACE_MODE_READ) {
1870 u32 sid = current_sid();
1871 u32 csid = task_sid(child);
1872 return avc_has_perm(sid, csid, SECCLASS_FILE, FILE__READ, NULL);
1873 }

--- 224 unchanged lines hidden (view full) ---

2098
2099/* binprm security operations */
2100
2101static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2102{
2103 const struct task_security_struct *old_tsec;
2104 struct task_security_struct *new_tsec;
2105 struct inode_security_struct *isec;
2103 struct avc_audit_data ad;
2106 struct common_audit_data ad;
2104 struct inode *inode = bprm->file->f_path.dentry->d_inode;
2105 int rc;
2106
2107 rc = cap_bprm_set_creds(bprm);
2108 if (rc)
2109 return rc;
2110
2111 /* SELinux context only depends on initial program or script and not

--- 21 unchanged lines hidden (view full) ---

2133 } else {
2134 /* Check for a default transition on this program. */
2135 rc = security_transition_sid(old_tsec->sid, isec->sid,
2136 SECCLASS_PROCESS, &new_tsec->sid);
2137 if (rc)
2138 return rc;
2139 }
2140
2107 struct inode *inode = bprm->file->f_path.dentry->d_inode;
2108 int rc;
2109
2110 rc = cap_bprm_set_creds(bprm);
2111 if (rc)
2112 return rc;
2113
2114 /* SELinux context only depends on initial program or script and not

--- 21 unchanged lines hidden (view full) ---

2136 } else {
2137 /* Check for a default transition on this program. */
2138 rc = security_transition_sid(old_tsec->sid, isec->sid,
2139 SECCLASS_PROCESS, &new_tsec->sid);
2140 if (rc)
2141 return rc;
2142 }
2143
2141 AVC_AUDIT_DATA_INIT(&ad, FS);
2144 COMMON_AUDIT_DATA_INIT(&ad, FS);
2142 ad.u.fs.path = bprm->file->f_path;
2143
2144 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
2145 new_tsec->sid = old_tsec->sid;
2146
2147 if (new_tsec->sid == old_tsec->sid) {
2148 rc = avc_has_perm(old_tsec->sid, isec->sid,
2149 SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, &ad);

--- 76 unchanged lines hidden (view full) ---

2226
2227extern struct vfsmount *selinuxfs_mount;
2228extern struct dentry *selinux_null;
2229
2230/* Derived from fs/exec.c:flush_old_files. */
2231static inline void flush_unauthorized_files(const struct cred *cred,
2232 struct files_struct *files)
2233{
2145 ad.u.fs.path = bprm->file->f_path;
2146
2147 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
2148 new_tsec->sid = old_tsec->sid;
2149
2150 if (new_tsec->sid == old_tsec->sid) {
2151 rc = avc_has_perm(old_tsec->sid, isec->sid,
2152 SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, &ad);

--- 76 unchanged lines hidden (view full) ---

2229
2230extern struct vfsmount *selinuxfs_mount;
2231extern struct dentry *selinux_null;
2232
2233/* Derived from fs/exec.c:flush_old_files. */
2234static inline void flush_unauthorized_files(const struct cred *cred,
2235 struct files_struct *files)
2236{
2234 struct avc_audit_data ad;
2237 struct common_audit_data ad;
2235 struct file *file, *devnull = NULL;
2236 struct tty_struct *tty;
2237 struct fdtable *fdt;
2238 long j = -1;
2239 int drop_tty = 0;
2240
2241 tty = get_current_tty();
2242 if (tty) {

--- 17 unchanged lines hidden (view full) ---

2260 tty_kref_put(tty);
2261 }
2262 /* Reset controlling tty. */
2263 if (drop_tty)
2264 no_tty();
2265
2266 /* Revalidate access to inherited open files. */
2267
2238 struct file *file, *devnull = NULL;
2239 struct tty_struct *tty;
2240 struct fdtable *fdt;
2241 long j = -1;
2242 int drop_tty = 0;
2243
2244 tty = get_current_tty();
2245 if (tty) {

--- 17 unchanged lines hidden (view full) ---

2263 tty_kref_put(tty);
2264 }
2265 /* Reset controlling tty. */
2266 if (drop_tty)
2267 no_tty();
2268
2269 /* Revalidate access to inherited open files. */
2270
2268 AVC_AUDIT_DATA_INIT(&ad, FS);
2271 COMMON_AUDIT_DATA_INIT(&ad, FS);
2269
2270 spin_lock(&files->file_lock);
2271 for (;;) {
2272 unsigned long set, i;
2273 int fd;
2274
2275 j++;
2276 i = j * __NFDBITS;

--- 232 unchanged lines hidden (view full) ---

2509 free_page((unsigned long)nosec_save);
2510out:
2511 return rc;
2512}
2513
2514static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2515{
2516 const struct cred *cred = current_cred();
2272
2273 spin_lock(&files->file_lock);
2274 for (;;) {
2275 unsigned long set, i;
2276 int fd;
2277
2278 j++;
2279 i = j * __NFDBITS;

--- 232 unchanged lines hidden (view full) ---

2512 free_page((unsigned long)nosec_save);
2513out:
2514 return rc;
2515}
2516
2517static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2518{
2519 const struct cred *cred = current_cred();
2517 struct avc_audit_data ad;
2520 struct common_audit_data ad;
2518 int rc;
2519
2520 rc = superblock_doinit(sb, data);
2521 if (rc)
2522 return rc;
2523
2524 /* Allow all mounts performed by the kernel */
2525 if (flags & MS_KERNMOUNT)
2526 return 0;
2527
2521 int rc;
2522
2523 rc = superblock_doinit(sb, data);
2524 if (rc)
2525 return rc;
2526
2527 /* Allow all mounts performed by the kernel */
2528 if (flags & MS_KERNMOUNT)
2529 return 0;
2530
2528 AVC_AUDIT_DATA_INIT(&ad, FS);
2531 COMMON_AUDIT_DATA_INIT(&ad, FS);
2529 ad.u.fs.path.dentry = sb->s_root;
2530 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2531}
2532
2533static int selinux_sb_statfs(struct dentry *dentry)
2534{
2535 const struct cred *cred = current_cred();
2532 ad.u.fs.path.dentry = sb->s_root;
2533 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2534}
2535
2536static int selinux_sb_statfs(struct dentry *dentry)
2537{
2538 const struct cred *cred = current_cred();
2536 struct avc_audit_data ad;
2539 struct common_audit_data ad;
2537
2540
2538 AVC_AUDIT_DATA_INIT(&ad, FS);
2541 COMMON_AUDIT_DATA_INIT(&ad, FS);
2539 ad.u.fs.path.dentry = dentry->d_sb->s_root;
2540 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2541}
2542
2543static int selinux_mount(char *dev_name,
2544 struct path *path,
2545 char *type,
2546 unsigned long flags,

--- 158 unchanged lines hidden (view full) ---

2705
2706 return inode_has_perm(cred, inode,
2707 file_mask_to_av(inode->i_mode, mask), NULL);
2708}
2709
2710static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
2711{
2712 const struct cred *cred = current_cred();
2542 ad.u.fs.path.dentry = dentry->d_sb->s_root;
2543 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2544}
2545
2546static int selinux_mount(char *dev_name,
2547 struct path *path,
2548 char *type,
2549 unsigned long flags,

--- 158 unchanged lines hidden (view full) ---

2708
2709 return inode_has_perm(cred, inode,
2710 file_mask_to_av(inode->i_mode, mask), NULL);
2711}
2712
2713static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
2714{
2715 const struct cred *cred = current_cred();
2716 unsigned int ia_valid = iattr->ia_valid;
2713
2717
2714 if (iattr->ia_valid & ATTR_FORCE)
2715 return 0;
2718 /* ATTR_FORCE is just used for ATTR_KILL_S[UG]ID. */
2719 if (ia_valid & ATTR_FORCE) {
2720 ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_MODE |
2721 ATTR_FORCE);
2722 if (!ia_valid)
2723 return 0;
2724 }
2716
2725
2717 if (iattr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2718 ATTR_ATIME_SET | ATTR_MTIME_SET))
2726 if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2727 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET))
2719 return dentry_has_perm(cred, NULL, dentry, FILE__SETATTR);
2720
2721 return dentry_has_perm(cred, NULL, dentry, FILE__WRITE);
2722}
2723
2724static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
2725{
2726 const struct cred *cred = current_cred();

--- 23 unchanged lines hidden (view full) ---

2750}
2751
2752static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2753 const void *value, size_t size, int flags)
2754{
2755 struct inode *inode = dentry->d_inode;
2756 struct inode_security_struct *isec = inode->i_security;
2757 struct superblock_security_struct *sbsec;
2728 return dentry_has_perm(cred, NULL, dentry, FILE__SETATTR);
2729
2730 return dentry_has_perm(cred, NULL, dentry, FILE__WRITE);
2731}
2732
2733static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
2734{
2735 const struct cred *cred = current_cred();

--- 23 unchanged lines hidden (view full) ---

2759}
2760
2761static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2762 const void *value, size_t size, int flags)
2763{
2764 struct inode *inode = dentry->d_inode;
2765 struct inode_security_struct *isec = inode->i_security;
2766 struct superblock_security_struct *sbsec;
2758 struct avc_audit_data ad;
2767 struct common_audit_data ad;
2759 u32 newsid, sid = current_sid();
2760 int rc = 0;
2761
2762 if (strcmp(name, XATTR_NAME_SELINUX))
2763 return selinux_inode_setotherxattr(dentry, name);
2764
2765 sbsec = inode->i_sb->s_security;
2766 if (!(sbsec->flags & SE_SBLABELSUPP))
2767 return -EOPNOTSUPP;
2768
2769 if (!is_owner_or_cap(inode))
2770 return -EPERM;
2771
2768 u32 newsid, sid = current_sid();
2769 int rc = 0;
2770
2771 if (strcmp(name, XATTR_NAME_SELINUX))
2772 return selinux_inode_setotherxattr(dentry, name);
2773
2774 sbsec = inode->i_sb->s_security;
2775 if (!(sbsec->flags & SE_SBLABELSUPP))
2776 return -EOPNOTSUPP;
2777
2778 if (!is_owner_or_cap(inode))
2779 return -EPERM;
2780
2772 AVC_AUDIT_DATA_INIT(&ad, FS);
2781 COMMON_AUDIT_DATA_INIT(&ad, FS);
2773 ad.u.fs.path.dentry = dentry;
2774
2775 rc = avc_has_perm(sid, isec->sid, isec->sclass,
2776 FILE__RELABELFROM, &ad);
2777 if (rc)
2778 return rc;
2779
2780 rc = security_context_to_sid(value, size, &newsid);

--- 152 unchanged lines hidden (view full) ---

2933
2934/* file security operations */
2935
2936static int selinux_revalidate_file_permission(struct file *file, int mask)
2937{
2938 const struct cred *cred = current_cred();
2939 struct inode *inode = file->f_path.dentry->d_inode;
2940
2782 ad.u.fs.path.dentry = dentry;
2783
2784 rc = avc_has_perm(sid, isec->sid, isec->sclass,
2785 FILE__RELABELFROM, &ad);
2786 if (rc)
2787 return rc;
2788
2789 rc = security_context_to_sid(value, size, &newsid);

--- 152 unchanged lines hidden (view full) ---

2942
2943/* file security operations */
2944
2945static int selinux_revalidate_file_permission(struct file *file, int mask)
2946{
2947 const struct cred *cred = current_cred();
2948 struct inode *inode = file->f_path.dentry->d_inode;
2949
2941 if (!mask) {
2942 /* No permission to check. Existence test. */
2943 return 0;
2944 }
2945
2946 /* file_mask_to_av won't add FILE__WRITE if MAY_APPEND is set */
2947 if ((file->f_flags & O_APPEND) && (mask & MAY_WRITE))
2948 mask |= MAY_APPEND;
2949
2950 return file_has_perm(cred, file,
2951 file_mask_to_av(inode->i_mode, mask));
2952}
2953
2954static int selinux_file_permission(struct file *file, int mask)
2955{
2950 /* file_mask_to_av won't add FILE__WRITE if MAY_APPEND is set */
2951 if ((file->f_flags & O_APPEND) && (mask & MAY_WRITE))
2952 mask |= MAY_APPEND;
2953
2954 return file_has_perm(cred, file,
2955 file_mask_to_av(inode->i_mode, mask));
2956}
2957
2958static int selinux_file_permission(struct file *file, int mask)
2959{
2960 struct inode *inode = file->f_path.dentry->d_inode;
2961 struct file_security_struct *fsec = file->f_security;
2962 struct inode_security_struct *isec = inode->i_security;
2963 u32 sid = current_sid();
2964
2956 if (!mask)
2957 /* No permission to check. Existence test. */
2958 return 0;
2959
2965 if (!mask)
2966 /* No permission to check. Existence test. */
2967 return 0;
2968
2969 if (sid == fsec->sid && fsec->isid == isec->sid &&
2970 fsec->pseqno == avc_policy_seqno())
2971 /* No change since dentry_open check. */
2972 return 0;
2973
2960 return selinux_revalidate_file_permission(file, mask);
2961}
2962
2963static int selinux_file_alloc_security(struct file *file)
2964{
2965 return file_alloc_security(file);
2966}
2967

--- 56 unchanged lines hidden (view full) ---

3024
3025static int selinux_file_mmap(struct file *file, unsigned long reqprot,
3026 unsigned long prot, unsigned long flags,
3027 unsigned long addr, unsigned long addr_only)
3028{
3029 int rc = 0;
3030 u32 sid = current_sid();
3031
2974 return selinux_revalidate_file_permission(file, mask);
2975}
2976
2977static int selinux_file_alloc_security(struct file *file)
2978{
2979 return file_alloc_security(file);
2980}
2981

--- 56 unchanged lines hidden (view full) ---

3038
3039static int selinux_file_mmap(struct file *file, unsigned long reqprot,
3040 unsigned long prot, unsigned long flags,
3041 unsigned long addr, unsigned long addr_only)
3042{
3043 int rc = 0;
3044 u32 sid = current_sid();
3045
3032 if (addr < mmap_min_addr)
3046 /*
3047 * notice that we are intentionally putting the SELinux check before
3048 * the secondary cap_file_mmap check. This is such a likely attempt
3049 * at bad behaviour/exploit that we always want to get the AVC, even
3050 * if DAC would have also denied the operation.
3051 */
3052 if (addr < CONFIG_LSM_MMAP_MIN_ADDR) {
3033 rc = avc_has_perm(sid, sid, SECCLASS_MEMPROTECT,
3034 MEMPROTECT__MMAP_ZERO, NULL);
3053 rc = avc_has_perm(sid, sid, SECCLASS_MEMPROTECT,
3054 MEMPROTECT__MMAP_ZERO, NULL);
3055 if (rc)
3056 return rc;
3057 }
3058
3059 /* do DAC check on address space usage */
3060 rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
3035 if (rc || addr_only)
3036 return rc;
3037
3038 if (selinux_checkreqprot)
3039 prot = reqprot;
3040
3041 return file_map_prot_check(file, prot,
3042 (flags & MAP_TYPE) == MAP_SHARED);

--- 159 unchanged lines hidden (view full) ---

3202/* task security operations */
3203
3204static int selinux_task_create(unsigned long clone_flags)
3205{
3206 return current_has_perm(current, PROCESS__FORK);
3207}
3208
3209/*
3061 if (rc || addr_only)
3062 return rc;
3063
3064 if (selinux_checkreqprot)
3065 prot = reqprot;
3066
3067 return file_map_prot_check(file, prot,
3068 (flags & MAP_TYPE) == MAP_SHARED);

--- 159 unchanged lines hidden (view full) ---

3228/* task security operations */
3229
3230static int selinux_task_create(unsigned long clone_flags)
3231{
3232 return current_has_perm(current, PROCESS__FORK);
3233}
3234
3235/*
3236 * allocate the SELinux part of blank credentials
3237 */
3238static int selinux_cred_alloc_blank(struct cred *cred, gfp_t gfp)
3239{
3240 struct task_security_struct *tsec;
3241
3242 tsec = kzalloc(sizeof(struct task_security_struct), gfp);
3243 if (!tsec)
3244 return -ENOMEM;
3245
3246 cred->security = tsec;
3247 return 0;
3248}
3249
3250/*
3210 * detach and free the LSM part of a set of credentials
3211 */
3212static void selinux_cred_free(struct cred *cred)
3213{
3214 struct task_security_struct *tsec = cred->security;
3251 * detach and free the LSM part of a set of credentials
3252 */
3253static void selinux_cred_free(struct cred *cred)
3254{
3255 struct task_security_struct *tsec = cred->security;
3215 cred->security = NULL;
3256
3257 BUG_ON((unsigned long) cred->security < PAGE_SIZE);
3258 cred->security = (void *) 0x7UL;
3216 kfree(tsec);
3217}
3218
3219/*
3220 * prepare a new set of credentials for modification
3221 */
3222static int selinux_cred_prepare(struct cred *new, const struct cred *old,
3223 gfp_t gfp)

--- 7 unchanged lines hidden (view full) ---

3231 if (!tsec)
3232 return -ENOMEM;
3233
3234 new->security = tsec;
3235 return 0;
3236}
3237
3238/*
3259 kfree(tsec);
3260}
3261
3262/*
3263 * prepare a new set of credentials for modification
3264 */
3265static int selinux_cred_prepare(struct cred *new, const struct cred *old,
3266 gfp_t gfp)

--- 7 unchanged lines hidden (view full) ---

3274 if (!tsec)
3275 return -ENOMEM;
3276
3277 new->security = tsec;
3278 return 0;
3279}
3280
3281/*
3282 * transfer the SELinux data to a blank set of creds
3283 */
3284static void selinux_cred_transfer(struct cred *new, const struct cred *old)
3285{
3286 const struct task_security_struct *old_tsec = old->security;
3287 struct task_security_struct *tsec = new->security;
3288
3289 *tsec = *old_tsec;
3290}
3291
3292/*
3239 * set the security data for a kernel service
3240 * - all the creation contexts are set to unlabelled
3241 */
3242static int selinux_kernel_act_as(struct cred *new, u32 secid)
3243{
3244 struct task_security_struct *tsec = new->security;
3245 u32 sid = current_sid();
3246 int ret;

--- 27 unchanged lines hidden (view full) ---

3274 KERNEL_SERVICE__CREATE_FILES_AS,
3275 NULL);
3276
3277 if (ret == 0)
3278 tsec->create_sid = isec->sid;
3279 return 0;
3280}
3281
3293 * set the security data for a kernel service
3294 * - all the creation contexts are set to unlabelled
3295 */
3296static int selinux_kernel_act_as(struct cred *new, u32 secid)
3297{
3298 struct task_security_struct *tsec = new->security;
3299 u32 sid = current_sid();
3300 int ret;

--- 27 unchanged lines hidden (view full) ---

3328 KERNEL_SERVICE__CREATE_FILES_AS,
3329 NULL);
3330
3331 if (ret == 0)
3332 tsec->create_sid = isec->sid;
3333 return 0;
3334}
3335
3336static int selinux_kernel_module_request(void)
3337{
3338 return task_has_system(current, SYSTEM__MODULE_REQUEST);
3339}
3340
3282static int selinux_task_setpgid(struct task_struct *p, pid_t pgid)
3283{
3284 return current_has_perm(p, PROCESS__SETPGID);
3285}
3286
3287static int selinux_task_getpgid(struct task_struct *p)
3288{
3289 return current_has_perm(p, PROCESS__GETPGID);

--- 101 unchanged lines hidden (view full) ---

3391 u32 sid = task_sid(p);
3392
3393 isec->sid = sid;
3394 isec->initialized = 1;
3395}
3396
3397/* Returns error only if unable to parse addresses */
3398static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3341static int selinux_task_setpgid(struct task_struct *p, pid_t pgid)
3342{
3343 return current_has_perm(p, PROCESS__SETPGID);
3344}
3345
3346static int selinux_task_getpgid(struct task_struct *p)
3347{
3348 return current_has_perm(p, PROCESS__GETPGID);

--- 101 unchanged lines hidden (view full) ---

3450 u32 sid = task_sid(p);
3451
3452 isec->sid = sid;
3453 isec->initialized = 1;
3454}
3455
3456/* Returns error only if unable to parse addresses */
3457static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3399 struct avc_audit_data *ad, u8 *proto)
3458 struct common_audit_data *ad, u8 *proto)
3400{
3401 int offset, ihlen, ret = -EINVAL;
3402 struct iphdr _iph, *ih;
3403
3404 offset = skb_network_offset(skb);
3405 ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
3406 if (ih == NULL)
3407 goto out;

--- 64 unchanged lines hidden (view full) ---

3472out:
3473 return ret;
3474}
3475
3476#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
3477
3478/* Returns error only if unable to parse addresses */
3479static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3459{
3460 int offset, ihlen, ret = -EINVAL;
3461 struct iphdr _iph, *ih;
3462
3463 offset = skb_network_offset(skb);
3464 ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
3465 if (ih == NULL)
3466 goto out;

--- 64 unchanged lines hidden (view full) ---

3531out:
3532 return ret;
3533}
3534
3535#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
3536
3537/* Returns error only if unable to parse addresses */
3538static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3480 struct avc_audit_data *ad, u8 *proto)
3539 struct common_audit_data *ad, u8 *proto)
3481{
3482 u8 nexthdr;
3483 int ret = -EINVAL, offset;
3484 struct ipv6hdr _ipv6h, *ip6;
3485
3486 offset = skb_network_offset(skb);
3487 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
3488 if (ip6 == NULL)

--- 54 unchanged lines hidden (view full) ---

3543 break;
3544 }
3545out:
3546 return ret;
3547}
3548
3549#endif /* IPV6 */
3550
3540{
3541 u8 nexthdr;
3542 int ret = -EINVAL, offset;
3543 struct ipv6hdr _ipv6h, *ip6;
3544
3545 offset = skb_network_offset(skb);
3546 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
3547 if (ip6 == NULL)

--- 54 unchanged lines hidden (view full) ---

3602 break;
3603 }
3604out:
3605 return ret;
3606}
3607
3608#endif /* IPV6 */
3609
3551static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,
3610static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
3552 char **_addrp, int src, u8 *proto)
3553{
3554 char *addrp;
3555 int ret;
3556
3557 switch (ad->u.net.family) {
3558 case PF_INET:
3559 ret = selinux_parse_skb_ipv4(skb, ad, proto);

--- 65 unchanged lines hidden (view full) ---

3625 return 0;
3626}
3627
3628/* socket security operations */
3629static int socket_has_perm(struct task_struct *task, struct socket *sock,
3630 u32 perms)
3631{
3632 struct inode_security_struct *isec;
3611 char **_addrp, int src, u8 *proto)
3612{
3613 char *addrp;
3614 int ret;
3615
3616 switch (ad->u.net.family) {
3617 case PF_INET:
3618 ret = selinux_parse_skb_ipv4(skb, ad, proto);

--- 65 unchanged lines hidden (view full) ---

3684 return 0;
3685}
3686
3687/* socket security operations */
3688static int socket_has_perm(struct task_struct *task, struct socket *sock,
3689 u32 perms)
3690{
3691 struct inode_security_struct *isec;
3633 struct avc_audit_data ad;
3692 struct common_audit_data ad;
3634 u32 sid;
3635 int err = 0;
3636
3637 isec = SOCK_INODE(sock)->i_security;
3638
3639 if (isec->sid == SECINITSID_KERNEL)
3640 goto out;
3641 sid = task_sid(task);
3642
3693 u32 sid;
3694 int err = 0;
3695
3696 isec = SOCK_INODE(sock)->i_security;
3697
3698 if (isec->sid == SECINITSID_KERNEL)
3699 goto out;
3700 sid = task_sid(task);
3701
3643 AVC_AUDIT_DATA_INIT(&ad, NET);
3702 COMMON_AUDIT_DATA_INIT(&ad, NET);
3644 ad.u.net.sk = sock->sk;
3645 err = avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
3646
3647out:
3648 return err;
3649}
3650
3651static int selinux_socket_create(int family, int type,

--- 70 unchanged lines hidden (view full) ---

3722 * If PF_INET or PF_INET6, check name_bind permission for the port.
3723 * Multiple address binding for SCTP is not supported yet: we just
3724 * check the first address now.
3725 */
3726 family = sock->sk->sk_family;
3727 if (family == PF_INET || family == PF_INET6) {
3728 char *addrp;
3729 struct inode_security_struct *isec;
3703 ad.u.net.sk = sock->sk;
3704 err = avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
3705
3706out:
3707 return err;
3708}
3709
3710static int selinux_socket_create(int family, int type,

--- 70 unchanged lines hidden (view full) ---

3781 * If PF_INET or PF_INET6, check name_bind permission for the port.
3782 * Multiple address binding for SCTP is not supported yet: we just
3783 * check the first address now.
3784 */
3785 family = sock->sk->sk_family;
3786 if (family == PF_INET || family == PF_INET6) {
3787 char *addrp;
3788 struct inode_security_struct *isec;
3730 struct avc_audit_data ad;
3789 struct common_audit_data ad;
3731 struct sockaddr_in *addr4 = NULL;
3732 struct sockaddr_in6 *addr6 = NULL;
3733 unsigned short snum;
3734 struct sock *sk = sock->sk;
3735 u32 sid, node_perm;
3736
3737 isec = SOCK_INODE(sock)->i_security;
3738

--- 12 unchanged lines hidden (view full) ---

3751
3752 inet_get_local_port_range(&low, &high);
3753
3754 if (snum < max(PROT_SOCK, low) || snum > high) {
3755 err = sel_netport_sid(sk->sk_protocol,
3756 snum, &sid);
3757 if (err)
3758 goto out;
3790 struct sockaddr_in *addr4 = NULL;
3791 struct sockaddr_in6 *addr6 = NULL;
3792 unsigned short snum;
3793 struct sock *sk = sock->sk;
3794 u32 sid, node_perm;
3795
3796 isec = SOCK_INODE(sock)->i_security;
3797

--- 12 unchanged lines hidden (view full) ---

3810
3811 inet_get_local_port_range(&low, &high);
3812
3813 if (snum < max(PROT_SOCK, low) || snum > high) {
3814 err = sel_netport_sid(sk->sk_protocol,
3815 snum, &sid);
3816 if (err)
3817 goto out;
3759 AVC_AUDIT_DATA_INIT(&ad, NET);
3818 COMMON_AUDIT_DATA_INIT(&ad, NET);
3760 ad.u.net.sport = htons(snum);
3761 ad.u.net.family = family;
3762 err = avc_has_perm(isec->sid, sid,
3763 isec->sclass,
3764 SOCKET__NAME_BIND, &ad);
3765 if (err)
3766 goto out;
3767 }

--- 16 unchanged lines hidden (view full) ---

3784 node_perm = RAWIP_SOCKET__NODE_BIND;
3785 break;
3786 }
3787
3788 err = sel_netnode_sid(addrp, family, &sid);
3789 if (err)
3790 goto out;
3791
3819 ad.u.net.sport = htons(snum);
3820 ad.u.net.family = family;
3821 err = avc_has_perm(isec->sid, sid,
3822 isec->sclass,
3823 SOCKET__NAME_BIND, &ad);
3824 if (err)
3825 goto out;
3826 }

--- 16 unchanged lines hidden (view full) ---

3843 node_perm = RAWIP_SOCKET__NODE_BIND;
3844 break;
3845 }
3846
3847 err = sel_netnode_sid(addrp, family, &sid);
3848 if (err)
3849 goto out;
3850
3792 AVC_AUDIT_DATA_INIT(&ad, NET);
3851 COMMON_AUDIT_DATA_INIT(&ad, NET);
3793 ad.u.net.sport = htons(snum);
3794 ad.u.net.family = family;
3795
3796 if (family == PF_INET)
3797 ad.u.net.v4info.saddr = addr4->sin_addr.s_addr;
3798 else
3799 ipv6_addr_copy(&ad.u.net.v6info.saddr, &addr6->sin6_addr);
3800

--- 17 unchanged lines hidden (view full) ---

3818 return err;
3819
3820 /*
3821 * If a TCP or DCCP socket, check name_connect permission for the port.
3822 */
3823 isec = SOCK_INODE(sock)->i_security;
3824 if (isec->sclass == SECCLASS_TCP_SOCKET ||
3825 isec->sclass == SECCLASS_DCCP_SOCKET) {
3852 ad.u.net.sport = htons(snum);
3853 ad.u.net.family = family;
3854
3855 if (family == PF_INET)
3856 ad.u.net.v4info.saddr = addr4->sin_addr.s_addr;
3857 else
3858 ipv6_addr_copy(&ad.u.net.v6info.saddr, &addr6->sin6_addr);
3859

--- 17 unchanged lines hidden (view full) ---

3877 return err;
3878
3879 /*
3880 * If a TCP or DCCP socket, check name_connect permission for the port.
3881 */
3882 isec = SOCK_INODE(sock)->i_security;
3883 if (isec->sclass == SECCLASS_TCP_SOCKET ||
3884 isec->sclass == SECCLASS_DCCP_SOCKET) {
3826 struct avc_audit_data ad;
3885 struct common_audit_data ad;
3827 struct sockaddr_in *addr4 = NULL;
3828 struct sockaddr_in6 *addr6 = NULL;
3829 unsigned short snum;
3830 u32 sid, perm;
3831
3832 if (sk->sk_family == PF_INET) {
3833 addr4 = (struct sockaddr_in *)address;
3834 if (addrlen < sizeof(struct sockaddr_in))

--- 8 unchanged lines hidden (view full) ---

3843
3844 err = sel_netport_sid(sk->sk_protocol, snum, &sid);
3845 if (err)
3846 goto out;
3847
3848 perm = (isec->sclass == SECCLASS_TCP_SOCKET) ?
3849 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3850
3886 struct sockaddr_in *addr4 = NULL;
3887 struct sockaddr_in6 *addr6 = NULL;
3888 unsigned short snum;
3889 u32 sid, perm;
3890
3891 if (sk->sk_family == PF_INET) {
3892 addr4 = (struct sockaddr_in *)address;
3893 if (addrlen < sizeof(struct sockaddr_in))

--- 8 unchanged lines hidden (view full) ---

3902
3903 err = sel_netport_sid(sk->sk_protocol, snum, &sid);
3904 if (err)
3905 goto out;
3906
3907 perm = (isec->sclass == SECCLASS_TCP_SOCKET) ?
3908 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3909
3851 AVC_AUDIT_DATA_INIT(&ad, NET);
3910 COMMON_AUDIT_DATA_INIT(&ad, NET);
3852 ad.u.net.dport = htons(snum);
3853 ad.u.net.family = sk->sk_family;
3854 err = avc_has_perm(isec->sid, sid, isec->sclass, perm, &ad);
3855 if (err)
3856 goto out;
3857 }
3858
3859 err = selinux_netlbl_socket_connect(sk, address);

--- 73 unchanged lines hidden (view full) ---

3933
3934static int selinux_socket_unix_stream_connect(struct socket *sock,
3935 struct socket *other,
3936 struct sock *newsk)
3937{
3938 struct sk_security_struct *ssec;
3939 struct inode_security_struct *isec;
3940 struct inode_security_struct *other_isec;
3911 ad.u.net.dport = htons(snum);
3912 ad.u.net.family = sk->sk_family;
3913 err = avc_has_perm(isec->sid, sid, isec->sclass, perm, &ad);
3914 if (err)
3915 goto out;
3916 }
3917
3918 err = selinux_netlbl_socket_connect(sk, address);

--- 73 unchanged lines hidden (view full) ---

3992
3993static int selinux_socket_unix_stream_connect(struct socket *sock,
3994 struct socket *other,
3995 struct sock *newsk)
3996{
3997 struct sk_security_struct *ssec;
3998 struct inode_security_struct *isec;
3999 struct inode_security_struct *other_isec;
3941 struct avc_audit_data ad;
4000 struct common_audit_data ad;
3942 int err;
3943
3944 isec = SOCK_INODE(sock)->i_security;
3945 other_isec = SOCK_INODE(other)->i_security;
3946
4001 int err;
4002
4003 isec = SOCK_INODE(sock)->i_security;
4004 other_isec = SOCK_INODE(other)->i_security;
4005
3947 AVC_AUDIT_DATA_INIT(&ad, NET);
4006 COMMON_AUDIT_DATA_INIT(&ad, NET);
3948 ad.u.net.sk = other->sk;
3949
3950 err = avc_has_perm(isec->sid, other_isec->sid,
3951 isec->sclass,
3952 UNIX_STREAM_SOCKET__CONNECTTO, &ad);
3953 if (err)
3954 return err;
3955

--- 9 unchanged lines hidden (view full) ---

3965 return err;
3966}
3967
3968static int selinux_socket_unix_may_send(struct socket *sock,
3969 struct socket *other)
3970{
3971 struct inode_security_struct *isec;
3972 struct inode_security_struct *other_isec;
4007 ad.u.net.sk = other->sk;
4008
4009 err = avc_has_perm(isec->sid, other_isec->sid,
4010 isec->sclass,
4011 UNIX_STREAM_SOCKET__CONNECTTO, &ad);
4012 if (err)
4013 return err;
4014

--- 9 unchanged lines hidden (view full) ---

4024 return err;
4025}
4026
4027static int selinux_socket_unix_may_send(struct socket *sock,
4028 struct socket *other)
4029{
4030 struct inode_security_struct *isec;
4031 struct inode_security_struct *other_isec;
3973 struct avc_audit_data ad;
4032 struct common_audit_data ad;
3974 int err;
3975
3976 isec = SOCK_INODE(sock)->i_security;
3977 other_isec = SOCK_INODE(other)->i_security;
3978
4033 int err;
4034
4035 isec = SOCK_INODE(sock)->i_security;
4036 other_isec = SOCK_INODE(other)->i_security;
4037
3979 AVC_AUDIT_DATA_INIT(&ad, NET);
4038 COMMON_AUDIT_DATA_INIT(&ad, NET);
3980 ad.u.net.sk = other->sk;
3981
3982 err = avc_has_perm(isec->sid, other_isec->sid,
3983 isec->sclass, SOCKET__SENDTO, &ad);
3984 if (err)
3985 return err;
3986
3987 return 0;
3988}
3989
3990static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
3991 u32 peer_sid,
4039 ad.u.net.sk = other->sk;
4040
4041 err = avc_has_perm(isec->sid, other_isec->sid,
4042 isec->sclass, SOCKET__SENDTO, &ad);
4043 if (err)
4044 return err;
4045
4046 return 0;
4047}
4048
4049static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
4050 u32 peer_sid,
3992 struct avc_audit_data *ad)
4051 struct common_audit_data *ad)
3993{
3994 int err;
3995 u32 if_sid;
3996 u32 node_sid;
3997
3998 err = sel_netif_sid(ifindex, &if_sid);
3999 if (err)
4000 return err;

--- 11 unchanged lines hidden (view full) ---

4012
4013static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4014 u16 family)
4015{
4016 int err = 0;
4017 struct sk_security_struct *sksec = sk->sk_security;
4018 u32 peer_sid;
4019 u32 sk_sid = sksec->sid;
4052{
4053 int err;
4054 u32 if_sid;
4055 u32 node_sid;
4056
4057 err = sel_netif_sid(ifindex, &if_sid);
4058 if (err)
4059 return err;

--- 11 unchanged lines hidden (view full) ---

4071
4072static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4073 u16 family)
4074{
4075 int err = 0;
4076 struct sk_security_struct *sksec = sk->sk_security;
4077 u32 peer_sid;
4078 u32 sk_sid = sksec->sid;
4020 struct avc_audit_data ad;
4079 struct common_audit_data ad;
4021 char *addrp;
4022
4080 char *addrp;
4081
4023 AVC_AUDIT_DATA_INIT(&ad, NET);
4082 COMMON_AUDIT_DATA_INIT(&ad, NET);
4024 ad.u.net.netif = skb->iif;
4025 ad.u.net.family = family;
4026 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4027 if (err)
4028 return err;
4029
4030 if (selinux_secmark_enabled()) {
4031 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET,

--- 21 unchanged lines hidden (view full) ---

4053}
4054
4055static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4056{
4057 int err;
4058 struct sk_security_struct *sksec = sk->sk_security;
4059 u16 family = sk->sk_family;
4060 u32 sk_sid = sksec->sid;
4083 ad.u.net.netif = skb->iif;
4084 ad.u.net.family = family;
4085 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4086 if (err)
4087 return err;
4088
4089 if (selinux_secmark_enabled()) {
4090 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET,

--- 21 unchanged lines hidden (view full) ---

4112}
4113
4114static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4115{
4116 int err;
4117 struct sk_security_struct *sksec = sk->sk_security;
4118 u16 family = sk->sk_family;
4119 u32 sk_sid = sksec->sid;
4061 struct avc_audit_data ad;
4120 struct common_audit_data ad;
4062 char *addrp;
4063 u8 secmark_active;
4064 u8 peerlbl_active;
4065
4066 if (family != PF_INET && family != PF_INET6)
4067 return 0;
4068
4069 /* Handle mapped IPv4 packets arriving via IPv6 sockets */

--- 7 unchanged lines hidden (view full) ---

4077 if (!selinux_policycap_netpeer)
4078 return selinux_sock_rcv_skb_compat(sk, skb, family);
4079
4080 secmark_active = selinux_secmark_enabled();
4081 peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled();
4082 if (!secmark_active && !peerlbl_active)
4083 return 0;
4084
4121 char *addrp;
4122 u8 secmark_active;
4123 u8 peerlbl_active;
4124
4125 if (family != PF_INET && family != PF_INET6)
4126 return 0;
4127
4128 /* Handle mapped IPv4 packets arriving via IPv6 sockets */

--- 7 unchanged lines hidden (view full) ---

4136 if (!selinux_policycap_netpeer)
4137 return selinux_sock_rcv_skb_compat(sk, skb, family);
4138
4139 secmark_active = selinux_secmark_enabled();
4140 peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled();
4141 if (!secmark_active && !peerlbl_active)
4142 return 0;
4143
4085 AVC_AUDIT_DATA_INIT(&ad, NET);
4144 COMMON_AUDIT_DATA_INIT(&ad, NET);
4086 ad.u.net.netif = skb->iif;
4087 ad.u.net.family = family;
4088 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4089 if (err)
4090 return err;
4091
4092 if (peerlbl_active) {
4093 u32 peer_sid;

--- 197 unchanged lines hidden (view full) ---

4291}
4292
4293static void selinux_req_classify_flow(const struct request_sock *req,
4294 struct flowi *fl)
4295{
4296 fl->secid = req->secid;
4297}
4298
4145 ad.u.net.netif = skb->iif;
4146 ad.u.net.family = family;
4147 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4148 if (err)
4149 return err;
4150
4151 if (peerlbl_active) {
4152 u32 peer_sid;

--- 197 unchanged lines hidden (view full) ---

4350}
4351
4352static void selinux_req_classify_flow(const struct request_sock *req,
4353 struct flowi *fl)
4354{
4355 fl->secid = req->secid;
4356}
4357
4358static int selinux_tun_dev_create(void)
4359{
4360 u32 sid = current_sid();
4361
4362 /* we aren't taking into account the "sockcreate" SID since the socket
4363 * that is being created here is not a socket in the traditional sense,
4364 * instead it is a private sock, accessible only to the kernel, and
4365 * representing a wide range of network traffic spanning multiple
4366 * connections unlike traditional sockets - check the TUN driver to
4367 * get a better understanding of why this socket is special */
4368
4369 return avc_has_perm(sid, sid, SECCLASS_TUN_SOCKET, TUN_SOCKET__CREATE,
4370 NULL);
4371}
4372
4373static void selinux_tun_dev_post_create(struct sock *sk)
4374{
4375 struct sk_security_struct *sksec = sk->sk_security;
4376
4377 /* we don't currently perform any NetLabel based labeling here and it
4378 * isn't clear that we would want to do so anyway; while we could apply
4379 * labeling without the support of the TUN user the resulting labeled
4380 * traffic from the other end of the connection would almost certainly
4381 * cause confusion to the TUN user that had no idea network labeling
4382 * protocols were being used */
4383
4384 /* see the comments in selinux_tun_dev_create() about why we don't use
4385 * the sockcreate SID here */
4386
4387 sksec->sid = current_sid();
4388 sksec->sclass = SECCLASS_TUN_SOCKET;
4389}
4390
4391static int selinux_tun_dev_attach(struct sock *sk)
4392{
4393 struct sk_security_struct *sksec = sk->sk_security;
4394 u32 sid = current_sid();
4395 int err;
4396
4397 err = avc_has_perm(sid, sksec->sid, SECCLASS_TUN_SOCKET,
4398 TUN_SOCKET__RELABELFROM, NULL);
4399 if (err)
4400 return err;
4401 err = avc_has_perm(sid, sid, SECCLASS_TUN_SOCKET,
4402 TUN_SOCKET__RELABELTO, NULL);
4403 if (err)
4404 return err;
4405
4406 sksec->sid = sid;
4407
4408 return 0;
4409}
4410
4299static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
4300{
4301 int err = 0;
4302 u32 perm;
4303 struct nlmsghdr *nlh;
4304 struct socket *sock = sk->sk_socket;
4305 struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
4306

--- 28 unchanged lines hidden (view full) ---

4335#ifdef CONFIG_NETFILTER
4336
4337static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4338 u16 family)
4339{
4340 int err;
4341 char *addrp;
4342 u32 peer_sid;
4411static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
4412{
4413 int err = 0;
4414 u32 perm;
4415 struct nlmsghdr *nlh;
4416 struct socket *sock = sk->sk_socket;
4417 struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
4418

--- 28 unchanged lines hidden (view full) ---

4447#ifdef CONFIG_NETFILTER
4448
4449static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4450 u16 family)
4451{
4452 int err;
4453 char *addrp;
4454 u32 peer_sid;
4343 struct avc_audit_data ad;
4455 struct common_audit_data ad;
4344 u8 secmark_active;
4345 u8 netlbl_active;
4346 u8 peerlbl_active;
4347
4348 if (!selinux_policycap_netpeer)
4349 return NF_ACCEPT;
4350
4351 secmark_active = selinux_secmark_enabled();
4352 netlbl_active = netlbl_enabled();
4353 peerlbl_active = netlbl_active || selinux_xfrm_enabled();
4354 if (!secmark_active && !peerlbl_active)
4355 return NF_ACCEPT;
4356
4357 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0)
4358 return NF_DROP;
4359
4456 u8 secmark_active;
4457 u8 netlbl_active;
4458 u8 peerlbl_active;
4459
4460 if (!selinux_policycap_netpeer)
4461 return NF_ACCEPT;
4462
4463 secmark_active = selinux_secmark_enabled();
4464 netlbl_active = netlbl_enabled();
4465 peerlbl_active = netlbl_active || selinux_xfrm_enabled();
4466 if (!secmark_active && !peerlbl_active)
4467 return NF_ACCEPT;
4468
4469 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0)
4470 return NF_DROP;
4471
4360 AVC_AUDIT_DATA_INIT(&ad, NET);
4472 COMMON_AUDIT_DATA_INIT(&ad, NET);
4361 ad.u.net.netif = ifindex;
4362 ad.u.net.family = family;
4363 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
4364 return NF_DROP;
4365
4366 if (peerlbl_active) {
4367 err = selinux_inet_sys_rcv_skb(ifindex, addrp, family,
4368 peer_sid, &ad);

--- 71 unchanged lines hidden (view full) ---

4440}
4441
4442static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4443 int ifindex,
4444 u16 family)
4445{
4446 struct sock *sk = skb->sk;
4447 struct sk_security_struct *sksec;
4473 ad.u.net.netif = ifindex;
4474 ad.u.net.family = family;
4475 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
4476 return NF_DROP;
4477
4478 if (peerlbl_active) {
4479 err = selinux_inet_sys_rcv_skb(ifindex, addrp, family,
4480 peer_sid, &ad);

--- 71 unchanged lines hidden (view full) ---

4552}
4553
4554static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4555 int ifindex,
4556 u16 family)
4557{
4558 struct sock *sk = skb->sk;
4559 struct sk_security_struct *sksec;
4448 struct avc_audit_data ad;
4560 struct common_audit_data ad;
4449 char *addrp;
4450 u8 proto;
4451
4452 if (sk == NULL)
4453 return NF_ACCEPT;
4454 sksec = sk->sk_security;
4455
4561 char *addrp;
4562 u8 proto;
4563
4564 if (sk == NULL)
4565 return NF_ACCEPT;
4566 sksec = sk->sk_security;
4567
4456 AVC_AUDIT_DATA_INIT(&ad, NET);
4568 COMMON_AUDIT_DATA_INIT(&ad, NET);
4457 ad.u.net.netif = ifindex;
4458 ad.u.net.family = family;
4459 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4460 return NF_DROP;
4461
4462 if (selinux_secmark_enabled())
4463 if (avc_has_perm(sksec->sid, skb->secmark,
4464 SECCLASS_PACKET, PACKET__SEND, &ad))

--- 7 unchanged lines hidden (view full) ---

4472}
4473
4474static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4475 u16 family)
4476{
4477 u32 secmark_perm;
4478 u32 peer_sid;
4479 struct sock *sk;
4569 ad.u.net.netif = ifindex;
4570 ad.u.net.family = family;
4571 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4572 return NF_DROP;
4573
4574 if (selinux_secmark_enabled())
4575 if (avc_has_perm(sksec->sid, skb->secmark,
4576 SECCLASS_PACKET, PACKET__SEND, &ad))

--- 7 unchanged lines hidden (view full) ---

4584}
4585
4586static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4587 u16 family)
4588{
4589 u32 secmark_perm;
4590 u32 peer_sid;
4591 struct sock *sk;
4480 struct avc_audit_data ad;
4592 struct common_audit_data ad;
4481 char *addrp;
4482 u8 secmark_active;
4483 u8 peerlbl_active;
4484
4485 /* If any sort of compatibility mode is enabled then handoff processing
4486 * to the selinux_ip_postroute_compat() function to deal with the
4487 * special handling. We do this in an attempt to keep this function
4488 * as fast and as clean as possible. */

--- 42 unchanged lines hidden (view full) ---

4531 } else
4532 peer_sid = SECINITSID_KERNEL;
4533 } else {
4534 struct sk_security_struct *sksec = sk->sk_security;
4535 peer_sid = sksec->sid;
4536 secmark_perm = PACKET__SEND;
4537 }
4538
4593 char *addrp;
4594 u8 secmark_active;
4595 u8 peerlbl_active;
4596
4597 /* If any sort of compatibility mode is enabled then handoff processing
4598 * to the selinux_ip_postroute_compat() function to deal with the
4599 * special handling. We do this in an attempt to keep this function
4600 * as fast and as clean as possible. */

--- 42 unchanged lines hidden (view full) ---

4643 } else
4644 peer_sid = SECINITSID_KERNEL;
4645 } else {
4646 struct sk_security_struct *sksec = sk->sk_security;
4647 peer_sid = sksec->sid;
4648 secmark_perm = PACKET__SEND;
4649 }
4650
4539 AVC_AUDIT_DATA_INIT(&ad, NET);
4651 COMMON_AUDIT_DATA_INIT(&ad, NET);
4540 ad.u.net.netif = ifindex;
4541 ad.u.net.family = family;
4542 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
4543 return NF_DROP;
4544
4545 if (secmark_active)
4546 if (avc_has_perm(peer_sid, skb->secmark,
4547 SECCLASS_PACKET, secmark_perm, &ad))

--- 53 unchanged lines hidden (view full) ---

4601 err = selinux_nlmsg_perm(sk, skb);
4602
4603 return err;
4604}
4605
4606static int selinux_netlink_recv(struct sk_buff *skb, int capability)
4607{
4608 int err;
4652 ad.u.net.netif = ifindex;
4653 ad.u.net.family = family;
4654 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
4655 return NF_DROP;
4656
4657 if (secmark_active)
4658 if (avc_has_perm(peer_sid, skb->secmark,
4659 SECCLASS_PACKET, secmark_perm, &ad))

--- 53 unchanged lines hidden (view full) ---

4713 err = selinux_nlmsg_perm(sk, skb);
4714
4715 return err;
4716}
4717
4718static int selinux_netlink_recv(struct sk_buff *skb, int capability)
4719{
4720 int err;
4609 struct avc_audit_data ad;
4721 struct common_audit_data ad;
4610
4611 err = cap_netlink_recv(skb, capability);
4612 if (err)
4613 return err;
4614
4722
4723 err = cap_netlink_recv(skb, capability);
4724 if (err)
4725 return err;
4726
4615 AVC_AUDIT_DATA_INIT(&ad, CAP);
4727 COMMON_AUDIT_DATA_INIT(&ad, CAP);
4616 ad.u.cap = capability;
4617
4618 return avc_has_perm(NETLINK_CB(skb).sid, NETLINK_CB(skb).sid,
4619 SECCLASS_CAPABILITY, CAP_TO_MASK(capability), &ad);
4620}
4621
4622static int ipc_alloc_security(struct task_struct *task,
4623 struct kern_ipc_perm *perm,

--- 42 unchanged lines hidden (view full) ---

4666 msg->security = NULL;
4667 kfree(msec);
4668}
4669
4670static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4671 u32 perms)
4672{
4673 struct ipc_security_struct *isec;
4728 ad.u.cap = capability;
4729
4730 return avc_has_perm(NETLINK_CB(skb).sid, NETLINK_CB(skb).sid,
4731 SECCLASS_CAPABILITY, CAP_TO_MASK(capability), &ad);
4732}
4733
4734static int ipc_alloc_security(struct task_struct *task,
4735 struct kern_ipc_perm *perm,

--- 42 unchanged lines hidden (view full) ---

4778 msg->security = NULL;
4779 kfree(msec);
4780}
4781
4782static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4783 u32 perms)
4784{
4785 struct ipc_security_struct *isec;
4674 struct avc_audit_data ad;
4786 struct common_audit_data ad;
4675 u32 sid = current_sid();
4676
4677 isec = ipc_perms->security;
4678
4787 u32 sid = current_sid();
4788
4789 isec = ipc_perms->security;
4790
4679 AVC_AUDIT_DATA_INIT(&ad, IPC);
4791 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4680 ad.u.ipc_id = ipc_perms->key;
4681
4682 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
4683}
4684
4685static int selinux_msg_msg_alloc_security(struct msg_msg *msg)
4686{
4687 return msg_msg_alloc_security(msg);
4688}
4689
4690static void selinux_msg_msg_free_security(struct msg_msg *msg)
4691{
4692 msg_msg_free_security(msg);
4693}
4694
4695/* message queue security operations */
4696static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4697{
4698 struct ipc_security_struct *isec;
4792 ad.u.ipc_id = ipc_perms->key;
4793
4794 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
4795}
4796
4797static int selinux_msg_msg_alloc_security(struct msg_msg *msg)
4798{
4799 return msg_msg_alloc_security(msg);
4800}
4801
4802static void selinux_msg_msg_free_security(struct msg_msg *msg)
4803{
4804 msg_msg_free_security(msg);
4805}
4806
4807/* message queue security operations */
4808static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4809{
4810 struct ipc_security_struct *isec;
4699 struct avc_audit_data ad;
4811 struct common_audit_data ad;
4700 u32 sid = current_sid();
4701 int rc;
4702
4703 rc = ipc_alloc_security(current, &msq->q_perm, SECCLASS_MSGQ);
4704 if (rc)
4705 return rc;
4706
4707 isec = msq->q_perm.security;
4708
4812 u32 sid = current_sid();
4813 int rc;
4814
4815 rc = ipc_alloc_security(current, &msq->q_perm, SECCLASS_MSGQ);
4816 if (rc)
4817 return rc;
4818
4819 isec = msq->q_perm.security;
4820
4709 AVC_AUDIT_DATA_INIT(&ad, IPC);
4821 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4710 ad.u.ipc_id = msq->q_perm.key;
4711
4712 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4713 MSGQ__CREATE, &ad);
4714 if (rc) {
4715 ipc_free_security(&msq->q_perm);
4716 return rc;
4717 }
4718 return 0;
4719}
4720
4721static void selinux_msg_queue_free_security(struct msg_queue *msq)
4722{
4723 ipc_free_security(&msq->q_perm);
4724}
4725
4726static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4727{
4728 struct ipc_security_struct *isec;
4822 ad.u.ipc_id = msq->q_perm.key;
4823
4824 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4825 MSGQ__CREATE, &ad);
4826 if (rc) {
4827 ipc_free_security(&msq->q_perm);
4828 return rc;
4829 }
4830 return 0;
4831}
4832
4833static void selinux_msg_queue_free_security(struct msg_queue *msq)
4834{
4835 ipc_free_security(&msq->q_perm);
4836}
4837
4838static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4839{
4840 struct ipc_security_struct *isec;
4729 struct avc_audit_data ad;
4841 struct common_audit_data ad;
4730 u32 sid = current_sid();
4731
4732 isec = msq->q_perm.security;
4733
4842 u32 sid = current_sid();
4843
4844 isec = msq->q_perm.security;
4845
4734 AVC_AUDIT_DATA_INIT(&ad, IPC);
4846 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4735 ad.u.ipc_id = msq->q_perm.key;
4736
4737 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4738 MSGQ__ASSOCIATE, &ad);
4739}
4740
4741static int selinux_msg_queue_msgctl(struct msg_queue *msq, int cmd)
4742{

--- 22 unchanged lines hidden (view full) ---

4765 err = ipc_has_perm(&msq->q_perm, perms);
4766 return err;
4767}
4768
4769static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, int msqflg)
4770{
4771 struct ipc_security_struct *isec;
4772 struct msg_security_struct *msec;
4847 ad.u.ipc_id = msq->q_perm.key;
4848
4849 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4850 MSGQ__ASSOCIATE, &ad);
4851}
4852
4853static int selinux_msg_queue_msgctl(struct msg_queue *msq, int cmd)
4854{

--- 22 unchanged lines hidden (view full) ---

4877 err = ipc_has_perm(&msq->q_perm, perms);
4878 return err;
4879}
4880
4881static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, int msqflg)
4882{
4883 struct ipc_security_struct *isec;
4884 struct msg_security_struct *msec;
4773 struct avc_audit_data ad;
4885 struct common_audit_data ad;
4774 u32 sid = current_sid();
4775 int rc;
4776
4777 isec = msq->q_perm.security;
4778 msec = msg->security;
4779
4780 /*
4781 * First time through, need to assign label to the message

--- 4 unchanged lines hidden (view full) ---

4786 * message queue this message will be stored in
4787 */
4788 rc = security_transition_sid(sid, isec->sid, SECCLASS_MSG,
4789 &msec->sid);
4790 if (rc)
4791 return rc;
4792 }
4793
4886 u32 sid = current_sid();
4887 int rc;
4888
4889 isec = msq->q_perm.security;
4890 msec = msg->security;
4891
4892 /*
4893 * First time through, need to assign label to the message

--- 4 unchanged lines hidden (view full) ---

4898 * message queue this message will be stored in
4899 */
4900 rc = security_transition_sid(sid, isec->sid, SECCLASS_MSG,
4901 &msec->sid);
4902 if (rc)
4903 return rc;
4904 }
4905
4794 AVC_AUDIT_DATA_INIT(&ad, IPC);
4906 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4795 ad.u.ipc_id = msq->q_perm.key;
4796
4797 /* Can this process write to the queue? */
4798 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4799 MSGQ__WRITE, &ad);
4800 if (!rc)
4801 /* Can this process send the message */
4802 rc = avc_has_perm(sid, msec->sid, SECCLASS_MSG,

--- 7 unchanged lines hidden (view full) ---

4810}
4811
4812static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4813 struct task_struct *target,
4814 long type, int mode)
4815{
4816 struct ipc_security_struct *isec;
4817 struct msg_security_struct *msec;
4907 ad.u.ipc_id = msq->q_perm.key;
4908
4909 /* Can this process write to the queue? */
4910 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
4911 MSGQ__WRITE, &ad);
4912 if (!rc)
4913 /* Can this process send the message */
4914 rc = avc_has_perm(sid, msec->sid, SECCLASS_MSG,

--- 7 unchanged lines hidden (view full) ---

4922}
4923
4924static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4925 struct task_struct *target,
4926 long type, int mode)
4927{
4928 struct ipc_security_struct *isec;
4929 struct msg_security_struct *msec;
4818 struct avc_audit_data ad;
4930 struct common_audit_data ad;
4819 u32 sid = task_sid(target);
4820 int rc;
4821
4822 isec = msq->q_perm.security;
4823 msec = msg->security;
4824
4931 u32 sid = task_sid(target);
4932 int rc;
4933
4934 isec = msq->q_perm.security;
4935 msec = msg->security;
4936
4825 AVC_AUDIT_DATA_INIT(&ad, IPC);
4937 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4826 ad.u.ipc_id = msq->q_perm.key;
4827
4828 rc = avc_has_perm(sid, isec->sid,
4829 SECCLASS_MSGQ, MSGQ__READ, &ad);
4830 if (!rc)
4831 rc = avc_has_perm(sid, msec->sid,
4832 SECCLASS_MSG, MSG__RECEIVE, &ad);
4833 return rc;
4834}
4835
4836/* Shared Memory security operations */
4837static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4838{
4839 struct ipc_security_struct *isec;
4938 ad.u.ipc_id = msq->q_perm.key;
4939
4940 rc = avc_has_perm(sid, isec->sid,
4941 SECCLASS_MSGQ, MSGQ__READ, &ad);
4942 if (!rc)
4943 rc = avc_has_perm(sid, msec->sid,
4944 SECCLASS_MSG, MSG__RECEIVE, &ad);
4945 return rc;
4946}
4947
4948/* Shared Memory security operations */
4949static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4950{
4951 struct ipc_security_struct *isec;
4840 struct avc_audit_data ad;
4952 struct common_audit_data ad;
4841 u32 sid = current_sid();
4842 int rc;
4843
4844 rc = ipc_alloc_security(current, &shp->shm_perm, SECCLASS_SHM);
4845 if (rc)
4846 return rc;
4847
4848 isec = shp->shm_perm.security;
4849
4953 u32 sid = current_sid();
4954 int rc;
4955
4956 rc = ipc_alloc_security(current, &shp->shm_perm, SECCLASS_SHM);
4957 if (rc)
4958 return rc;
4959
4960 isec = shp->shm_perm.security;
4961
4850 AVC_AUDIT_DATA_INIT(&ad, IPC);
4962 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4851 ad.u.ipc_id = shp->shm_perm.key;
4852
4853 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
4854 SHM__CREATE, &ad);
4855 if (rc) {
4856 ipc_free_security(&shp->shm_perm);
4857 return rc;
4858 }
4859 return 0;
4860}
4861
4862static void selinux_shm_free_security(struct shmid_kernel *shp)
4863{
4864 ipc_free_security(&shp->shm_perm);
4865}
4866
4867static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
4868{
4869 struct ipc_security_struct *isec;
4963 ad.u.ipc_id = shp->shm_perm.key;
4964
4965 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
4966 SHM__CREATE, &ad);
4967 if (rc) {
4968 ipc_free_security(&shp->shm_perm);
4969 return rc;
4970 }
4971 return 0;
4972}
4973
4974static void selinux_shm_free_security(struct shmid_kernel *shp)
4975{
4976 ipc_free_security(&shp->shm_perm);
4977}
4978
4979static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
4980{
4981 struct ipc_security_struct *isec;
4870 struct avc_audit_data ad;
4982 struct common_audit_data ad;
4871 u32 sid = current_sid();
4872
4873 isec = shp->shm_perm.security;
4874
4983 u32 sid = current_sid();
4984
4985 isec = shp->shm_perm.security;
4986
4875 AVC_AUDIT_DATA_INIT(&ad, IPC);
4987 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4876 ad.u.ipc_id = shp->shm_perm.key;
4877
4878 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
4879 SHM__ASSOCIATE, &ad);
4880}
4881
4882/* Note, at this point, shp is locked down */
4883static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd)

--- 40 unchanged lines hidden (view full) ---

4924
4925 return ipc_has_perm(&shp->shm_perm, perms);
4926}
4927
4928/* Semaphore security operations */
4929static int selinux_sem_alloc_security(struct sem_array *sma)
4930{
4931 struct ipc_security_struct *isec;
4988 ad.u.ipc_id = shp->shm_perm.key;
4989
4990 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
4991 SHM__ASSOCIATE, &ad);
4992}
4993
4994/* Note, at this point, shp is locked down */
4995static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd)

--- 40 unchanged lines hidden (view full) ---

5036
5037 return ipc_has_perm(&shp->shm_perm, perms);
5038}
5039
5040/* Semaphore security operations */
5041static int selinux_sem_alloc_security(struct sem_array *sma)
5042{
5043 struct ipc_security_struct *isec;
4932 struct avc_audit_data ad;
5044 struct common_audit_data ad;
4933 u32 sid = current_sid();
4934 int rc;
4935
4936 rc = ipc_alloc_security(current, &sma->sem_perm, SECCLASS_SEM);
4937 if (rc)
4938 return rc;
4939
4940 isec = sma->sem_perm.security;
4941
5045 u32 sid = current_sid();
5046 int rc;
5047
5048 rc = ipc_alloc_security(current, &sma->sem_perm, SECCLASS_SEM);
5049 if (rc)
5050 return rc;
5051
5052 isec = sma->sem_perm.security;
5053
4942 AVC_AUDIT_DATA_INIT(&ad, IPC);
5054 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4943 ad.u.ipc_id = sma->sem_perm.key;
4944
4945 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
4946 SEM__CREATE, &ad);
4947 if (rc) {
4948 ipc_free_security(&sma->sem_perm);
4949 return rc;
4950 }
4951 return 0;
4952}
4953
4954static void selinux_sem_free_security(struct sem_array *sma)
4955{
4956 ipc_free_security(&sma->sem_perm);
4957}
4958
4959static int selinux_sem_associate(struct sem_array *sma, int semflg)
4960{
4961 struct ipc_security_struct *isec;
5055 ad.u.ipc_id = sma->sem_perm.key;
5056
5057 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
5058 SEM__CREATE, &ad);
5059 if (rc) {
5060 ipc_free_security(&sma->sem_perm);
5061 return rc;
5062 }
5063 return 0;
5064}
5065
5066static void selinux_sem_free_security(struct sem_array *sma)
5067{
5068 ipc_free_security(&sma->sem_perm);
5069}
5070
5071static int selinux_sem_associate(struct sem_array *sma, int semflg)
5072{
5073 struct ipc_security_struct *isec;
4962 struct avc_audit_data ad;
5074 struct common_audit_data ad;
4963 u32 sid = current_sid();
4964
4965 isec = sma->sem_perm.security;
4966
5075 u32 sid = current_sid();
5076
5077 isec = sma->sem_perm.security;
5078
4967 AVC_AUDIT_DATA_INIT(&ad, IPC);
5079 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4968 ad.u.ipc_id = sma->sem_perm.key;
4969
4970 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
4971 SEM__ASSOCIATE, &ad);
4972}
4973
4974/* Note, at this point, sma is locked down */
4975static int selinux_sem_semctl(struct sem_array *sma, int cmd)

--- 201 unchanged lines hidden (view full) ---

5177 tsec->sockcreate_sid = sid;
5178 } else if (!strcmp(name, "current")) {
5179 error = -EINVAL;
5180 if (sid == 0)
5181 goto abort_change;
5182
5183 /* Only allow single threaded processes to change context */
5184 error = -EPERM;
5080 ad.u.ipc_id = sma->sem_perm.key;
5081
5082 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
5083 SEM__ASSOCIATE, &ad);
5084}
5085
5086/* Note, at this point, sma is locked down */
5087static int selinux_sem_semctl(struct sem_array *sma, int cmd)

--- 201 unchanged lines hidden (view full) ---

5289 tsec->sockcreate_sid = sid;
5290 } else if (!strcmp(name, "current")) {
5291 error = -EINVAL;
5292 if (sid == 0)
5293 goto abort_change;
5294
5295 /* Only allow single threaded processes to change context */
5296 error = -EPERM;
5185 if (!is_single_threaded(p)) {
5297 if (!current_is_single_threaded()) {
5186 error = security_bounded_transition(tsec->sid, sid);
5187 if (error)
5188 goto abort_change;
5189 }
5190
5191 /* Check permissions for the transition. */
5192 error = avc_has_perm(tsec->sid, sid, SECCLASS_PROCESS,
5193 PROCESS__DYNTRANSITION, NULL);

--- 40 unchanged lines hidden (view full) ---

5234 return security_context_to_sid(secdata, seclen, secid);
5235}
5236
5237static void selinux_release_secctx(char *secdata, u32 seclen)
5238{
5239 kfree(secdata);
5240}
5241
5298 error = security_bounded_transition(tsec->sid, sid);
5299 if (error)
5300 goto abort_change;
5301 }
5302
5303 /* Check permissions for the transition. */
5304 error = avc_has_perm(tsec->sid, sid, SECCLASS_PROCESS,
5305 PROCESS__DYNTRANSITION, NULL);

--- 40 unchanged lines hidden (view full) ---

5346 return security_context_to_sid(secdata, seclen, secid);
5347}
5348
5349static void selinux_release_secctx(char *secdata, u32 seclen)
5350{
5351 kfree(secdata);
5352}
5353
5354/*
5355 * called with inode->i_mutex locked
5356 */
5357static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
5358{
5359 return selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, ctx, ctxlen, 0);
5360}
5361
5362/*
5363 * called with inode->i_mutex locked
5364 */
5365static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
5366{
5367 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SELINUX, ctx, ctxlen, 0);
5368}
5369
5370static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
5371{
5372 int len = 0;
5373 len = selinux_inode_getsecurity(inode, XATTR_SELINUX_SUFFIX,
5374 ctx, true);
5375 if (len < 0)
5376 return len;
5377 *ctxlen = len;
5378 return 0;
5379}
5242#ifdef CONFIG_KEYS
5243
5244static int selinux_key_alloc(struct key *k, const struct cred *cred,
5245 unsigned long flags)
5246{
5247 const struct task_security_struct *tsec;
5248 struct key_security_struct *ksec;
5249

--- 55 unchanged lines hidden (view full) ---

5305 return rc;
5306}
5307
5308#endif
5309
5310static struct security_operations selinux_ops = {
5311 .name = "selinux",
5312
5380#ifdef CONFIG_KEYS
5381
5382static int selinux_key_alloc(struct key *k, const struct cred *cred,
5383 unsigned long flags)
5384{
5385 const struct task_security_struct *tsec;
5386 struct key_security_struct *ksec;
5387

--- 55 unchanged lines hidden (view full) ---

5443 return rc;
5444}
5445
5446#endif
5447
5448static struct security_operations selinux_ops = {
5449 .name = "selinux",
5450
5313 .ptrace_may_access = selinux_ptrace_may_access,
5451 .ptrace_access_check = selinux_ptrace_access_check,
5314 .ptrace_traceme = selinux_ptrace_traceme,
5315 .capget = selinux_capget,
5316 .capset = selinux_capset,
5317 .sysctl = selinux_sysctl,
5318 .capable = selinux_capable,
5319 .quotactl = selinux_quotactl,
5320 .quota_on = selinux_quota_on,
5321 .syslog = selinux_syslog,

--- 56 unchanged lines hidden (view full) ---

5378 .file_fcntl = selinux_file_fcntl,
5379 .file_set_fowner = selinux_file_set_fowner,
5380 .file_send_sigiotask = selinux_file_send_sigiotask,
5381 .file_receive = selinux_file_receive,
5382
5383 .dentry_open = selinux_dentry_open,
5384
5385 .task_create = selinux_task_create,
5452 .ptrace_traceme = selinux_ptrace_traceme,
5453 .capget = selinux_capget,
5454 .capset = selinux_capset,
5455 .sysctl = selinux_sysctl,
5456 .capable = selinux_capable,
5457 .quotactl = selinux_quotactl,
5458 .quota_on = selinux_quota_on,
5459 .syslog = selinux_syslog,

--- 56 unchanged lines hidden (view full) ---

5516 .file_fcntl = selinux_file_fcntl,
5517 .file_set_fowner = selinux_file_set_fowner,
5518 .file_send_sigiotask = selinux_file_send_sigiotask,
5519 .file_receive = selinux_file_receive,
5520
5521 .dentry_open = selinux_dentry_open,
5522
5523 .task_create = selinux_task_create,
5524 .cred_alloc_blank = selinux_cred_alloc_blank,
5386 .cred_free = selinux_cred_free,
5387 .cred_prepare = selinux_cred_prepare,
5525 .cred_free = selinux_cred_free,
5526 .cred_prepare = selinux_cred_prepare,
5527 .cred_transfer = selinux_cred_transfer,
5388 .kernel_act_as = selinux_kernel_act_as,
5389 .kernel_create_files_as = selinux_kernel_create_files_as,
5528 .kernel_act_as = selinux_kernel_act_as,
5529 .kernel_create_files_as = selinux_kernel_create_files_as,
5530 .kernel_module_request = selinux_kernel_module_request,
5390 .task_setpgid = selinux_task_setpgid,
5391 .task_getpgid = selinux_task_getpgid,
5392 .task_getsid = selinux_task_getsid,
5393 .task_getsecid = selinux_task_getsecid,
5394 .task_setnice = selinux_task_setnice,
5395 .task_setioprio = selinux_task_setioprio,
5396 .task_getioprio = selinux_task_getioprio,
5397 .task_setrlimit = selinux_task_setrlimit,

--- 32 unchanged lines hidden (view full) ---

5430 .d_instantiate = selinux_d_instantiate,
5431
5432 .getprocattr = selinux_getprocattr,
5433 .setprocattr = selinux_setprocattr,
5434
5435 .secid_to_secctx = selinux_secid_to_secctx,
5436 .secctx_to_secid = selinux_secctx_to_secid,
5437 .release_secctx = selinux_release_secctx,
5531 .task_setpgid = selinux_task_setpgid,
5532 .task_getpgid = selinux_task_getpgid,
5533 .task_getsid = selinux_task_getsid,
5534 .task_getsecid = selinux_task_getsecid,
5535 .task_setnice = selinux_task_setnice,
5536 .task_setioprio = selinux_task_setioprio,
5537 .task_getioprio = selinux_task_getioprio,
5538 .task_setrlimit = selinux_task_setrlimit,

--- 32 unchanged lines hidden (view full) ---

5571 .d_instantiate = selinux_d_instantiate,
5572
5573 .getprocattr = selinux_getprocattr,
5574 .setprocattr = selinux_setprocattr,
5575
5576 .secid_to_secctx = selinux_secid_to_secctx,
5577 .secctx_to_secid = selinux_secctx_to_secid,
5578 .release_secctx = selinux_release_secctx,
5579 .inode_notifysecctx = selinux_inode_notifysecctx,
5580 .inode_setsecctx = selinux_inode_setsecctx,
5581 .inode_getsecctx = selinux_inode_getsecctx,
5438
5439 .unix_stream_connect = selinux_socket_unix_stream_connect,
5440 .unix_may_send = selinux_socket_unix_may_send,
5441
5442 .socket_create = selinux_socket_create,
5443 .socket_post_create = selinux_socket_post_create,
5444 .socket_bind = selinux_socket_bind,
5445 .socket_connect = selinux_socket_connect,

--- 13 unchanged lines hidden (view full) ---

5459 .sk_free_security = selinux_sk_free_security,
5460 .sk_clone_security = selinux_sk_clone_security,
5461 .sk_getsecid = selinux_sk_getsecid,
5462 .sock_graft = selinux_sock_graft,
5463 .inet_conn_request = selinux_inet_conn_request,
5464 .inet_csk_clone = selinux_inet_csk_clone,
5465 .inet_conn_established = selinux_inet_conn_established,
5466 .req_classify_flow = selinux_req_classify_flow,
5582
5583 .unix_stream_connect = selinux_socket_unix_stream_connect,
5584 .unix_may_send = selinux_socket_unix_may_send,
5585
5586 .socket_create = selinux_socket_create,
5587 .socket_post_create = selinux_socket_post_create,
5588 .socket_bind = selinux_socket_bind,
5589 .socket_connect = selinux_socket_connect,

--- 13 unchanged lines hidden (view full) ---

5603 .sk_free_security = selinux_sk_free_security,
5604 .sk_clone_security = selinux_sk_clone_security,
5605 .sk_getsecid = selinux_sk_getsecid,
5606 .sock_graft = selinux_sock_graft,
5607 .inet_conn_request = selinux_inet_conn_request,
5608 .inet_csk_clone = selinux_inet_csk_clone,
5609 .inet_conn_established = selinux_inet_conn_established,
5610 .req_classify_flow = selinux_req_classify_flow,
5611 .tun_dev_create = selinux_tun_dev_create,
5612 .tun_dev_post_create = selinux_tun_dev_post_create,
5613 .tun_dev_attach = selinux_tun_dev_attach,
5467
5468#ifdef CONFIG_SECURITY_NETWORK_XFRM
5469 .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc,
5470 .xfrm_policy_clone_security = selinux_xfrm_policy_clone,
5471 .xfrm_policy_free_security = selinux_xfrm_policy_free,
5472 .xfrm_policy_delete_security = selinux_xfrm_policy_delete,
5473 .xfrm_state_alloc_security = selinux_xfrm_state_alloc,
5474 .xfrm_state_free_security = selinux_xfrm_state_free,

--- 198 unchanged lines hidden (view full) ---

5673 return -EINVAL;
5674 }
5675
5676 printk(KERN_INFO "SELinux: Disabled at runtime.\n");
5677
5678 selinux_disabled = 1;
5679 selinux_enabled = 0;
5680
5614
5615#ifdef CONFIG_SECURITY_NETWORK_XFRM
5616 .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc,
5617 .xfrm_policy_clone_security = selinux_xfrm_policy_clone,
5618 .xfrm_policy_free_security = selinux_xfrm_policy_free,
5619 .xfrm_policy_delete_security = selinux_xfrm_policy_delete,
5620 .xfrm_state_alloc_security = selinux_xfrm_state_alloc,
5621 .xfrm_state_free_security = selinux_xfrm_state_free,

--- 198 unchanged lines hidden (view full) ---

5820 return -EINVAL;
5821 }
5822
5823 printk(KERN_INFO "SELinux: Disabled at runtime.\n");
5824
5825 selinux_disabled = 1;
5826 selinux_enabled = 0;
5827
5828 /* Try to destroy the avc node cache */
5829 avc_disable();
5830
5681 /* Reset security_ops to the secondary module, dummy or capability. */
5682 security_ops = secondary_ops;
5683
5684 /* Unregister netfilter hooks. */
5685 selinux_nf_ip_exit();
5686
5687 /* Unregister selinuxfs. */
5688 exit_sel_fs();
5689
5690 return 0;
5691}
5692#endif
5831 /* Reset security_ops to the secondary module, dummy or capability. */
5832 security_ops = secondary_ops;
5833
5834 /* Unregister netfilter hooks. */
5835 selinux_nf_ip_exit();
5836
5837 /* Unregister selinuxfs. */
5838 exit_sel_fs();
5839
5840 return 0;
5841}
5842#endif