Commit 4ea2607f authored by Florian Westphal's avatar Florian Westphal Committed by David S. Miller

ipv6: addrconf: don't use rtnl mutex in RTM_GETNETCONF

Instead of relying on rtnl mutex bump device reference count.
After this change, values reported can change in parallel, but thats not
much different from current state, as anyone can change the settings
right after rtnl_unlock (and before userspace processed reply).

While at it, switch to GFP_KERNEL allocation.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b274f6db
...@@ -616,23 +616,23 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -616,23 +616,23 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
{ {
struct net *net = sock_net(in_skb->sk); struct net *net = sock_net(in_skb->sk);
struct nlattr *tb[NETCONFA_MAX+1]; struct nlattr *tb[NETCONFA_MAX+1];
struct inet6_dev *in6_dev = NULL;
struct net_device *dev = NULL;
struct netconfmsg *ncm; struct netconfmsg *ncm;
struct sk_buff *skb; struct sk_buff *skb;
struct ipv6_devconf *devconf; struct ipv6_devconf *devconf;
struct inet6_dev *in6_dev;
struct net_device *dev;
int ifindex; int ifindex;
int err; int err;
err = nlmsg_parse(nlh, sizeof(*ncm), tb, NETCONFA_MAX, err = nlmsg_parse(nlh, sizeof(*ncm), tb, NETCONFA_MAX,
devconf_ipv6_policy, extack); devconf_ipv6_policy, extack);
if (err < 0) if (err < 0)
goto errout; return err;
err = -EINVAL;
if (!tb[NETCONFA_IFINDEX]) if (!tb[NETCONFA_IFINDEX])
goto errout; return -EINVAL;
err = -EINVAL;
ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]); ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]);
switch (ifindex) { switch (ifindex) {
case NETCONFA_IFINDEX_ALL: case NETCONFA_IFINDEX_ALL:
...@@ -642,10 +642,10 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -642,10 +642,10 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
devconf = net->ipv6.devconf_dflt; devconf = net->ipv6.devconf_dflt;
break; break;
default: default:
dev = __dev_get_by_index(net, ifindex); dev = dev_get_by_index(net, ifindex);
if (!dev) if (!dev)
goto errout; return -EINVAL;
in6_dev = __in6_dev_get(dev); in6_dev = in6_dev_get(dev);
if (!in6_dev) if (!in6_dev)
goto errout; goto errout;
devconf = &in6_dev->cnf; devconf = &in6_dev->cnf;
...@@ -653,7 +653,7 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -653,7 +653,7 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
} }
err = -ENOBUFS; err = -ENOBUFS;
skb = nlmsg_new(inet6_netconf_msgsize_devconf(NETCONFA_ALL), GFP_ATOMIC); skb = nlmsg_new(inet6_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL);
if (!skb) if (!skb)
goto errout; goto errout;
...@@ -669,6 +669,10 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -669,6 +669,10 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
} }
err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
errout: errout:
if (in6_dev)
in6_dev_put(in6_dev);
if (dev)
dev_put(dev);
return err; return err;
} }
...@@ -6570,7 +6574,7 @@ int __init addrconf_init(void) ...@@ -6570,7 +6574,7 @@ int __init addrconf_init(void)
__rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, __rtnl_register(PF_INET6, RTM_GETANYCAST, NULL,
inet6_dump_ifacaddr, 0); inet6_dump_ifacaddr, 0);
__rtnl_register(PF_INET6, RTM_GETNETCONF, inet6_netconf_get_devconf, __rtnl_register(PF_INET6, RTM_GETNETCONF, inet6_netconf_get_devconf,
inet6_netconf_dump_devconf, 0); inet6_netconf_dump_devconf, RTNL_FLAG_DOIT_UNLOCKED);
ipv6_addr_label_rtnl_register(); ipv6_addr_label_rtnl_register();
......
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