Commit 7c624149 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[NETLINK]: Check connect address.

parent f8f1f469
......@@ -91,6 +91,11 @@ struct nlmsgerr
#define NET_MAJOR 36 /* Major 36 is reserved for networking */
enum {
NETLINK_UNCONNECTED = 0,
NETLINK_CONNECTED,
};
#ifdef __KERNEL__
#include <linux/capability.h>
......
......@@ -365,6 +365,7 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
struct sockaddr_nl *nladdr=(struct sockaddr_nl*)addr;
if (addr->sa_family == AF_UNSPEC) {
sk->sk_state = NETLINK_UNCONNECTED;
nlk->dst_pid = 0;
nlk->dst_groups = 0;
return 0;
......@@ -380,6 +381,7 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
err = netlink_autobind(sock);
if (err == 0) {
sk->sk_state = NETLINK_CONNECTED;
nlk->dst_pid = nladdr->nl_pid;
nlk->dst_groups = nladdr->nl_groups;
}
......@@ -427,7 +429,9 @@ struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
/* Don't bother queuing skb if kernel socket has no input function */
nlk = nlk_sk(sock);
if (nlk->pid == 0 && !nlk->data_ready) {
if ((nlk->pid == 0 && !nlk->data_ready) ||
(sock->sk_state == NETLINK_CONNECTED &&
nlk->dst_pid != nlk_sk(ssk)->pid)) {
sock_put(sock);
return ERR_PTR(-ECONNREFUSED);
}
......
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