Skip to content

Commit d7e3861

Browse files
dsaherndavem330
authored andcommitted
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: 5fcd266 ("net/ipv4: Add support for dumping addresses for a specific device") Fixes: c33078e ("net/ipv4: Update inet_dump_ifaddr for strict data checking") Reported-by: Li RongQing <[email protected]> Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 01aa9d5 commit d7e3861

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/ipv4/devinet.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
17611761
struct net_device *dev;
17621762
struct in_device *in_dev;
17631763
struct hlist_head *head;
1764-
int err;
1764+
int err = 0;
17651765

17661766
s_h = cb->args[0];
17671767
s_idx = idx = cb->args[1];
@@ -1771,12 +1771,15 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
17711771
err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
17721772
skb->sk, cb);
17731773
if (err < 0)
1774-
return err;
1774+
goto put_tgt_net;
17751775

1776+
err = 0;
17761777
if (fillargs.ifindex) {
17771778
dev = __dev_get_by_index(tgt_net, fillargs.ifindex);
1778-
if (!dev)
1779-
return -ENODEV;
1779+
if (!dev) {
1780+
err = -ENODEV;
1781+
goto put_tgt_net;
1782+
}
17801783

17811784
in_dev = __in_dev_get_rtnl(dev);
17821785
if (in_dev) {
@@ -1821,7 +1824,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
18211824
if (fillargs.netnsid >= 0)
18221825
put_net(tgt_net);
18231826

1824-
return skb->len;
1827+
return err < 0 ? err : skb->len;
18251828
}
18261829

18271830
static void rtmsg_ifa(int event, struct in_ifaddr *ifa, struct nlmsghdr *nlh,

0 commit comments

Comments
 (0)