diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 5b6b11c943e4..f9a361621f74 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2379,8 +2379,8 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, struct net *net = sock_net(in_skb->sk); struct nlattr *tb[NETCONFA_MAX + 1]; const struct ipv4_devconf *devconf; - struct in_device *in_dev = NULL; - struct net_device *dev = NULL; + struct in_device *in_dev; + struct net_device *dev; struct sk_buff *skb; int ifindex; int err; @@ -2392,7 +2392,13 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, if (!tb[NETCONFA_IFINDEX]) return -EINVAL; + skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL); + if (!skb) + return -ENOBUFS; + ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]); + + rcu_read_lock(); switch (ifindex) { case NETCONFA_IFINDEX_ALL: devconf = net->ipv4.devconf_all; @@ -2402,36 +2408,29 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, break; default: err = -ENODEV; - dev = dev_get_by_index(net, ifindex); - if (dev) - in_dev = in_dev_get(dev); + dev = dev_get_by_index_rcu(net, ifindex); + if (!dev) + goto out_unlock; + in_dev = __in_dev_get_rcu(dev); if (!in_dev) - goto errout; + goto out_unlock; devconf = &in_dev->cnf; break; } - err = -ENOBUFS; - skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL); - if (!skb) - goto errout; - err = inet_netconf_fill_devconf(skb, ifindex, devconf, NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, RTM_NEWNETCONF, 0, NETCONFA_ALL); +out_unlock: + rcu_read_unlock(); if (err < 0) { /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ WARN_ON(err == -EMSGSIZE); kfree_skb(skb); - goto errout; + return err; } - err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); -errout: - if (in_dev) - in_dev_put(in_dev); - dev_put(dev); - return err; + return rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); } static int inet_netconf_dump_devconf(struct sk_buff *skb,