diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
commit | 10ce3cc919f50c2043b41ca968b43c26a3672600 (patch) | |
tree | ea409366a5208aced495bc0516a08b81fd43222e /security/selinux/hooks.c | |
parent | 24e3e5ae1e4c2a3a32f5b1f96b4e3fd721806acd (diff) | |
parent | 5c6a7a62c130afef3d61c1dee153012231ff5cd9 (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 1126c10a5e82..6a3683e28426 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -1090,7 +1090,7 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc | |||
1090 | return SECCLASS_NETLINK_ROUTE_SOCKET; | 1090 | return SECCLASS_NETLINK_ROUTE_SOCKET; |
1091 | case NETLINK_FIREWALL: | 1091 | case NETLINK_FIREWALL: |
1092 | return SECCLASS_NETLINK_FIREWALL_SOCKET; | 1092 | return SECCLASS_NETLINK_FIREWALL_SOCKET; |
1093 | case NETLINK_INET_DIAG: | 1093 | case NETLINK_SOCK_DIAG: |
1094 | return SECCLASS_NETLINK_TCPDIAG_SOCKET; | 1094 | return SECCLASS_NETLINK_TCPDIAG_SOCKET; |
1095 | case NETLINK_NFLOG: | 1095 | case NETLINK_NFLOG: |
1096 | return SECCLASS_NETLINK_NFLOG_SOCKET; | 1096 | return SECCLASS_NETLINK_NFLOG_SOCKET; |
@@ -1415,8 +1415,7 @@ static int current_has_perm(const struct task_struct *tsk, | |||
1415 | #endif | 1415 | #endif |
1416 | 1416 | ||
1417 | /* Check whether a task is allowed to use a capability. */ | 1417 | /* Check whether a task is allowed to use a capability. */ |
1418 | static int task_has_capability(struct task_struct *tsk, | 1418 | static int cred_has_capability(const struct cred *cred, |
1419 | const struct cred *cred, | ||
1420 | int cap, int audit) | 1419 | int cap, int audit) |
1421 | { | 1420 | { |
1422 | struct common_audit_data ad; | 1421 | struct common_audit_data ad; |
@@ -1427,7 +1426,7 @@ static int task_has_capability(struct task_struct *tsk, | |||
1427 | int rc; | 1426 | int rc; |
1428 | 1427 | ||
1429 | COMMON_AUDIT_DATA_INIT(&ad, CAP); | 1428 | COMMON_AUDIT_DATA_INIT(&ad, CAP); |
1430 | ad.tsk = tsk; | 1429 | ad.tsk = current; |
1431 | ad.u.cap = cap; | 1430 | ad.u.cap = cap; |
1432 | 1431 | ||
1433 | switch (CAP_TO_INDEX(cap)) { | 1432 | switch (CAP_TO_INDEX(cap)) { |
@@ -1740,7 +1739,7 @@ static inline u32 file_mask_to_av(int mode, int mask) | |||
1740 | { | 1739 | { |
1741 | u32 av = 0; | 1740 | u32 av = 0; |
1742 | 1741 | ||
1743 | if ((mode & S_IFMT) != S_IFDIR) { | 1742 | if (!S_ISDIR(mode)) { |
1744 | if (mask & MAY_EXEC) | 1743 | if (mask & MAY_EXEC) |
1745 | av |= FILE__EXECUTE; | 1744 | av |= FILE__EXECUTE; |
1746 | if (mask & MAY_READ) | 1745 | if (mask & MAY_READ) |
@@ -1811,7 +1810,7 @@ static int selinux_ptrace_access_check(struct task_struct *child, | |||
1811 | if (rc) | 1810 | if (rc) |
1812 | return rc; | 1811 | return rc; |
1813 | 1812 | ||
1814 | if (mode == PTRACE_MODE_READ) { | 1813 | if (mode & PTRACE_MODE_READ) { |
1815 | u32 sid = current_sid(); | 1814 | u32 sid = current_sid(); |
1816 | u32 csid = task_sid(child); | 1815 | u32 csid = task_sid(child); |
1817 | return avc_has_perm(sid, csid, SECCLASS_FILE, FILE__READ, NULL); | 1816 | return avc_has_perm(sid, csid, SECCLASS_FILE, FILE__READ, NULL); |
@@ -1868,16 +1867,16 @@ static int selinux_capset(struct cred *new, const struct cred *old, | |||
1868 | * the CAP_SETUID and CAP_SETGID capabilities using the capable hook. | 1867 | * the CAP_SETUID and CAP_SETGID capabilities using the capable hook. |
1869 | */ | 1868 | */ |
1870 | 1869 | ||
1871 | static int selinux_capable(struct task_struct *tsk, const struct cred *cred, | 1870 | static int selinux_capable(const struct cred *cred, struct user_namespace *ns, |
1872 | struct user_namespace *ns, int cap, int audit) | 1871 | int cap, int audit) |
1873 | { | 1872 | { |
1874 | int rc; | 1873 | int rc; |
1875 | 1874 | ||
1876 | rc = cap_capable(tsk, cred, ns, cap, audit); | 1875 | rc = cap_capable(cred, ns, cap, audit); |
1877 | if (rc) | 1876 | if (rc) |
1878 | return rc; | 1877 | return rc; |
1879 | 1878 | ||
1880 | return task_has_capability(tsk, cred, cap, audit); | 1879 | return cred_has_capability(cred, cap, audit); |
1881 | } | 1880 | } |
1882 | 1881 | ||
1883 | static int selinux_quotactl(int cmds, int type, int id, struct super_block *sb) | 1882 | static int selinux_quotactl(int cmds, int type, int id, struct super_block *sb) |
@@ -1954,8 +1953,7 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages) | |||
1954 | { | 1953 | { |
1955 | int rc, cap_sys_admin = 0; | 1954 | int rc, cap_sys_admin = 0; |
1956 | 1955 | ||
1957 | rc = selinux_capable(current, current_cred(), | 1956 | rc = selinux_capable(current_cred(), &init_user_ns, CAP_SYS_ADMIN, |
1958 | &init_user_ns, CAP_SYS_ADMIN, | ||
1959 | SECURITY_CAP_NOAUDIT); | 1957 | SECURITY_CAP_NOAUDIT); |
1960 | if (rc == 0) | 1958 | if (rc == 0) |
1961 | cap_sys_admin = 1; | 1959 | cap_sys_admin = 1; |
@@ -2507,7 +2505,7 @@ static int selinux_mount(char *dev_name, | |||
2507 | const struct cred *cred = current_cred(); | 2505 | const struct cred *cred = current_cred(); |
2508 | 2506 | ||
2509 | if (flags & MS_REMOUNT) | 2507 | if (flags & MS_REMOUNT) |
2510 | return superblock_has_perm(cred, path->mnt->mnt_sb, | 2508 | return superblock_has_perm(cred, path->dentry->d_sb, |
2511 | FILESYSTEM__REMOUNT, NULL); | 2509 | FILESYSTEM__REMOUNT, NULL); |
2512 | else | 2510 | else |
2513 | return path_has_perm(cred, path, FILE__MOUNTON); | 2511 | return path_has_perm(cred, path, FILE__MOUNTON); |
@@ -2598,7 +2596,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, | |||
2598 | return 0; | 2596 | return 0; |
2599 | } | 2597 | } |
2600 | 2598 | ||
2601 | static int selinux_inode_create(struct inode *dir, struct dentry *dentry, int mask) | 2599 | static int selinux_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode) |
2602 | { | 2600 | { |
2603 | return may_create(dir, dentry, SECCLASS_FILE); | 2601 | return may_create(dir, dentry, SECCLASS_FILE); |
2604 | } | 2602 | } |
@@ -2618,7 +2616,7 @@ static int selinux_inode_symlink(struct inode *dir, struct dentry *dentry, const | |||
2618 | return may_create(dir, dentry, SECCLASS_LNK_FILE); | 2616 | return may_create(dir, dentry, SECCLASS_LNK_FILE); |
2619 | } | 2617 | } |
2620 | 2618 | ||
2621 | static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry, int mask) | 2619 | static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mask) |
2622 | { | 2620 | { |
2623 | return may_create(dir, dentry, SECCLASS_DIR); | 2621 | return may_create(dir, dentry, SECCLASS_DIR); |
2624 | } | 2622 | } |
@@ -2628,7 +2626,7 @@ static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry) | |||
2628 | return may_link(dir, dentry, MAY_RMDIR); | 2626 | return may_link(dir, dentry, MAY_RMDIR); |
2629 | } | 2627 | } |
2630 | 2628 | ||
2631 | static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) | 2629 | static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) |
2632 | { | 2630 | { |
2633 | return may_create(dir, dentry, inode_mode_to_security_class(mode)); | 2631 | return may_create(dir, dentry, inode_mode_to_security_class(mode)); |
2634 | } | 2632 | } |
@@ -2859,8 +2857,7 @@ static int selinux_inode_getsecurity(const struct inode *inode, const char *name | |||
2859 | * and lack of permission just means that we fall back to the | 2857 | * and lack of permission just means that we fall back to the |
2860 | * in-core context value, not a denial. | 2858 | * in-core context value, not a denial. |
2861 | */ | 2859 | */ |
2862 | error = selinux_capable(current, current_cred(), | 2860 | error = selinux_capable(current_cred(), &init_user_ns, CAP_MAC_ADMIN, |
2863 | &init_user_ns, CAP_MAC_ADMIN, | ||
2864 | SECURITY_CAP_NOAUDIT); | 2861 | SECURITY_CAP_NOAUDIT); |
2865 | if (!error) | 2862 | if (!error) |
2866 | error = security_sid_to_context_force(isec->sid, &context, | 2863 | error = security_sid_to_context_force(isec->sid, &context, |
@@ -2993,8 +2990,8 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd, | |||
2993 | 2990 | ||
2994 | case KDSKBENT: | 2991 | case KDSKBENT: |
2995 | case KDSKBSENT: | 2992 | case KDSKBSENT: |
2996 | error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG, | 2993 | error = cred_has_capability(cred, CAP_SYS_TTY_CONFIG, |
2997 | SECURITY_CAP_AUDIT); | 2994 | SECURITY_CAP_AUDIT); |
2998 | break; | 2995 | break; |
2999 | 2996 | ||
3000 | /* default case assumes that the command will go | 2997 | /* default case assumes that the command will go |
@@ -3561,19 +3558,20 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb, | |||
3561 | u8 nexthdr; | 3558 | u8 nexthdr; |
3562 | int ret = -EINVAL, offset; | 3559 | int ret = -EINVAL, offset; |
3563 | struct ipv6hdr _ipv6h, *ip6; | 3560 | struct ipv6hdr _ipv6h, *ip6; |
3561 | __be16 frag_off; | ||
3564 | 3562 | ||
3565 | offset = skb_network_offset(skb); | 3563 | offset = skb_network_offset(skb); |
3566 | ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h); | 3564 | ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h); |
3567 | if (ip6 == NULL) | 3565 | if (ip6 == NULL) |
3568 | goto out; | 3566 | goto out; |
3569 | 3567 | ||
3570 | ipv6_addr_copy(&ad->u.net.v6info.saddr, &ip6->saddr); | 3568 | ad->u.net.v6info.saddr = ip6->saddr; |
3571 | ipv6_addr_copy(&ad->u.net.v6info.daddr, &ip6->daddr); | 3569 | ad->u.net.v6info.daddr = ip6->daddr; |
3572 | ret = 0; | 3570 | ret = 0; |
3573 | 3571 | ||
3574 | nexthdr = ip6->nexthdr; | 3572 | nexthdr = ip6->nexthdr; |
3575 | offset += sizeof(_ipv6h); | 3573 | offset += sizeof(_ipv6h); |
3576 | offset = ipv6_skip_exthdr(skb, offset, &nexthdr); | 3574 | offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off); |
3577 | if (offset < 0) | 3575 | if (offset < 0) |
3578 | goto out; | 3576 | goto out; |
3579 | 3577 | ||
@@ -3871,7 +3869,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in | |||
3871 | if (family == PF_INET) | 3869 | if (family == PF_INET) |
3872 | ad.u.net.v4info.saddr = addr4->sin_addr.s_addr; | 3870 | ad.u.net.v4info.saddr = addr4->sin_addr.s_addr; |
3873 | else | 3871 | else |
3874 | ipv6_addr_copy(&ad.u.net.v6info.saddr, &addr6->sin6_addr); | 3872 | ad.u.net.v6info.saddr = addr6->sin6_addr; |
3875 | 3873 | ||
3876 | err = avc_has_perm(sksec->sid, sid, | 3874 | err = avc_has_perm(sksec->sid, sid, |
3877 | sksec->sclass, node_perm, &ad); | 3875 | sksec->sclass, node_perm, &ad); |
@@ -4717,24 +4715,6 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
4717 | return selinux_nlmsg_perm(sk, skb); | 4715 | return selinux_nlmsg_perm(sk, skb); |
4718 | } | 4716 | } |
4719 | 4717 | ||
4720 | static int selinux_netlink_recv(struct sk_buff *skb, int capability) | ||
4721 | { | ||
4722 | int err; | ||
4723 | struct common_audit_data ad; | ||
4724 | u32 sid; | ||
4725 | |||
4726 | err = cap_netlink_recv(skb, capability); | ||
4727 | if (err) | ||
4728 | return err; | ||
4729 | |||
4730 | COMMON_AUDIT_DATA_INIT(&ad, CAP); | ||
4731 | ad.u.cap = capability; | ||
4732 | |||
4733 | security_task_getsecid(current, &sid); | ||
4734 | return avc_has_perm(sid, sid, SECCLASS_CAPABILITY, | ||
4735 | CAP_TO_MASK(capability), &ad); | ||
4736 | } | ||
4737 | |||
4738 | static int ipc_alloc_security(struct task_struct *task, | 4718 | static int ipc_alloc_security(struct task_struct *task, |
4739 | struct kern_ipc_perm *perm, | 4719 | struct kern_ipc_perm *perm, |
4740 | u16 sclass) | 4720 | u16 sclass) |
@@ -5463,7 +5443,6 @@ static struct security_operations selinux_ops = { | |||
5463 | .vm_enough_memory = selinux_vm_enough_memory, | 5443 | .vm_enough_memory = selinux_vm_enough_memory, |
5464 | 5444 | ||
5465 | .netlink_send = selinux_netlink_send, | 5445 | .netlink_send = selinux_netlink_send, |
5466 | .netlink_recv = selinux_netlink_recv, | ||
5467 | 5446 | ||
5468 | .bprm_set_creds = selinux_bprm_set_creds, | 5447 | .bprm_set_creds = selinux_bprm_set_creds, |
5469 | .bprm_committing_creds = selinux_bprm_committing_creds, | 5448 | .bprm_committing_creds = selinux_bprm_committing_creds, |