diff options
author | Eric Paris <eparis@redhat.com> | 2012-01-03 12:25:16 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2012-01-05 18:53:01 -0500 |
commit | fd778461524849afd035679030ae8e8873c72b81 (patch) | |
tree | 32a5849c1879413fce0307af304e372eaa8225b4 | |
parent | 69f594a38967f4540ce7a29b3fd214e68a8330bd (diff) |
security: remove the security_netlink_recv hook as it is equivalent to capable()
Once upon a time netlink was not sync and we had to get the effective
capabilities from the skb that was being received. Today we instead get
the capabilities from the current task. This has rendered the entire
purpose of the hook moot as it is now functionally equivalent to the
capable() call.
Signed-off-by: Eric Paris <eparis@redhat.com>
-rw-r--r-- | drivers/scsi/scsi_netlink.c | 2 | ||||
-rw-r--r-- | include/linux/security.h | 14 | ||||
-rw-r--r-- | kernel/audit.c | 4 | ||||
-rw-r--r-- | net/core/rtnetlink.c | 2 | ||||
-rw-r--r-- | net/decnet/netfilter/dn_rtmsg.c | 2 | ||||
-rw-r--r-- | net/ipv4/netfilter/ip_queue.c | 2 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6_queue.c | 2 | ||||
-rw-r--r-- | net/netfilter/nfnetlink.c | 2 | ||||
-rw-r--r-- | net/netlink/genetlink.c | 2 | ||||
-rw-r--r-- | net/xfrm/xfrm_user.c | 2 | ||||
-rw-r--r-- | security/capability.c | 1 | ||||
-rw-r--r-- | security/commoncap.c | 8 | ||||
-rw-r--r-- | security/security.c | 6 | ||||
-rw-r--r-- | security/selinux/hooks.c | 19 |
14 files changed, 10 insertions, 58 deletions
diff --git a/drivers/scsi/scsi_netlink.c b/drivers/scsi/scsi_netlink.c index 26a8a45584ef..feee1cc39ea0 100644 --- a/drivers/scsi/scsi_netlink.c +++ b/drivers/scsi/scsi_netlink.c | |||
@@ -111,7 +111,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb) | |||
111 | goto next_msg; | 111 | goto next_msg; |
112 | } | 112 | } |
113 | 113 | ||
114 | if (security_netlink_recv(skb, CAP_SYS_ADMIN)) { | 114 | if (!capable(CAP_SYS_ADMIN)) { |
115 | err = -EPERM; | 115 | err = -EPERM; |
116 | goto next_msg; | 116 | goto next_msg; |
117 | } | 117 | } |
diff --git a/include/linux/security.h b/include/linux/security.h index e345a9313a60..ba2d531c123f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -95,7 +95,6 @@ struct xfrm_user_sec_ctx; | |||
95 | struct seq_file; | 95 | struct seq_file; |
96 | 96 | ||
97 | extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb); | 97 | extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb); |
98 | extern int cap_netlink_recv(struct sk_buff *skb, int cap); | ||
99 | 98 | ||
100 | void reset_security_ops(void); | 99 | void reset_security_ops(void); |
101 | 100 | ||
@@ -792,12 +791,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
792 | * @skb contains the sk_buff structure for the netlink message. | 791 | * @skb contains the sk_buff structure for the netlink message. |
793 | * Return 0 if the information was successfully saved and message | 792 | * Return 0 if the information was successfully saved and message |
794 | * is allowed to be transmitted. | 793 | * is allowed to be transmitted. |
795 | * @netlink_recv: | ||
796 | * Check permission before processing the received netlink message in | ||
797 | * @skb. | ||
798 | * @skb contains the sk_buff structure for the netlink message. | ||
799 | * @cap indicates the capability required | ||
800 | * Return 0 if permission is granted. | ||
801 | * | 794 | * |
802 | * Security hooks for Unix domain networking. | 795 | * Security hooks for Unix domain networking. |
803 | * | 796 | * |
@@ -1556,7 +1549,6 @@ struct security_operations { | |||
1556 | struct sembuf *sops, unsigned nsops, int alter); | 1549 | struct sembuf *sops, unsigned nsops, int alter); |
1557 | 1550 | ||
1558 | int (*netlink_send) (struct sock *sk, struct sk_buff *skb); | 1551 | int (*netlink_send) (struct sock *sk, struct sk_buff *skb); |
1559 | int (*netlink_recv) (struct sk_buff *skb, int cap); | ||
1560 | 1552 | ||
1561 | void (*d_instantiate) (struct dentry *dentry, struct inode *inode); | 1553 | void (*d_instantiate) (struct dentry *dentry, struct inode *inode); |
1562 | 1554 | ||
@@ -1803,7 +1795,6 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode); | |||
1803 | int security_getprocattr(struct task_struct *p, char *name, char **value); | 1795 | int security_getprocattr(struct task_struct *p, char *name, char **value); |
1804 | int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size); | 1796 | int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size); |
1805 | int security_netlink_send(struct sock *sk, struct sk_buff *skb); | 1797 | int security_netlink_send(struct sock *sk, struct sk_buff *skb); |
1806 | int security_netlink_recv(struct sk_buff *skb, int cap); | ||
1807 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); | 1798 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); |
1808 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); | 1799 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); |
1809 | void security_release_secctx(char *secdata, u32 seclen); | 1800 | void security_release_secctx(char *secdata, u32 seclen); |
@@ -2478,11 +2469,6 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
2478 | return cap_netlink_send(sk, skb); | 2469 | return cap_netlink_send(sk, skb); |
2479 | } | 2470 | } |
2480 | 2471 | ||
2481 | static inline int security_netlink_recv(struct sk_buff *skb, int cap) | ||
2482 | { | ||
2483 | return cap_netlink_recv(skb, cap); | ||
2484 | } | ||
2485 | |||
2486 | static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) | 2472 | static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) |
2487 | { | 2473 | { |
2488 | return -EOPNOTSUPP; | 2474 | return -EOPNOTSUPP; |
diff --git a/kernel/audit.c b/kernel/audit.c index 0a1355ca3d79..f3ba55fa0b70 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -601,13 +601,13 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type) | |||
601 | case AUDIT_TTY_SET: | 601 | case AUDIT_TTY_SET: |
602 | case AUDIT_TRIM: | 602 | case AUDIT_TRIM: |
603 | case AUDIT_MAKE_EQUIV: | 603 | case AUDIT_MAKE_EQUIV: |
604 | if (security_netlink_recv(skb, CAP_AUDIT_CONTROL)) | 604 | if (!capable(CAP_AUDIT_CONTROL)) |
605 | err = -EPERM; | 605 | err = -EPERM; |
606 | break; | 606 | break; |
607 | case AUDIT_USER: | 607 | case AUDIT_USER: |
608 | case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG: | 608 | case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG: |
609 | case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2: | 609 | case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2: |
610 | if (security_netlink_recv(skb, CAP_AUDIT_WRITE)) | 610 | if (!capable(CAP_AUDIT_WRITE)) |
611 | err = -EPERM; | 611 | err = -EPERM; |
612 | break; | 612 | break; |
613 | default: /* bad msg */ | 613 | default: /* bad msg */ |
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 99d9e953fe39..d3a628196716 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -1931,7 +1931,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1931 | sz_idx = type>>2; | 1931 | sz_idx = type>>2; |
1932 | kind = type&3; | 1932 | kind = type&3; |
1933 | 1933 | ||
1934 | if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN)) | 1934 | if (kind != 2 && !capable(CAP_NET_ADMIN)) |
1935 | return -EPERM; | 1935 | return -EPERM; |
1936 | 1936 | ||
1937 | if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { | 1937 | if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { |
diff --git a/net/decnet/netfilter/dn_rtmsg.c b/net/decnet/netfilter/dn_rtmsg.c index 69975e0bcdea..1531135130db 100644 --- a/net/decnet/netfilter/dn_rtmsg.c +++ b/net/decnet/netfilter/dn_rtmsg.c | |||
@@ -108,7 +108,7 @@ static inline void dnrmg_receive_user_skb(struct sk_buff *skb) | |||
108 | if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) | 108 | if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) |
109 | return; | 109 | return; |
110 | 110 | ||
111 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) | 111 | if (!capable(CAP_NET_ADMIN)) |
112 | RCV_SKB_FAIL(-EPERM); | 112 | RCV_SKB_FAIL(-EPERM); |
113 | 113 | ||
114 | /* Eventually we might send routing messages too */ | 114 | /* Eventually we might send routing messages too */ |
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c index e59aabd0eae4..ffabb2674718 100644 --- a/net/ipv4/netfilter/ip_queue.c +++ b/net/ipv4/netfilter/ip_queue.c | |||
@@ -430,7 +430,7 @@ __ipq_rcv_skb(struct sk_buff *skb) | |||
430 | if (type <= IPQM_BASE) | 430 | if (type <= IPQM_BASE) |
431 | return; | 431 | return; |
432 | 432 | ||
433 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) | 433 | if (!capable(CAP_NET_ADMIN)) |
434 | RCV_SKB_FAIL(-EPERM); | 434 | RCV_SKB_FAIL(-EPERM); |
435 | 435 | ||
436 | spin_lock_bh(&queue_lock); | 436 | spin_lock_bh(&queue_lock); |
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c index e63c3972a739..5e5ce778be7f 100644 --- a/net/ipv6/netfilter/ip6_queue.c +++ b/net/ipv6/netfilter/ip6_queue.c | |||
@@ -431,7 +431,7 @@ __ipq_rcv_skb(struct sk_buff *skb) | |||
431 | if (type <= IPQM_BASE) | 431 | if (type <= IPQM_BASE) |
432 | return; | 432 | return; |
433 | 433 | ||
434 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) | 434 | if (!capable(CAP_NET_ADMIN)) |
435 | RCV_SKB_FAIL(-EPERM); | 435 | RCV_SKB_FAIL(-EPERM); |
436 | 436 | ||
437 | spin_lock_bh(&queue_lock); | 437 | spin_lock_bh(&queue_lock); |
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c index 1905976b5135..e6c2b8f32180 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c | |||
@@ -130,7 +130,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
130 | const struct nfnetlink_subsystem *ss; | 130 | const struct nfnetlink_subsystem *ss; |
131 | int type, err; | 131 | int type, err; |
132 | 132 | ||
133 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) | 133 | if (!capable(CAP_NET_ADMIN)) |
134 | return -EPERM; | 134 | return -EPERM; |
135 | 135 | ||
136 | /* All the messages must at least contain nfgenmsg */ | 136 | /* All the messages must at least contain nfgenmsg */ |
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 482fa571b4ee..05fedbf489a5 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -516,7 +516,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
516 | return -EOPNOTSUPP; | 516 | return -EOPNOTSUPP; |
517 | 517 | ||
518 | if ((ops->flags & GENL_ADMIN_PERM) && | 518 | if ((ops->flags & GENL_ADMIN_PERM) && |
519 | security_netlink_recv(skb, CAP_NET_ADMIN)) | 519 | !capable(CAP_NET_ADMIN)) |
520 | return -EPERM; | 520 | return -EPERM; |
521 | 521 | ||
522 | if (nlh->nlmsg_flags & NLM_F_DUMP) { | 522 | if (nlh->nlmsg_flags & NLM_F_DUMP) { |
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 0256b8a0a7cf..71de86698efa 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -2290,7 +2290,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
2290 | link = &xfrm_dispatch[type]; | 2290 | link = &xfrm_dispatch[type]; |
2291 | 2291 | ||
2292 | /* All operations require privileges, even GET */ | 2292 | /* All operations require privileges, even GET */ |
2293 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) | 2293 | if (!capable(CAP_NET_ADMIN)) |
2294 | return -EPERM; | 2294 | return -EPERM; |
2295 | 2295 | ||
2296 | if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) || | 2296 | if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) || |
diff --git a/security/capability.c b/security/capability.c index 2984ea4f776f..a2c064d10448 100644 --- a/security/capability.c +++ b/security/capability.c | |||
@@ -999,7 +999,6 @@ void __init security_fixup_ops(struct security_operations *ops) | |||
999 | set_to_cap_if_null(ops, sem_semctl); | 999 | set_to_cap_if_null(ops, sem_semctl); |
1000 | set_to_cap_if_null(ops, sem_semop); | 1000 | set_to_cap_if_null(ops, sem_semop); |
1001 | set_to_cap_if_null(ops, netlink_send); | 1001 | set_to_cap_if_null(ops, netlink_send); |
1002 | set_to_cap_if_null(ops, netlink_recv); | ||
1003 | set_to_cap_if_null(ops, d_instantiate); | 1002 | set_to_cap_if_null(ops, d_instantiate); |
1004 | set_to_cap_if_null(ops, getprocattr); | 1003 | set_to_cap_if_null(ops, getprocattr); |
1005 | set_to_cap_if_null(ops, setprocattr); | 1004 | set_to_cap_if_null(ops, setprocattr); |
diff --git a/security/commoncap.c b/security/commoncap.c index 89f02ff66af9..7817a763444d 100644 --- a/security/commoncap.c +++ b/security/commoncap.c | |||
@@ -56,14 +56,6 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
58 | 58 | ||
59 | int cap_netlink_recv(struct sk_buff *skb, int cap) | ||
60 | { | ||
61 | if (!cap_raised(current_cap(), cap)) | ||
62 | return -EPERM; | ||
63 | return 0; | ||
64 | } | ||
65 | EXPORT_SYMBOL(cap_netlink_recv); | ||
66 | |||
67 | /** | 59 | /** |
68 | * cap_capable - Determine whether a task has a particular effective capability | 60 | * cap_capable - Determine whether a task has a particular effective capability |
69 | * @cred: The credentials to use | 61 | * @cred: The credentials to use |
diff --git a/security/security.c b/security/security.c index 8900c5c4db5c..85481a9c5632 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -922,12 +922,6 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
922 | return security_ops->netlink_send(sk, skb); | 922 | return security_ops->netlink_send(sk, skb); |
923 | } | 923 | } |
924 | 924 | ||
925 | int security_netlink_recv(struct sk_buff *skb, int cap) | ||
926 | { | ||
927 | return security_ops->netlink_recv(skb, cap); | ||
928 | } | ||
929 | EXPORT_SYMBOL(security_netlink_recv); | ||
930 | |||
931 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) | 925 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) |
932 | { | 926 | { |
933 | return security_ops->secid_to_secctx(secid, secdata, seclen); | 927 | return security_ops->secid_to_secctx(secid, secdata, seclen); |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 14f94cd29c80..3e37d25a9bbe 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -4713,24 +4713,6 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
4713 | return selinux_nlmsg_perm(sk, skb); | 4713 | return selinux_nlmsg_perm(sk, skb); |
4714 | } | 4714 | } |
4715 | 4715 | ||
4716 | static int selinux_netlink_recv(struct sk_buff *skb, int capability) | ||
4717 | { | ||
4718 | int err; | ||
4719 | struct common_audit_data ad; | ||
4720 | u32 sid; | ||
4721 | |||
4722 | err = cap_netlink_recv(skb, capability); | ||
4723 | if (err) | ||
4724 | return err; | ||
4725 | |||
4726 | COMMON_AUDIT_DATA_INIT(&ad, CAP); | ||
4727 | ad.u.cap = capability; | ||
4728 | |||
4729 | security_task_getsecid(current, &sid); | ||
4730 | return avc_has_perm(sid, sid, SECCLASS_CAPABILITY, | ||
4731 | CAP_TO_MASK(capability), &ad); | ||
4732 | } | ||
4733 | |||
4734 | static int ipc_alloc_security(struct task_struct *task, | 4716 | static int ipc_alloc_security(struct task_struct *task, |
4735 | struct kern_ipc_perm *perm, | 4717 | struct kern_ipc_perm *perm, |
4736 | u16 sclass) | 4718 | u16 sclass) |
@@ -5459,7 +5441,6 @@ static struct security_operations selinux_ops = { | |||
5459 | .vm_enough_memory = selinux_vm_enough_memory, | 5441 | .vm_enough_memory = selinux_vm_enough_memory, |
5460 | 5442 | ||
5461 | .netlink_send = selinux_netlink_send, | 5443 | .netlink_send = selinux_netlink_send, |
5462 | .netlink_recv = selinux_netlink_recv, | ||
5463 | 5444 | ||
5464 | .bprm_set_creds = selinux_bprm_set_creds, | 5445 | .bprm_set_creds = selinux_bprm_set_creds, |
5465 | .bprm_committing_creds = selinux_bprm_committing_creds, | 5446 | .bprm_committing_creds = selinux_bprm_committing_creds, |