Commit d7e38611 authored by David Ahern's avatar David Ahern Committed by David S. Miller

net/ipv4: Put target net when address dump fails due to bad attributes

If tgt_net is set based on IFA_TARGET_NETNSID attribute in the dump
request, make sure all error paths call put_net.

Fixes: 5fcd266a ("net/ipv4: Add support for dumping addresses for a specific device")
Fixes: c33078e3 ("net/ipv4: Update inet_dump_ifaddr for strict data checking")
Reported-by: default avatarLi RongQing <lirongqing@baidu.com>
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 01aa9d51
...@@ -1761,7 +1761,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1761,7 +1761,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
struct net_device *dev; struct net_device *dev;
struct in_device *in_dev; struct in_device *in_dev;
struct hlist_head *head; struct hlist_head *head;
int err; int err = 0;
s_h = cb->args[0]; s_h = cb->args[0];
s_idx = idx = cb->args[1]; s_idx = idx = cb->args[1];
...@@ -1771,12 +1771,15 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1771,12 +1771,15 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net, err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
skb->sk, cb); skb->sk, cb);
if (err < 0) if (err < 0)
return err; goto put_tgt_net;
err = 0;
if (fillargs.ifindex) { if (fillargs.ifindex) {
dev = __dev_get_by_index(tgt_net, fillargs.ifindex); dev = __dev_get_by_index(tgt_net, fillargs.ifindex);
if (!dev) if (!dev) {
return -ENODEV; err = -ENODEV;
goto put_tgt_net;
}
in_dev = __in_dev_get_rtnl(dev); in_dev = __in_dev_get_rtnl(dev);
if (in_dev) { if (in_dev) {
...@@ -1821,7 +1824,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1821,7 +1824,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
if (fillargs.netnsid >= 0) if (fillargs.netnsid >= 0)
put_net(tgt_net); put_net(tgt_net);
return skb->len; return err < 0 ? err : skb->len;
} }
static void rtmsg_ifa(int event, struct in_ifaddr *ifa, struct nlmsghdr *nlh, static void rtmsg_ifa(int event, struct in_ifaddr *ifa, struct nlmsghdr *nlh,
......
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