aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink/af_netlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/netlink/af_netlink.c')
-rw-r--r--net/netlink/af_netlink.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 19e98007691c..795424396aff 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -428,7 +428,8 @@ static int __netlink_create(struct net *net, struct socket *sock,
428 return 0; 428 return 0;
429} 429}
430 430
431static int netlink_create(struct net *net, struct socket *sock, int protocol) 431static int netlink_create(struct net *net, struct socket *sock, int protocol,
432 int kern)
432{ 433{
433 struct module *module = NULL; 434 struct module *module = NULL;
434 struct mutex *cb_mutex; 435 struct mutex *cb_mutex;
@@ -454,9 +455,14 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol)
454 if (nl_table[protocol].registered && 455 if (nl_table[protocol].registered &&
455 try_module_get(nl_table[protocol].module)) 456 try_module_get(nl_table[protocol].module))
456 module = nl_table[protocol].module; 457 module = nl_table[protocol].module;
458 else
459 err = -EPROTONOSUPPORT;
457 cb_mutex = nl_table[protocol].cb_mutex; 460 cb_mutex = nl_table[protocol].cb_mutex;
458 netlink_unlock_table(); 461 netlink_unlock_table();
459 462
463 if (err < 0)
464 goto out;
465
460 err = __netlink_create(net, sock, cb_mutex, protocol); 466 err = __netlink_create(net, sock, cb_mutex, protocol);
461 if (err < 0) 467 if (err < 0)
462 goto out_module; 468 goto out_module;
@@ -497,7 +503,7 @@ static int netlink_release(struct socket *sock)
497 503
498 skb_queue_purge(&sk->sk_write_queue); 504 skb_queue_purge(&sk->sk_write_queue);
499 505
500 if (nlk->pid && !nlk->subscriptions) { 506 if (nlk->pid) {
501 struct netlink_notify n = { 507 struct netlink_notify n = {
502 .net = sock_net(sk), 508 .net = sock_net(sk),
503 .protocol = sk->sk_protocol, 509 .protocol = sk->sk_protocol,
@@ -677,6 +683,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
677 struct netlink_sock *nlk = nlk_sk(sk); 683 struct netlink_sock *nlk = nlk_sk(sk);
678 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 684 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
679 685
686 if (alen < sizeof(addr->sa_family))
687 return -EINVAL;
688
680 if (addr->sa_family == AF_UNSPEC) { 689 if (addr->sa_family == AF_UNSPEC) {
681 sk->sk_state = NETLINK_UNCONNECTED; 690 sk->sk_state = NETLINK_UNCONNECTED;
682 nlk->dst_pid = 0; 691 nlk->dst_pid = 0;
@@ -707,7 +716,7 @@ static int netlink_getname(struct socket *sock, struct sockaddr *addr,
707{ 716{
708 struct sock *sk = sock->sk; 717 struct sock *sk = sock->sk;
709 struct netlink_sock *nlk = nlk_sk(sk); 718 struct netlink_sock *nlk = nlk_sk(sk);
710 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 719 DECLARE_SOCKADDR(struct sockaddr_nl *, nladdr, addr);
711 720
712 nladdr->nl_family = AF_NETLINK; 721 nladdr->nl_family = AF_NETLINK;
713 nladdr->nl_pad = 0; 722 nladdr->nl_pad = 0;
@@ -1087,21 +1096,27 @@ static inline int do_one_set_err(struct sock *sk,
1087 struct netlink_set_err_data *p) 1096 struct netlink_set_err_data *p)
1088{ 1097{
1089 struct netlink_sock *nlk = nlk_sk(sk); 1098 struct netlink_sock *nlk = nlk_sk(sk);
1099 int ret = 0;
1090 1100
1091 if (sk == p->exclude_sk) 1101 if (sk == p->exclude_sk)
1092 goto out; 1102 goto out;
1093 1103
1094 if (sock_net(sk) != sock_net(p->exclude_sk)) 1104 if (!net_eq(sock_net(sk), sock_net(p->exclude_sk)))
1095 goto out; 1105 goto out;
1096 1106
1097 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups || 1107 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups ||
1098 !test_bit(p->group - 1, nlk->groups)) 1108 !test_bit(p->group - 1, nlk->groups))
1099 goto out; 1109 goto out;
1100 1110
1111 if (p->code == ENOBUFS && nlk->flags & NETLINK_RECV_NO_ENOBUFS) {
1112 ret = 1;
1113 goto out;
1114 }
1115
1101 sk->sk_err = p->code; 1116 sk->sk_err = p->code;
1102 sk->sk_error_report(sk); 1117 sk->sk_error_report(sk);
1103out: 1118out:
1104 return 0; 1119 return ret;
1105} 1120}
1106 1121
1107/** 1122/**
@@ -1110,12 +1125,16 @@ out:
1110 * @pid: the PID of a process that we want to skip (if any) 1125 * @pid: the PID of a process that we want to skip (if any)
1111 * @groups: the broadcast group that will notice the error 1126 * @groups: the broadcast group that will notice the error
1112 * @code: error code, must be negative (as usual in kernelspace) 1127 * @code: error code, must be negative (as usual in kernelspace)
1128 *
1129 * This function returns the number of broadcast listeners that have set the
1130 * NETLINK_RECV_NO_ENOBUFS socket option.
1113 */ 1131 */
1114void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) 1132int netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
1115{ 1133{
1116 struct netlink_set_err_data info; 1134 struct netlink_set_err_data info;
1117 struct hlist_node *node; 1135 struct hlist_node *node;
1118 struct sock *sk; 1136 struct sock *sk;
1137 int ret = 0;
1119 1138
1120 info.exclude_sk = ssk; 1139 info.exclude_sk = ssk;
1121 info.pid = pid; 1140 info.pid = pid;
@@ -1126,9 +1145,10 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
1126 read_lock(&nl_table_lock); 1145 read_lock(&nl_table_lock);
1127 1146
1128 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) 1147 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list)
1129 do_one_set_err(sk, &info); 1148 ret += do_one_set_err(sk, &info);
1130 1149
1131 read_unlock(&nl_table_lock); 1150 read_unlock(&nl_table_lock);
1151 return ret;
1132} 1152}
1133EXPORT_SYMBOL(netlink_set_err); 1153EXPORT_SYMBOL(netlink_set_err);
1134 1154
@@ -1972,12 +1992,12 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
1972 if (v == SEQ_START_TOKEN) 1992 if (v == SEQ_START_TOKEN)
1973 seq_puts(seq, 1993 seq_puts(seq,
1974 "sk Eth Pid Groups " 1994 "sk Eth Pid Groups "
1975 "Rmem Wmem Dump Locks Drops\n"); 1995 "Rmem Wmem Dump Locks Drops Inode\n");
1976 else { 1996 else {
1977 struct sock *s = v; 1997 struct sock *s = v;
1978 struct netlink_sock *nlk = nlk_sk(s); 1998 struct netlink_sock *nlk = nlk_sk(s);
1979 1999
1980 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d\n", 2000 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
1981 s, 2001 s,
1982 s->sk_protocol, 2002 s->sk_protocol,
1983 nlk->pid, 2003 nlk->pid,
@@ -1986,7 +2006,8 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
1986 sk_wmem_alloc_get(s), 2006 sk_wmem_alloc_get(s),
1987 nlk->cb, 2007 nlk->cb,
1988 atomic_read(&s->sk_refcnt), 2008 atomic_read(&s->sk_refcnt),
1989 atomic_read(&s->sk_drops) 2009 atomic_read(&s->sk_drops),
2010 sock_i_ino(s)
1990 ); 2011 );
1991 2012
1992 } 2013 }
@@ -2050,7 +2071,7 @@ static const struct proto_ops netlink_ops = {
2050 .sendpage = sock_no_sendpage, 2071 .sendpage = sock_no_sendpage,
2051}; 2072};
2052 2073
2053static struct net_proto_family netlink_family_ops = { 2074static const struct net_proto_family netlink_family_ops = {
2054 .family = PF_NETLINK, 2075 .family = PF_NETLINK,
2055 .create = netlink_create, 2076 .create = netlink_create,
2056 .owner = THIS_MODULE, /* for consistency 8) */ 2077 .owner = THIS_MODULE, /* for consistency 8) */