Skip to content

Commit 242afaa

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: 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: 6371a71 ("net/ipv6: Add support for dumping addresses for a specific device") Fixes: ed6eff1 ("net/ipv6: Update inet6_dump_addr for strict data checking") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d7e3861 commit 242afaa

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/ipv6/addrconf.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5089,23 +5089,25 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
50895089
struct net_device *dev;
50905090
struct inet6_dev *idev;
50915091
struct hlist_head *head;
5092+
int err = 0;
50925093

50935094
s_h = cb->args[0];
50945095
s_idx = idx = cb->args[1];
50955096
s_ip_idx = cb->args[2];
50965097

50975098
if (cb->strict_check) {
5098-
int err;
5099-
51005099
err = inet6_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
51015100
skb->sk, cb);
51025101
if (err < 0)
5103-
return err;
5102+
goto put_tgt_net;
51045103

5104+
err = 0;
51055105
if (fillargs.ifindex) {
51065106
dev = __dev_get_by_index(tgt_net, fillargs.ifindex);
5107-
if (!dev)
5108-
return -ENODEV;
5107+
if (!dev) {
5108+
err = -ENODEV;
5109+
goto put_tgt_net;
5110+
}
51095111
idev = __in6_dev_get(dev);
51105112
if (idev) {
51115113
err = in6_dump_addrs(idev, skb, cb, s_ip_idx,
@@ -5144,7 +5146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
51445146
if (fillargs.netnsid >= 0)
51455147
put_net(tgt_net);
51465148

5147-
return skb->len;
5149+
return err < 0 ? err : skb->len;
51485150
}
51495151

51505152
static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)

0 commit comments

Comments
 (0)