net/{ipv4,ipv6}: Do not put target net if input nsid is invalid
authorBjørn Mork <bjorn@mork.no>
Thu, 25 Oct 2018 19:18:25 +0000 (21:18 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 Oct 2018 23:21:31 +0000 (16:21 -0700)
The cleanup path will put the target net when netnsid is set.  So we must
reset netnsid if the input is invalid.

Fixes: d7e38611b81e ("net/ipv4: Put target net when address dump fails due to bad attributes")
Fixes: 242afaa6968c ("net/ipv6: Put target net when address dump fails due to bad attributes")
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/devinet.c
net/ipv6/addrconf.c

index 9250b309c742d629eb6f76307d668f828793c0ed..a34602ae27dee2d3ff5d579172910c5f9f004292 100644 (file)
@@ -1704,6 +1704,7 @@ static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
 
                        net = rtnl_get_net_ns_capable(sk, fillargs->netnsid);
                        if (IS_ERR(net)) {
+                               fillargs->netnsid = -1;
                                NL_SET_ERR_MSG(extack, "ipv4: Invalid target network namespace id");
                                return PTR_ERR(net);
                        }
index 7eb09c86fa130a6ce492297b8ec5e172f47ea691..63a808d5af1575255ae9ef16aeb9a2a9549571d5 100644 (file)
@@ -5058,6 +5058,7 @@ static int inet6_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
                        fillargs->netnsid = nla_get_s32(tb[i]);
                        net = rtnl_get_net_ns_capable(sk, fillargs->netnsid);
                        if (IS_ERR(net)) {
+                               fillargs->netnsid = -1;
                                NL_SET_ERR_MSG_MOD(extack, "Invalid target network namespace id");
                                return PTR_ERR(net);
                        }