[ Upstream commit
b44108dbdbaa07c609bb5755e8dd6c2035236251 ]
git commit
9cb3a50c (ipv4: Invalidate the socket cached route on
pmtu events if possible) introduced a refcount problem. We don't
get a refcount on the route if we get it from__sk_dst_get(), but
we need one if we want to reuse this route because __sk_dst_set()
releases the refcount of the old route. This patch adds proper
refcount handling for that case. We introduce a 'new' flag to
indicate that we are going to use a new route and we release the
old route only if we replace it by a new one.
Reported-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
struct flowi4 fl4;
struct rtable *rt;
struct dst_entry *dst;
+ bool new = false;
bh_lock_sock(sk);
rt = (struct rtable *) __sk_dst_get(sk);
rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
if (IS_ERR(rt))
goto out;
+
+ new = true;
}
__ip_rt_update_pmtu((struct rtable *) rt->dst.path, &fl4, mtu);
dst = dst_check(&rt->dst, 0);
if (!dst) {
+ if (new)
+ dst_release(&rt->dst);
+
rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
if (IS_ERR(rt))
goto out;
- dst = &rt->dst;
+ new = true;
}
- __sk_dst_set(sk, dst);
+ if (new)
+ __sk_dst_set(sk, &rt->dst);
out:
bh_unlock_sock(sk);