aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/avc.c34
-rw-r--r--security/selinux/hooks.c71
-rw-r--r--security/selinux/include/avc.h16
3 files changed, 104 insertions, 17 deletions
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 1a70fa26da72..00f3860c2370 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -436,9 +436,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
436{ 436{
437 struct common_audit_data *ad = a; 437 struct common_audit_data *ad = a;
438 audit_log_format(ab, "avc: %s ", 438 audit_log_format(ab, "avc: %s ",
439 ad->selinux_audit_data.denied ? "denied" : "granted"); 439 ad->selinux_audit_data->denied ? "denied" : "granted");
440 avc_dump_av(ab, ad->selinux_audit_data.tclass, 440 avc_dump_av(ab, ad->selinux_audit_data->tclass,
441 ad->selinux_audit_data.audited); 441 ad->selinux_audit_data->audited);
442 audit_log_format(ab, " for "); 442 audit_log_format(ab, " for ");
443} 443}
444 444
@@ -452,9 +452,9 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
452{ 452{
453 struct common_audit_data *ad = a; 453 struct common_audit_data *ad = a;
454 audit_log_format(ab, " "); 454 audit_log_format(ab, " ");
455 avc_dump_query(ab, ad->selinux_audit_data.ssid, 455 avc_dump_query(ab, ad->selinux_audit_data->ssid,
456 ad->selinux_audit_data.tsid, 456 ad->selinux_audit_data->tsid,
457 ad->selinux_audit_data.tclass); 457 ad->selinux_audit_data->tclass);
458} 458}
459 459
460/* This is the slow part of avc audit with big stack footprint */ 460/* This is the slow part of avc audit with big stack footprint */
@@ -464,10 +464,12 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
464 unsigned flags) 464 unsigned flags)
465{ 465{
466 struct common_audit_data stack_data; 466 struct common_audit_data stack_data;
467 struct selinux_audit_data sad = {0,};
467 468
468 if (!a) { 469 if (!a) {
469 a = &stack_data; 470 a = &stack_data;
470 COMMON_AUDIT_DATA_INIT(a, NONE); 471 COMMON_AUDIT_DATA_INIT(a, NONE);
472 a->selinux_audit_data = &sad;
471 } 473 }
472 474
473 /* 475 /*
@@ -481,12 +483,12 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
481 (flags & MAY_NOT_BLOCK)) 483 (flags & MAY_NOT_BLOCK))
482 return -ECHILD; 484 return -ECHILD;
483 485
484 a->selinux_audit_data.tclass = tclass; 486 a->selinux_audit_data->tclass = tclass;
485 a->selinux_audit_data.requested = requested; 487 a->selinux_audit_data->requested = requested;
486 a->selinux_audit_data.ssid = ssid; 488 a->selinux_audit_data->ssid = ssid;
487 a->selinux_audit_data.tsid = tsid; 489 a->selinux_audit_data->tsid = tsid;
488 a->selinux_audit_data.audited = audited; 490 a->selinux_audit_data->audited = audited;
489 a->selinux_audit_data.denied = denied; 491 a->selinux_audit_data->denied = denied;
490 a->lsm_pre_audit = avc_audit_pre_callback; 492 a->lsm_pre_audit = avc_audit_pre_callback;
491 a->lsm_post_audit = avc_audit_post_callback; 493 a->lsm_post_audit = avc_audit_post_callback;
492 common_lsm_audit(a); 494 common_lsm_audit(a);
@@ -523,7 +525,7 @@ inline int avc_audit(u32 ssid, u32 tsid,
523 if (unlikely(denied)) { 525 if (unlikely(denied)) {
524 audited = denied & avd->auditdeny; 526 audited = denied & avd->auditdeny;
525 /* 527 /*
526 * a->selinux_audit_data.auditdeny is TRICKY! Setting a bit in 528 * a->selinux_audit_data->auditdeny is TRICKY! Setting a bit in
527 * this field means that ANY denials should NOT be audited if 529 * this field means that ANY denials should NOT be audited if
528 * the policy contains an explicit dontaudit rule for that 530 * the policy contains an explicit dontaudit rule for that
529 * permission. Take notice that this is unrelated to the 531 * permission. Take notice that this is unrelated to the
@@ -532,15 +534,15 @@ inline int avc_audit(u32 ssid, u32 tsid,
532 * 534 *
533 * denied == READ 535 * denied == READ
534 * avd.auditdeny & ACCESS == 0 (not set means explicit rule) 536 * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
535 * selinux_audit_data.auditdeny & ACCESS == 1 537 * selinux_audit_data->auditdeny & ACCESS == 1
536 * 538 *
537 * We will NOT audit the denial even though the denied 539 * We will NOT audit the denial even though the denied
538 * permission was READ and the auditdeny checks were for 540 * permission was READ and the auditdeny checks were for
539 * ACCESS 541 * ACCESS
540 */ 542 */
541 if (a && 543 if (a &&
542 a->selinux_audit_data.auditdeny && 544 a->selinux_audit_data->auditdeny &&
543 !(a->selinux_audit_data.auditdeny & avd->auditdeny)) 545 !(a->selinux_audit_data->auditdeny & avd->auditdeny))
544 audited = 0; 546 audited = 0;
545 } else if (result) 547 } else if (result)
546 audited = denied = requested; 548 audited = denied = requested;
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 28482f9e15b8..3861ce4b1007 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1420,6 +1420,7 @@ 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,};
1423 struct av_decision avd; 1424 struct av_decision avd;
1424 u16 sclass; 1425 u16 sclass;
1425 u32 sid = cred_sid(cred); 1426 u32 sid = cred_sid(cred);
@@ -1427,6 +1428,7 @@ static int cred_has_capability(const struct cred *cred,
1427 int rc; 1428 int rc;
1428 1429
1429 COMMON_AUDIT_DATA_INIT(&ad, CAP); 1430 COMMON_AUDIT_DATA_INIT(&ad, CAP);
1431 ad.selinux_audit_data = &sad;
1430 ad.tsk = current; 1432 ad.tsk = current;
1431 ad.u.cap = cap; 1433 ad.u.cap = cap;
1432 1434
@@ -1492,9 +1494,11 @@ static int inode_has_perm_noadp(const struct cred *cred,
1492 unsigned flags) 1494 unsigned flags)
1493{ 1495{
1494 struct common_audit_data ad; 1496 struct common_audit_data ad;
1497 struct selinux_audit_data sad = {0,};
1495 1498
1496 COMMON_AUDIT_DATA_INIT(&ad, INODE); 1499 COMMON_AUDIT_DATA_INIT(&ad, INODE);
1497 ad.u.inode = inode; 1500 ad.u.inode = inode;
1501 ad.selinux_audit_data = &sad;
1498 return inode_has_perm(cred, inode, perms, &ad, flags); 1502 return inode_has_perm(cred, inode, perms, &ad, flags);
1499} 1503}
1500 1504
@@ -1507,9 +1511,11 @@ static inline int dentry_has_perm(const struct cred *cred,
1507{ 1511{
1508 struct inode *inode = dentry->d_inode; 1512 struct inode *inode = dentry->d_inode;
1509 struct common_audit_data ad; 1513 struct common_audit_data ad;
1514 struct selinux_audit_data sad = {0,};
1510 1515
1511 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1516 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1512 ad.u.dentry = dentry; 1517 ad.u.dentry = dentry;
1518 ad.selinux_audit_data = &sad;
1513 return inode_has_perm(cred, inode, av, &ad, 0); 1519 return inode_has_perm(cred, inode, av, &ad, 0);
1514} 1520}
1515 1521
@@ -1522,9 +1528,11 @@ static inline int path_has_perm(const struct cred *cred,
1522{ 1528{
1523 struct inode *inode = path->dentry->d_inode; 1529 struct inode *inode = path->dentry->d_inode;
1524 struct common_audit_data ad; 1530 struct common_audit_data ad;
1531 struct selinux_audit_data sad = {0,};
1525 1532
1526 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1533 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1527 ad.u.path = *path; 1534 ad.u.path = *path;
1535 ad.selinux_audit_data = &sad;
1528 return inode_has_perm(cred, inode, av, &ad, 0); 1536 return inode_has_perm(cred, inode, av, &ad, 0);
1529} 1537}
1530 1538
@@ -1543,11 +1551,13 @@ static int file_has_perm(const struct cred *cred,
1543 struct file_security_struct *fsec = file->f_security; 1551 struct file_security_struct *fsec = file->f_security;
1544 struct inode *inode = file->f_path.dentry->d_inode; 1552 struct inode *inode = file->f_path.dentry->d_inode;
1545 struct common_audit_data ad; 1553 struct common_audit_data ad;
1554 struct selinux_audit_data sad = {0,};
1546 u32 sid = cred_sid(cred); 1555 u32 sid = cred_sid(cred);
1547 int rc; 1556 int rc;
1548 1557
1549 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1558 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1550 ad.u.path = file->f_path; 1559 ad.u.path = file->f_path;
1560 ad.selinux_audit_data = &sad;
1551 1561
1552 if (sid != fsec->sid) { 1562 if (sid != fsec->sid) {
1553 rc = avc_has_perm(sid, fsec->sid, 1563 rc = avc_has_perm(sid, fsec->sid,
@@ -1577,6 +1587,7 @@ static int may_create(struct inode *dir,
1577 struct superblock_security_struct *sbsec; 1587 struct superblock_security_struct *sbsec;
1578 u32 sid, newsid; 1588 u32 sid, newsid;
1579 struct common_audit_data ad; 1589 struct common_audit_data ad;
1590 struct selinux_audit_data sad = {0,};
1580 int rc; 1591 int rc;
1581 1592
1582 dsec = dir->i_security; 1593 dsec = dir->i_security;
@@ -1587,6 +1598,7 @@ static int may_create(struct inode *dir,
1587 1598
1588 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1599 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1589 ad.u.dentry = dentry; 1600 ad.u.dentry = dentry;
1601 ad.selinux_audit_data = &sad;
1590 1602
1591 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, 1603 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1592 DIR__ADD_NAME | DIR__SEARCH, 1604 DIR__ADD_NAME | DIR__SEARCH,
@@ -1631,6 +1643,7 @@ static int may_link(struct inode *dir,
1631{ 1643{
1632 struct inode_security_struct *dsec, *isec; 1644 struct inode_security_struct *dsec, *isec;
1633 struct common_audit_data ad; 1645 struct common_audit_data ad;
1646 struct selinux_audit_data sad = {0,};
1634 u32 sid = current_sid(); 1647 u32 sid = current_sid();
1635 u32 av; 1648 u32 av;
1636 int rc; 1649 int rc;
@@ -1640,6 +1653,7 @@ static int may_link(struct inode *dir,
1640 1653
1641 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1654 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1642 ad.u.dentry = dentry; 1655 ad.u.dentry = dentry;
1656 ad.selinux_audit_data = &sad;
1643 1657
1644 av = DIR__SEARCH; 1658 av = DIR__SEARCH;
1645 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); 1659 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
@@ -1674,6 +1688,7 @@ static inline int may_rename(struct inode *old_dir,
1674{ 1688{
1675 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec; 1689 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1676 struct common_audit_data ad; 1690 struct common_audit_data ad;
1691 struct selinux_audit_data sad = {0,};
1677 u32 sid = current_sid(); 1692 u32 sid = current_sid();
1678 u32 av; 1693 u32 av;
1679 int old_is_dir, new_is_dir; 1694 int old_is_dir, new_is_dir;
@@ -1685,6 +1700,7 @@ static inline int may_rename(struct inode *old_dir,
1685 new_dsec = new_dir->i_security; 1700 new_dsec = new_dir->i_security;
1686 1701
1687 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1702 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1703 ad.selinux_audit_data = &sad;
1688 1704
1689 ad.u.dentry = old_dentry; 1705 ad.u.dentry = old_dentry;
1690 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, 1706 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
@@ -1970,6 +1986,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
1970 struct task_security_struct *new_tsec; 1986 struct task_security_struct *new_tsec;
1971 struct inode_security_struct *isec; 1987 struct inode_security_struct *isec;
1972 struct common_audit_data ad; 1988 struct common_audit_data ad;
1989 struct selinux_audit_data sad = {0,};
1973 struct inode *inode = bprm->file->f_path.dentry->d_inode; 1990 struct inode *inode = bprm->file->f_path.dentry->d_inode;
1974 int rc; 1991 int rc;
1975 1992
@@ -2009,6 +2026,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2009 } 2026 }
2010 2027
2011 COMMON_AUDIT_DATA_INIT(&ad, PATH); 2028 COMMON_AUDIT_DATA_INIT(&ad, PATH);
2029 ad.selinux_audit_data = &sad;
2012 ad.u.path = bprm->file->f_path; 2030 ad.u.path = bprm->file->f_path;
2013 2031
2014 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) 2032 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
@@ -2098,6 +2116,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2098 struct files_struct *files) 2116 struct files_struct *files)
2099{ 2117{
2100 struct common_audit_data ad; 2118 struct common_audit_data ad;
2119 struct selinux_audit_data sad = {0,};
2101 struct file *file, *devnull = NULL; 2120 struct file *file, *devnull = NULL;
2102 struct tty_struct *tty; 2121 struct tty_struct *tty;
2103 struct fdtable *fdt; 2122 struct fdtable *fdt;
@@ -2135,6 +2154,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2135 /* Revalidate access to inherited open files. */ 2154 /* Revalidate access to inherited open files. */
2136 2155
2137 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2156 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2157 ad.selinux_audit_data = &sad;
2138 2158
2139 spin_lock(&files->file_lock); 2159 spin_lock(&files->file_lock);
2140 for (;;) { 2160 for (;;) {
@@ -2472,6 +2492,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2472{ 2492{
2473 const struct cred *cred = current_cred(); 2493 const struct cred *cred = current_cred();
2474 struct common_audit_data ad; 2494 struct common_audit_data ad;
2495 struct selinux_audit_data sad = {0,};
2475 int rc; 2496 int rc;
2476 2497
2477 rc = superblock_doinit(sb, data); 2498 rc = superblock_doinit(sb, data);
@@ -2483,6 +2504,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2483 return 0; 2504 return 0;
2484 2505
2485 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2506 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2507 ad.selinux_audit_data = &sad;
2486 ad.u.dentry = sb->s_root; 2508 ad.u.dentry = sb->s_root;
2487 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); 2509 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2488} 2510}
@@ -2491,8 +2513,10 @@ static int selinux_sb_statfs(struct dentry *dentry)
2491{ 2513{
2492 const struct cred *cred = current_cred(); 2514 const struct cred *cred = current_cred();
2493 struct common_audit_data ad; 2515 struct common_audit_data ad;
2516 struct selinux_audit_data sad = {0,};
2494 2517
2495 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2518 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2519 ad.selinux_audit_data = &sad;
2496 ad.u.dentry = dentry->d_sb->s_root; 2520 ad.u.dentry = dentry->d_sb->s_root;
2497 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); 2521 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2498} 2522}
@@ -2656,6 +2680,7 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2656{ 2680{
2657 const struct cred *cred = current_cred(); 2681 const struct cred *cred = current_cred();
2658 struct common_audit_data ad; 2682 struct common_audit_data ad;
2683 struct selinux_audit_data sad = {0,};
2659 u32 perms; 2684 u32 perms;
2660 bool from_access; 2685 bool from_access;
2661 unsigned flags = mask & MAY_NOT_BLOCK; 2686 unsigned flags = mask & MAY_NOT_BLOCK;
@@ -2668,10 +2693,11 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2668 return 0; 2693 return 0;
2669 2694
2670 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2695 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2696 ad.selinux_audit_data = &sad;
2671 ad.u.inode = inode; 2697 ad.u.inode = inode;
2672 2698
2673 if (from_access) 2699 if (from_access)
2674 ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS; 2700 ad.selinux_audit_data->auditdeny |= FILE__AUDIT_ACCESS;
2675 2701
2676 perms = file_mask_to_av(inode->i_mode, mask); 2702 perms = file_mask_to_av(inode->i_mode, mask);
2677 2703
@@ -2737,6 +2763,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2737 struct inode_security_struct *isec = inode->i_security; 2763 struct inode_security_struct *isec = inode->i_security;
2738 struct superblock_security_struct *sbsec; 2764 struct superblock_security_struct *sbsec;
2739 struct common_audit_data ad; 2765 struct common_audit_data ad;
2766 struct selinux_audit_data sad = {0,};
2740 u32 newsid, sid = current_sid(); 2767 u32 newsid, sid = current_sid();
2741 int rc = 0; 2768 int rc = 0;
2742 2769
@@ -2751,6 +2778,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2751 return -EPERM; 2778 return -EPERM;
2752 2779
2753 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2780 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2781 ad.selinux_audit_data = &sad;
2754 ad.u.dentry = dentry; 2782 ad.u.dentry = dentry;
2755 2783
2756 rc = avc_has_perm(sid, isec->sid, isec->sclass, 2784 rc = avc_has_perm(sid, isec->sid, isec->sclass,
@@ -3345,10 +3373,12 @@ static int selinux_kernel_module_request(char *kmod_name)
3345{ 3373{
3346 u32 sid; 3374 u32 sid;
3347 struct common_audit_data ad; 3375 struct common_audit_data ad;
3376 struct selinux_audit_data sad = {0,};
3348 3377
3349 sid = task_sid(current); 3378 sid = task_sid(current);
3350 3379
3351 COMMON_AUDIT_DATA_INIT(&ad, KMOD); 3380 COMMON_AUDIT_DATA_INIT(&ad, KMOD);
3381 ad.selinux_audit_data = &sad;
3352 ad.u.kmod_name = kmod_name; 3382 ad.u.kmod_name = kmod_name;
3353 3383
3354 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM, 3384 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
@@ -3721,12 +3751,14 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
3721{ 3751{
3722 struct sk_security_struct *sksec = sk->sk_security; 3752 struct sk_security_struct *sksec = sk->sk_security;
3723 struct common_audit_data ad; 3753 struct common_audit_data ad;
3754 struct selinux_audit_data sad = {0,};
3724 u32 tsid = task_sid(task); 3755 u32 tsid = task_sid(task);
3725 3756
3726 if (sksec->sid == SECINITSID_KERNEL) 3757 if (sksec->sid == SECINITSID_KERNEL)
3727 return 0; 3758 return 0;
3728 3759
3729 COMMON_AUDIT_DATA_INIT(&ad, NET); 3760 COMMON_AUDIT_DATA_INIT(&ad, NET);
3761 ad.selinux_audit_data = &sad;
3730 ad.u.net.sk = sk; 3762 ad.u.net.sk = sk;
3731 3763
3732 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad); 3764 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad);
@@ -3805,6 +3837,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3805 char *addrp; 3837 char *addrp;
3806 struct sk_security_struct *sksec = sk->sk_security; 3838 struct sk_security_struct *sksec = sk->sk_security;
3807 struct common_audit_data ad; 3839 struct common_audit_data ad;
3840 struct selinux_audit_data sad = {0,};
3808 struct sockaddr_in *addr4 = NULL; 3841 struct sockaddr_in *addr4 = NULL;
3809 struct sockaddr_in6 *addr6 = NULL; 3842 struct sockaddr_in6 *addr6 = NULL;
3810 unsigned short snum; 3843 unsigned short snum;
@@ -3831,6 +3864,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3831 if (err) 3864 if (err)
3832 goto out; 3865 goto out;
3833 COMMON_AUDIT_DATA_INIT(&ad, NET); 3866 COMMON_AUDIT_DATA_INIT(&ad, NET);
3867 ad.selinux_audit_data = &sad;
3834 ad.u.net.sport = htons(snum); 3868 ad.u.net.sport = htons(snum);
3835 ad.u.net.family = family; 3869 ad.u.net.family = family;
3836 err = avc_has_perm(sksec->sid, sid, 3870 err = avc_has_perm(sksec->sid, sid,
@@ -3864,6 +3898,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3864 goto out; 3898 goto out;
3865 3899
3866 COMMON_AUDIT_DATA_INIT(&ad, NET); 3900 COMMON_AUDIT_DATA_INIT(&ad, NET);
3901 ad.selinux_audit_data = &sad;
3867 ad.u.net.sport = htons(snum); 3902 ad.u.net.sport = htons(snum);
3868 ad.u.net.family = family; 3903 ad.u.net.family = family;
3869 3904
@@ -3897,6 +3932,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3897 if (sksec->sclass == SECCLASS_TCP_SOCKET || 3932 if (sksec->sclass == SECCLASS_TCP_SOCKET ||
3898 sksec->sclass == SECCLASS_DCCP_SOCKET) { 3933 sksec->sclass == SECCLASS_DCCP_SOCKET) {
3899 struct common_audit_data ad; 3934 struct common_audit_data ad;
3935 struct selinux_audit_data sad = {0,};
3900 struct sockaddr_in *addr4 = NULL; 3936 struct sockaddr_in *addr4 = NULL;
3901 struct sockaddr_in6 *addr6 = NULL; 3937 struct sockaddr_in6 *addr6 = NULL;
3902 unsigned short snum; 3938 unsigned short snum;
@@ -3922,6 +3958,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3922 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT; 3958 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3923 3959
3924 COMMON_AUDIT_DATA_INIT(&ad, NET); 3960 COMMON_AUDIT_DATA_INIT(&ad, NET);
3961 ad.selinux_audit_data = &sad;
3925 ad.u.net.dport = htons(snum); 3962 ad.u.net.dport = htons(snum);
3926 ad.u.net.family = sk->sk_family; 3963 ad.u.net.family = sk->sk_family;
3927 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad); 3964 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad);
@@ -4012,9 +4049,11 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
4012 struct sk_security_struct *sksec_other = other->sk_security; 4049 struct sk_security_struct *sksec_other = other->sk_security;
4013 struct sk_security_struct *sksec_new = newsk->sk_security; 4050 struct sk_security_struct *sksec_new = newsk->sk_security;
4014 struct common_audit_data ad; 4051 struct common_audit_data ad;
4052 struct selinux_audit_data sad = {0,};
4015 int err; 4053 int err;
4016 4054
4017 COMMON_AUDIT_DATA_INIT(&ad, NET); 4055 COMMON_AUDIT_DATA_INIT(&ad, NET);
4056 ad.selinux_audit_data = &sad;
4018 ad.u.net.sk = other; 4057 ad.u.net.sk = other;
4019 4058
4020 err = avc_has_perm(sksec_sock->sid, sksec_other->sid, 4059 err = avc_has_perm(sksec_sock->sid, sksec_other->sid,
@@ -4042,8 +4081,10 @@ static int selinux_socket_unix_may_send(struct socket *sock,
4042 struct sk_security_struct *ssec = sock->sk->sk_security; 4081 struct sk_security_struct *ssec = sock->sk->sk_security;
4043 struct sk_security_struct *osec = other->sk->sk_security; 4082 struct sk_security_struct *osec = other->sk->sk_security;
4044 struct common_audit_data ad; 4083 struct common_audit_data ad;
4084 struct selinux_audit_data sad = {0,};
4045 4085
4046 COMMON_AUDIT_DATA_INIT(&ad, NET); 4086 COMMON_AUDIT_DATA_INIT(&ad, NET);
4087 ad.selinux_audit_data = &sad;
4047 ad.u.net.sk = other->sk; 4088 ad.u.net.sk = other->sk;
4048 4089
4049 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO, 4090 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO,
@@ -4080,9 +4121,11 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4080 struct sk_security_struct *sksec = sk->sk_security; 4121 struct sk_security_struct *sksec = sk->sk_security;
4081 u32 sk_sid = sksec->sid; 4122 u32 sk_sid = sksec->sid;
4082 struct common_audit_data ad; 4123 struct common_audit_data ad;
4124 struct selinux_audit_data sad = {0,};
4083 char *addrp; 4125 char *addrp;
4084 4126
4085 COMMON_AUDIT_DATA_INIT(&ad, NET); 4127 COMMON_AUDIT_DATA_INIT(&ad, NET);
4128 ad.selinux_audit_data = &sad;
4086 ad.u.net.netif = skb->skb_iif; 4129 ad.u.net.netif = skb->skb_iif;
4087 ad.u.net.family = family; 4130 ad.u.net.family = family;
4088 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4131 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
@@ -4111,6 +4154,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4111 u16 family = sk->sk_family; 4154 u16 family = sk->sk_family;
4112 u32 sk_sid = sksec->sid; 4155 u32 sk_sid = sksec->sid;
4113 struct common_audit_data ad; 4156 struct common_audit_data ad;
4157 struct selinux_audit_data sad = {0,};
4114 char *addrp; 4158 char *addrp;
4115 u8 secmark_active; 4159 u8 secmark_active;
4116 u8 peerlbl_active; 4160 u8 peerlbl_active;
@@ -4135,6 +4179,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4135 return 0; 4179 return 0;
4136 4180
4137 COMMON_AUDIT_DATA_INIT(&ad, NET); 4181 COMMON_AUDIT_DATA_INIT(&ad, NET);
4182 ad.selinux_audit_data = &sad;
4138 ad.u.net.netif = skb->skb_iif; 4183 ad.u.net.netif = skb->skb_iif;
4139 ad.u.net.family = family; 4184 ad.u.net.family = family;
4140 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4185 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
@@ -4471,6 +4516,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4471 char *addrp; 4516 char *addrp;
4472 u32 peer_sid; 4517 u32 peer_sid;
4473 struct common_audit_data ad; 4518 struct common_audit_data ad;
4519 struct selinux_audit_data sad = {0,};
4474 u8 secmark_active; 4520 u8 secmark_active;
4475 u8 netlbl_active; 4521 u8 netlbl_active;
4476 u8 peerlbl_active; 4522 u8 peerlbl_active;
@@ -4488,6 +4534,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4488 return NF_DROP; 4534 return NF_DROP;
4489 4535
4490 COMMON_AUDIT_DATA_INIT(&ad, NET); 4536 COMMON_AUDIT_DATA_INIT(&ad, NET);
4537 ad.selinux_audit_data = &sad;
4491 ad.u.net.netif = ifindex; 4538 ad.u.net.netif = ifindex;
4492 ad.u.net.family = family; 4539 ad.u.net.family = family;
4493 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) 4540 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
@@ -4576,6 +4623,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4576 struct sock *sk = skb->sk; 4623 struct sock *sk = skb->sk;
4577 struct sk_security_struct *sksec; 4624 struct sk_security_struct *sksec;
4578 struct common_audit_data ad; 4625 struct common_audit_data ad;
4626 struct selinux_audit_data sad = {0,};
4579 char *addrp; 4627 char *addrp;
4580 u8 proto; 4628 u8 proto;
4581 4629
@@ -4584,6 +4632,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4584 sksec = sk->sk_security; 4632 sksec = sk->sk_security;
4585 4633
4586 COMMON_AUDIT_DATA_INIT(&ad, NET); 4634 COMMON_AUDIT_DATA_INIT(&ad, NET);
4635 ad.selinux_audit_data = &sad;
4587 ad.u.net.netif = ifindex; 4636 ad.u.net.netif = ifindex;
4588 ad.u.net.family = family; 4637 ad.u.net.family = family;
4589 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto)) 4638 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
@@ -4607,6 +4656,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4607 u32 peer_sid; 4656 u32 peer_sid;
4608 struct sock *sk; 4657 struct sock *sk;
4609 struct common_audit_data ad; 4658 struct common_audit_data ad;
4659 struct selinux_audit_data sad = {0,};
4610 char *addrp; 4660 char *addrp;
4611 u8 secmark_active; 4661 u8 secmark_active;
4612 u8 peerlbl_active; 4662 u8 peerlbl_active;
@@ -4653,6 +4703,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4653 } 4703 }
4654 4704
4655 COMMON_AUDIT_DATA_INIT(&ad, NET); 4705 COMMON_AUDIT_DATA_INIT(&ad, NET);
4706 ad.selinux_audit_data = &sad;
4656 ad.u.net.netif = ifindex; 4707 ad.u.net.netif = ifindex;
4657 ad.u.net.family = family; 4708 ad.u.net.family = family;
4658 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL)) 4709 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
@@ -4769,11 +4820,13 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4769{ 4820{
4770 struct ipc_security_struct *isec; 4821 struct ipc_security_struct *isec;
4771 struct common_audit_data ad; 4822 struct common_audit_data ad;
4823 struct selinux_audit_data sad = {0,};
4772 u32 sid = current_sid(); 4824 u32 sid = current_sid();
4773 4825
4774 isec = ipc_perms->security; 4826 isec = ipc_perms->security;
4775 4827
4776 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4828 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4829 ad.selinux_audit_data = &sad;
4777 ad.u.ipc_id = ipc_perms->key; 4830 ad.u.ipc_id = ipc_perms->key;
4778 4831
4779 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad); 4832 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
@@ -4794,6 +4847,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4794{ 4847{
4795 struct ipc_security_struct *isec; 4848 struct ipc_security_struct *isec;
4796 struct common_audit_data ad; 4849 struct common_audit_data ad;
4850 struct selinux_audit_data sad = {0,};
4797 u32 sid = current_sid(); 4851 u32 sid = current_sid();
4798 int rc; 4852 int rc;
4799 4853
@@ -4804,6 +4858,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4804 isec = msq->q_perm.security; 4858 isec = msq->q_perm.security;
4805 4859
4806 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4860 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4861 ad.selinux_audit_data = &sad;
4807 ad.u.ipc_id = msq->q_perm.key; 4862 ad.u.ipc_id = msq->q_perm.key;
4808 4863
4809 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4864 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4824,11 +4879,13 @@ static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4824{ 4879{
4825 struct ipc_security_struct *isec; 4880 struct ipc_security_struct *isec;
4826 struct common_audit_data ad; 4881 struct common_audit_data ad;
4882 struct selinux_audit_data sad = {0,};
4827 u32 sid = current_sid(); 4883 u32 sid = current_sid();
4828 4884
4829 isec = msq->q_perm.security; 4885 isec = msq->q_perm.security;
4830 4886
4831 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4887 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4888 ad.selinux_audit_data = &sad;
4832 ad.u.ipc_id = msq->q_perm.key; 4889 ad.u.ipc_id = msq->q_perm.key;
4833 4890
4834 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4891 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4868,6 +4925,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4868 struct ipc_security_struct *isec; 4925 struct ipc_security_struct *isec;
4869 struct msg_security_struct *msec; 4926 struct msg_security_struct *msec;
4870 struct common_audit_data ad; 4927 struct common_audit_data ad;
4928 struct selinux_audit_data sad = {0,};
4871 u32 sid = current_sid(); 4929 u32 sid = current_sid();
4872 int rc; 4930 int rc;
4873 4931
@@ -4889,6 +4947,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4889 } 4947 }
4890 4948
4891 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4949 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4950 ad.selinux_audit_data = &sad;
4892 ad.u.ipc_id = msq->q_perm.key; 4951 ad.u.ipc_id = msq->q_perm.key;
4893 4952
4894 /* Can this process write to the queue? */ 4953 /* Can this process write to the queue? */
@@ -4913,6 +4972,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4913 struct ipc_security_struct *isec; 4972 struct ipc_security_struct *isec;
4914 struct msg_security_struct *msec; 4973 struct msg_security_struct *msec;
4915 struct common_audit_data ad; 4974 struct common_audit_data ad;
4975 struct selinux_audit_data sad = {0,};
4916 u32 sid = task_sid(target); 4976 u32 sid = task_sid(target);
4917 int rc; 4977 int rc;
4918 4978
@@ -4920,6 +4980,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4920 msec = msg->security; 4980 msec = msg->security;
4921 4981
4922 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4982 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4983 ad.selinux_audit_data = &sad;
4923 ad.u.ipc_id = msq->q_perm.key; 4984 ad.u.ipc_id = msq->q_perm.key;
4924 4985
4925 rc = avc_has_perm(sid, isec->sid, 4986 rc = avc_has_perm(sid, isec->sid,
@@ -4935,6 +4996,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4935{ 4996{
4936 struct ipc_security_struct *isec; 4997 struct ipc_security_struct *isec;
4937 struct common_audit_data ad; 4998 struct common_audit_data ad;
4999 struct selinux_audit_data sad = {0,};
4938 u32 sid = current_sid(); 5000 u32 sid = current_sid();
4939 int rc; 5001 int rc;
4940 5002
@@ -4945,6 +5007,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4945 isec = shp->shm_perm.security; 5007 isec = shp->shm_perm.security;
4946 5008
4947 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5009 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5010 ad.selinux_audit_data = &sad;
4948 ad.u.ipc_id = shp->shm_perm.key; 5011 ad.u.ipc_id = shp->shm_perm.key;
4949 5012
4950 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5013 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -4965,11 +5028,13 @@ static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
4965{ 5028{
4966 struct ipc_security_struct *isec; 5029 struct ipc_security_struct *isec;
4967 struct common_audit_data ad; 5030 struct common_audit_data ad;
5031 struct selinux_audit_data sad = {0,};
4968 u32 sid = current_sid(); 5032 u32 sid = current_sid();
4969 5033
4970 isec = shp->shm_perm.security; 5034 isec = shp->shm_perm.security;
4971 5035
4972 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5036 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5037 ad.selinux_audit_data = &sad;
4973 ad.u.ipc_id = shp->shm_perm.key; 5038 ad.u.ipc_id = shp->shm_perm.key;
4974 5039
4975 return avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5040 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5027,6 +5092,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5027{ 5092{
5028 struct ipc_security_struct *isec; 5093 struct ipc_security_struct *isec;
5029 struct common_audit_data ad; 5094 struct common_audit_data ad;
5095 struct selinux_audit_data sad = {0,};
5030 u32 sid = current_sid(); 5096 u32 sid = current_sid();
5031 int rc; 5097 int rc;
5032 5098
@@ -5037,6 +5103,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5037 isec = sma->sem_perm.security; 5103 isec = sma->sem_perm.security;
5038 5104
5039 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5105 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5106 ad.selinux_audit_data = &sad;
5040 ad.u.ipc_id = sma->sem_perm.key; 5107 ad.u.ipc_id = sma->sem_perm.key;
5041 5108
5042 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5109 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5057,11 +5124,13 @@ static int selinux_sem_associate(struct sem_array *sma, int semflg)
5057{ 5124{
5058 struct ipc_security_struct *isec; 5125 struct ipc_security_struct *isec;
5059 struct common_audit_data ad; 5126 struct common_audit_data ad;
5127 struct selinux_audit_data sad = {0,};
5060 u32 sid = current_sid(); 5128 u32 sid = current_sid();
5061 5129
5062 isec = sma->sem_perm.security; 5130 isec = sma->sem_perm.security;
5063 5131
5064 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5132 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5133 ad.selinux_audit_data = &sad;
5065 ad.u.ipc_id = sma->sem_perm.key; 5134 ad.u.ipc_id = sma->sem_perm.key;
5066 5135
5067 return avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5136 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index 005a91bcb200..fa13f17ce0ff 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -46,6 +46,22 @@ struct avc_cache_stats {
46 unsigned int frees; 46 unsigned int frees;
47}; 47};
48 48
49struct selinux_audit_data {
50 u32 ssid;
51 u32 tsid;
52 u16 tclass;
53 u32 requested;
54 u32 audited;
55 u32 denied;
56 /*
57 * auditdeny is a bit tricky and unintuitive. See the
58 * comments in avc.c for it's meaning and usage.
59 */
60 u32 auditdeny;
61 struct av_decision *avd;
62 int result;
63};
64
49/* 65/*
50 * AVC operations 66 * AVC operations
51 */ 67 */