Commit c3bb1361 authored by James Morris's avatar James Morris

[NET]: Backport netlink_set_nonroot changes by Andi Kleen.

parent 41e76c56
...@@ -162,6 +162,10 @@ extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, ...@@ -162,6 +162,10 @@ extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
int (*done)(struct netlink_callback*)); int (*done)(struct netlink_callback*));
#define NL_NONROOT_RECV 0x1
#define NL_NONROOT_SEND 0x2
extern void netlink_set_nonroot(int protocol, unsigned flag);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* __LINUX_NETLINK_H */ #endif /* __LINUX_NETLINK_H */
...@@ -523,6 +523,7 @@ void __init rtnetlink_init(void) ...@@ -523,6 +523,7 @@ void __init rtnetlink_init(void)
rtnl = netlink_kernel_create(NETLINK_ROUTE, rtnetlink_rcv); rtnl = netlink_kernel_create(NETLINK_ROUTE, rtnetlink_rcv);
if (rtnl == NULL) if (rtnl == NULL)
panic("rtnetlink_init: cannot initialize rtnetlink\n"); panic("rtnetlink_init: cannot initialize rtnetlink\n");
netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);
register_netdevice_notifier(&rtnetlink_dev_notifier); register_netdevice_notifier(&rtnetlink_dev_notifier);
rtnetlink_links[PF_UNSPEC] = link_rtnetlink_table; rtnetlink_links[PF_UNSPEC] = link_rtnetlink_table;
rtnetlink_links[PF_PACKET] = link_rtnetlink_table; rtnetlink_links[PF_PACKET] = link_rtnetlink_table;
......
...@@ -69,6 +69,7 @@ struct netlink_opt ...@@ -69,6 +69,7 @@ struct netlink_opt
static struct sock *nl_table[MAX_LINKS]; static struct sock *nl_table[MAX_LINKS];
static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait); static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait);
static unsigned nl_nonroot[MAX_LINKS];
#ifdef NL_EMULATE_DEV #ifdef NL_EMULATE_DEV
static struct socket *netlink_kernel[MAX_LINKS]; static struct socket *netlink_kernel[MAX_LINKS];
...@@ -317,6 +318,11 @@ static int netlink_autobind(struct socket *sock) ...@@ -317,6 +318,11 @@ static int netlink_autobind(struct socket *sock)
return 0; return 0;
} }
static inline int netlink_capable(struct socket *sock, unsigned flag)
{
return (nl_nonroot[sock->sk->protocol] & flag) || capable(CAP_NET_ADMIN);
}
static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len) static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -328,7 +334,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len ...@@ -328,7 +334,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len
return -EINVAL; return -EINVAL;
/* Only superuser is allowed to listen multicasts */ /* Only superuser is allowed to listen multicasts */
if (nladdr->nl_groups && !capable(CAP_NET_ADMIN)) if (nladdr->nl_groups && !netlink_capable(sock, NL_NONROOT_RECV))
return -EPERM; return -EPERM;
if (nlk->pid) { if (nlk->pid) {
...@@ -368,7 +374,7 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr, ...@@ -368,7 +374,7 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
return -EINVAL; return -EINVAL;
/* Only superuser is allowed to send multicasts */ /* Only superuser is allowed to send multicasts */
if (nladdr->nl_groups && !capable(CAP_NET_ADMIN)) if (nladdr->nl_groups && !netlink_capable(sock, NL_NONROOT_SEND))
return -EPERM; return -EPERM;
if (!nlk->pid) if (!nlk->pid)
...@@ -590,7 +596,7 @@ static int netlink_sendmsg(struct kiocb *iocb, struct socket *sock, ...@@ -590,7 +596,7 @@ static int netlink_sendmsg(struct kiocb *iocb, struct socket *sock,
return -EINVAL; return -EINVAL;
dst_pid = addr->nl_pid; dst_pid = addr->nl_pid;
dst_groups = addr->nl_groups; dst_groups = addr->nl_groups;
if (dst_groups && !capable(CAP_NET_ADMIN)) if (dst_groups && !netlink_capable(sock, NL_NONROOT_SEND))
return -EPERM; return -EPERM;
} else { } else {
dst_pid = nlk->dst_pid; dst_pid = nlk->dst_pid;
...@@ -743,6 +749,12 @@ netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)) ...@@ -743,6 +749,12 @@ netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len))
return sk; return sk;
} }
void netlink_set_nonroot(int protocol, unsigned flags)
{
if ((unsigned)protocol < MAX_LINKS)
nl_nonroot[protocol] = flags;
}
static void netlink_destroy_callback(struct netlink_callback *cb) static void netlink_destroy_callback(struct netlink_callback *cb)
{ {
if (cb->skb) if (cb->skb)
......
...@@ -408,6 +408,7 @@ EXPORT_SYMBOL(netlink_unicast); ...@@ -408,6 +408,7 @@ EXPORT_SYMBOL(netlink_unicast);
EXPORT_SYMBOL(netlink_kernel_create); EXPORT_SYMBOL(netlink_kernel_create);
EXPORT_SYMBOL(netlink_dump_start); EXPORT_SYMBOL(netlink_dump_start);
EXPORT_SYMBOL(netlink_ack); EXPORT_SYMBOL(netlink_ack);
EXPORT_SYMBOL(netlink_set_nonroot);
EXPORT_SYMBOL(netlink_register_notifier); EXPORT_SYMBOL(netlink_register_notifier);
EXPORT_SYMBOL(netlink_unregister_notifier); EXPORT_SYMBOL(netlink_unregister_notifier);
#if defined(CONFIG_NETLINK_DEV) || defined(CONFIG_NETLINK_DEV_MODULE) #if defined(CONFIG_NETLINK_DEV) || defined(CONFIG_NETLINK_DEV_MODULE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment