X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=net%2Fnetlink%2Faf_netlink.c;h=e73d8f546c6bf075d4a4d7c591b1258e5c571408;hb=d486dd1fb8573fad5b8dab61a7d1406116fd4baf;hp=d56e0d21f919dc581df426af4511ee8e52f07155;hpb=a4c12d6c5dde48c69464baf7c703e425ee511433;p=linux-2.6-omap-h63xx.git diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index d56e0d21f91..e73d8f546c6 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -8,7 +8,7 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. - * + * * Tue Jun 26 14:36:48 MEST 2001 Herbert "herp" Rosmanith * added netlink_proto_exit * Tue Jan 22 18:32:44 BRST 2002 Arnaldo C. de Melo @@ -470,10 +470,9 @@ static int netlink_release(struct socket *sock) }; atomic_notifier_call_chain(&netlink_chain, NETLINK_URELEASE, &n); - } + } - if (nlk->module) - module_put(nlk->module); + module_put(nlk->module); netlink_table_grab(); if (nlk->flags & NETLINK_KERNEL_SOCKET) { @@ -529,11 +528,11 @@ retry: return err; } -static inline int netlink_capable(struct socket *sock, unsigned int flag) -{ +static inline int netlink_capable(struct socket *sock, unsigned int flag) +{ return (nl_table[sock->sk->sk_protocol].nl_nonroot & flag) || capable(CAP_NET_ADMIN); -} +} static void netlink_update_subscriptions(struct sock *sk, unsigned int subscriptions) @@ -575,7 +574,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len struct netlink_sock *nlk = nlk_sk(sk); struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; int err; - + if (nladdr->nl_family != AF_NETLINK) return -EINVAL; @@ -606,9 +605,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len netlink_table_grab(); netlink_update_subscriptions(sk, nlk->subscriptions + - hweight32(nladdr->nl_groups) - - hweight32(nlk->groups[0])); - nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | nladdr->nl_groups; + hweight32(nladdr->nl_groups) - + hweight32(nlk->groups[0])); + nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | nladdr->nl_groups; netlink_update_listeners(sk); netlink_table_ungrab(); @@ -653,7 +652,7 @@ static int netlink_getname(struct socket *sock, struct sockaddr *addr, int *addr struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); struct sockaddr_nl *nladdr=(struct sockaddr_nl *)addr; - + nladdr->nl_family = AF_NETLINK; nladdr->nl_pad = 0; *addr_len = sizeof(*nladdr); @@ -699,7 +698,7 @@ static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid) struct sock *netlink_getsockbyfilp(struct file *filp) { - struct inode *inode = filp->f_dentry->d_inode; + struct inode *inode = filp->f_path.dentry->d_inode; struct sock *sock; if (!S_ISSOCK(inode->i_mode)) @@ -1000,7 +999,7 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) } static int netlink_setsockopt(struct socket *sock, int level, int optname, - char __user *optval, int optlen) + char __user *optval, int optlen) { struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); @@ -1055,7 +1054,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, } static int netlink_getsockopt(struct socket *sock, int level, int optname, - char __user *optval, int __user *optlen) + char __user *optval, int __user *optlen) { struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); @@ -1075,8 +1074,9 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, return -EINVAL; len = sizeof(int); val = nlk->flags & NETLINK_RECV_PKTINFO ? 1 : 0; - put_user(len, optlen); - put_user(val, optval); + if (put_user(len, optlen) || + put_user(val, optval)) + return -EFAULT; err = 0; break; default: @@ -1147,12 +1147,11 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock, if (len > sk->sk_sndbuf - 32) goto out; err = -ENOBUFS; - skb = nlmsg_new(len, GFP_KERNEL); + skb = alloc_skb(len, GFP_KERNEL); if (skb==NULL) goto out; NETLINK_CB(skb).pid = nlk->pid; - NETLINK_CB(skb).dst_pid = dst_pid; NETLINK_CB(skb).dst_group = dst_group; NETLINK_CB(skb).loginuid = audit_get_loginuid(current->audit_context); selinux_get_task_sid(current, &(NETLINK_CB(skb).sid)); @@ -1258,15 +1257,15 @@ static void netlink_data_ready(struct sock *sk, int len) } /* - * We export these functions to other modules. They provide a + * We export these functions to other modules. They provide a * complete set of kernel non-blocking support for message * queueing. */ struct sock * netlink_kernel_create(int unit, unsigned int groups, - void (*input)(struct sock *sk, int len), - struct module *module) + void (*input)(struct sock *sk, int len), + struct module *module) { struct socket *sock; struct sock *sk; @@ -1318,10 +1317,10 @@ out_sock_release: } void netlink_set_nonroot(int protocol, unsigned int flags) -{ - if ((unsigned int)protocol < MAX_LINKS) +{ + if ((unsigned int)protocol < MAX_LINKS) nl_table[protocol].nl_nonroot = flags; -} +} static void netlink_destroy_callback(struct netlink_callback *cb) { @@ -1342,7 +1341,7 @@ static int netlink_dump(struct sock *sk) struct sk_buff *skb; struct nlmsghdr *nlh; int len, err = -ENOBUFS; - + skb = sock_rmalloc(sk, NLMSG_GOODSIZE, 0, GFP_KERNEL); if (!skb) goto errout; @@ -1434,14 +1433,13 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err) struct sk_buff *skb; struct nlmsghdr *rep; struct nlmsgerr *errmsg; - int size; + size_t payload = sizeof(*errmsg); - if (err == 0) - size = nlmsg_total_size(sizeof(*errmsg)); - else - size = nlmsg_total_size(sizeof(*errmsg) + nlmsg_len(nlh)); + /* error messages get the original request appened */ + if (err) + payload += nlmsg_len(nlh); - skb = nlmsg_new(size, GFP_KERNEL); + skb = nlmsg_new(payload, GFP_KERNEL); if (!skb) { struct sock *sk; @@ -1628,7 +1626,7 @@ static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos) if (v == SEQ_START_TOKEN) return netlink_seq_socket_idx(seq, 0); - + s = sk_next(v); if (s) return s; @@ -1715,7 +1713,7 @@ static int netlink_seq_open(struct inode *inode, struct file *file) return 0; } -static struct file_operations netlink_seq_fops = { +static const struct file_operations netlink_seq_fops = { .owner = THIS_MODULE, .open = netlink_seq_open, .read = seq_read, @@ -1734,7 +1732,7 @@ int netlink_unregister_notifier(struct notifier_block *nb) { return atomic_notifier_chain_unregister(&netlink_chain, nb); } - + static const struct proto_ops netlink_ops = { .family = PF_NETLINK, .owner = THIS_MODULE, @@ -1810,7 +1808,7 @@ static int __init netlink_proto_init(void) #ifdef CONFIG_PROC_FS proc_net_fops_create("netlink", 0, &netlink_seq_fops); #endif - /* The netlink device handler may be needed early. */ + /* The netlink device handler may be needed early. */ rtnetlink_init(); out: return err;