提交 fd778461 编写于 作者: E Eric Paris

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: NEric Paris <eparis@redhat.com>
上级 69f594a3
...@@ -111,7 +111,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb) ...@@ -111,7 +111,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
goto next_msg; goto next_msg;
} }
if (security_netlink_recv(skb, CAP_SYS_ADMIN)) { if (!capable(CAP_SYS_ADMIN)) {
err = -EPERM; err = -EPERM;
goto next_msg; goto next_msg;
} }
......
...@@ -95,7 +95,6 @@ struct xfrm_user_sec_ctx; ...@@ -95,7 +95,6 @@ struct xfrm_user_sec_ctx;
struct seq_file; struct seq_file;
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb); extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
extern int cap_netlink_recv(struct sk_buff *skb, int cap);
void reset_security_ops(void); void reset_security_ops(void);
...@@ -792,12 +791,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) ...@@ -792,12 +791,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
* @skb contains the sk_buff structure for the netlink message. * @skb contains the sk_buff structure for the netlink message.
* Return 0 if the information was successfully saved and message * Return 0 if the information was successfully saved and message
* is allowed to be transmitted. * is allowed to be transmitted.
* @netlink_recv:
* Check permission before processing the received netlink message in
* @skb.
* @skb contains the sk_buff structure for the netlink message.
* @cap indicates the capability required
* Return 0 if permission is granted.
* *
* Security hooks for Unix domain networking. * Security hooks for Unix domain networking.
* *
...@@ -1556,7 +1549,6 @@ struct security_operations { ...@@ -1556,7 +1549,6 @@ struct security_operations {
struct sembuf *sops, unsigned nsops, int alter); struct sembuf *sops, unsigned nsops, int alter);
int (*netlink_send) (struct sock *sk, struct sk_buff *skb); int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
int (*netlink_recv) (struct sk_buff *skb, int cap);
void (*d_instantiate) (struct dentry *dentry, struct inode *inode); void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
...@@ -1803,7 +1795,6 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode); ...@@ -1803,7 +1795,6 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode);
int security_getprocattr(struct task_struct *p, char *name, char **value); int security_getprocattr(struct task_struct *p, char *name, char **value);
int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size); int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_netlink_send(struct sock *sk, struct sk_buff *skb);
int security_netlink_recv(struct sk_buff *skb, int cap);
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
void security_release_secctx(char *secdata, u32 seclen); 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,11 +2469,6 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
return cap_netlink_send(sk, skb); return cap_netlink_send(sk, skb);
} }
static inline int security_netlink_recv(struct sk_buff *skb, int cap)
{
return cap_netlink_recv(skb, cap);
}
static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -601,13 +601,13 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type) ...@@ -601,13 +601,13 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
case AUDIT_TTY_SET: case AUDIT_TTY_SET:
case AUDIT_TRIM: case AUDIT_TRIM:
case AUDIT_MAKE_EQUIV: case AUDIT_MAKE_EQUIV:
if (security_netlink_recv(skb, CAP_AUDIT_CONTROL)) if (!capable(CAP_AUDIT_CONTROL))
err = -EPERM; err = -EPERM;
break; break;
case AUDIT_USER: case AUDIT_USER:
case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG: case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2: case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
if (security_netlink_recv(skb, CAP_AUDIT_WRITE)) if (!capable(CAP_AUDIT_WRITE))
err = -EPERM; err = -EPERM;
break; break;
default: /* bad msg */ default: /* bad msg */
......
...@@ -1931,7 +1931,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1931,7 +1931,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
sz_idx = type>>2; sz_idx = type>>2;
kind = type&3; kind = type&3;
if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN)) if (kind != 2 && !capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
......
...@@ -108,7 +108,7 @@ static inline void dnrmg_receive_user_skb(struct sk_buff *skb) ...@@ -108,7 +108,7 @@ static inline void dnrmg_receive_user_skb(struct sk_buff *skb)
if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
return; return;
if (security_netlink_recv(skb, CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
RCV_SKB_FAIL(-EPERM); RCV_SKB_FAIL(-EPERM);
/* Eventually we might send routing messages too */ /* Eventually we might send routing messages too */
......
...@@ -430,7 +430,7 @@ __ipq_rcv_skb(struct sk_buff *skb) ...@@ -430,7 +430,7 @@ __ipq_rcv_skb(struct sk_buff *skb)
if (type <= IPQM_BASE) if (type <= IPQM_BASE)
return; return;
if (security_netlink_recv(skb, CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
RCV_SKB_FAIL(-EPERM); RCV_SKB_FAIL(-EPERM);
spin_lock_bh(&queue_lock); spin_lock_bh(&queue_lock);
......
...@@ -431,7 +431,7 @@ __ipq_rcv_skb(struct sk_buff *skb) ...@@ -431,7 +431,7 @@ __ipq_rcv_skb(struct sk_buff *skb)
if (type <= IPQM_BASE) if (type <= IPQM_BASE)
return; return;
if (security_netlink_recv(skb, CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
RCV_SKB_FAIL(-EPERM); RCV_SKB_FAIL(-EPERM);
spin_lock_bh(&queue_lock); spin_lock_bh(&queue_lock);
......
...@@ -130,7 +130,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -130,7 +130,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
const struct nfnetlink_subsystem *ss; const struct nfnetlink_subsystem *ss;
int type, err; int type, err;
if (security_netlink_recv(skb, CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
/* All the messages must at least contain nfgenmsg */ /* All the messages must at least contain nfgenmsg */
......
...@@ -516,7 +516,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -516,7 +516,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if ((ops->flags & GENL_ADMIN_PERM) && if ((ops->flags & GENL_ADMIN_PERM) &&
security_netlink_recv(skb, CAP_NET_ADMIN)) !capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
......
...@@ -2290,7 +2290,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2290,7 +2290,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
link = &xfrm_dispatch[type]; link = &xfrm_dispatch[type];
/* All operations require privileges, even GET */ /* All operations require privileges, even GET */
if (security_netlink_recv(skb, CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) || if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) ||
......
...@@ -999,7 +999,6 @@ void __init security_fixup_ops(struct security_operations *ops) ...@@ -999,7 +999,6 @@ void __init security_fixup_ops(struct security_operations *ops)
set_to_cap_if_null(ops, sem_semctl); set_to_cap_if_null(ops, sem_semctl);
set_to_cap_if_null(ops, sem_semop); set_to_cap_if_null(ops, sem_semop);
set_to_cap_if_null(ops, netlink_send); set_to_cap_if_null(ops, netlink_send);
set_to_cap_if_null(ops, netlink_recv);
set_to_cap_if_null(ops, d_instantiate); set_to_cap_if_null(ops, d_instantiate);
set_to_cap_if_null(ops, getprocattr); set_to_cap_if_null(ops, getprocattr);
set_to_cap_if_null(ops, setprocattr); set_to_cap_if_null(ops, setprocattr);
......
...@@ -56,14 +56,6 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb) ...@@ -56,14 +56,6 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
} }
int cap_netlink_recv(struct sk_buff *skb, int cap)
{
if (!cap_raised(current_cap(), cap))
return -EPERM;
return 0;
}
EXPORT_SYMBOL(cap_netlink_recv);
/** /**
* cap_capable - Determine whether a task has a particular effective capability * cap_capable - Determine whether a task has a particular effective capability
* @cred: The credentials to use * @cred: The credentials to use
......
...@@ -922,12 +922,6 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb) ...@@ -922,12 +922,6 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb)
return security_ops->netlink_send(sk, skb); return security_ops->netlink_send(sk, skb);
} }
int security_netlink_recv(struct sk_buff *skb, int cap)
{
return security_ops->netlink_recv(skb, cap);
}
EXPORT_SYMBOL(security_netlink_recv);
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
{ {
return security_ops->secid_to_secctx(secid, secdata, seclen); return security_ops->secid_to_secctx(secid, secdata, seclen);
......
...@@ -4713,24 +4713,6 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) ...@@ -4713,24 +4713,6 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
return selinux_nlmsg_perm(sk, skb); return selinux_nlmsg_perm(sk, skb);
} }
static int selinux_netlink_recv(struct sk_buff *skb, int capability)
{
int err;
struct common_audit_data ad;
u32 sid;
err = cap_netlink_recv(skb, capability);
if (err)
return err;
COMMON_AUDIT_DATA_INIT(&ad, CAP);
ad.u.cap = capability;
security_task_getsecid(current, &sid);
return avc_has_perm(sid, sid, SECCLASS_CAPABILITY,
CAP_TO_MASK(capability), &ad);
}
static int ipc_alloc_security(struct task_struct *task, static int ipc_alloc_security(struct task_struct *task,
struct kern_ipc_perm *perm, struct kern_ipc_perm *perm,
u16 sclass) u16 sclass)
...@@ -5459,7 +5441,6 @@ static struct security_operations selinux_ops = { ...@@ -5459,7 +5441,6 @@ static struct security_operations selinux_ops = {
.vm_enough_memory = selinux_vm_enough_memory, .vm_enough_memory = selinux_vm_enough_memory,
.netlink_send = selinux_netlink_send, .netlink_send = selinux_netlink_send,
.netlink_recv = selinux_netlink_recv,
.bprm_set_creds = selinux_bprm_set_creds, .bprm_set_creds = selinux_bprm_set_creds,
.bprm_committing_creds = selinux_bprm_committing_creds, .bprm_committing_creds = selinux_bprm_committing_creds,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册