Skip to content

Commit efbc368

Browse files
committed
ipv4: Perform peer validation on cached route lookup.
Otherwise we won't notice the peer GENID change. Reported-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8f89148 commit efbc368

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

‎net/ipv4/route.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,12 +1693,8 @@ static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
16931693
}
16941694

16951695

1696-
static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
1696+
static struct rtable *ipv4_validate_peer(struct rtable *rt)
16971697
{
1698-
struct rtable *rt = (struct rtable *) dst;
1699-
1700-
if (rt_is_expired(rt))
1701-
return NULL;
17021698
if (rt->rt_peer_genid != rt_peer_genid()) {
17031699
struct inet_peer *peer;
17041700

@@ -1707,19 +1703,29 @@ static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
17071703

17081704
peer = rt->peer;
17091705
if (peer) {
1710-
check_peer_pmtu(dst, peer);
1706+
check_peer_pmtu(&rt->dst, peer);
17111707

17121708
if (peer->redirect_genid != redirect_genid)
17131709
peer->redirect_learned.a4 = 0;
17141710
if (peer->redirect_learned.a4 &&
17151711
peer->redirect_learned.a4 != rt->rt_gateway) {
1716-
if (check_peer_redir(dst, peer))
1712+
if (check_peer_redir(&rt->dst, peer))
17171713
return NULL;
17181714
}
17191715
}
17201716

17211717
rt->rt_peer_genid = rt_peer_genid();
17221718
}
1719+
return rt;
1720+
}
1721+
1722+
static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
1723+
{
1724+
struct rtable *rt = (struct rtable *) dst;
1725+
1726+
if (rt_is_expired(rt))
1727+
return NULL;
1728+
dst = (struct dst_entry *) ipv4_validate_peer(rt);
17231729
return dst;
17241730
}
17251731

@@ -2374,6 +2380,9 @@ int ip_route_input_common(struct sk_buff *skb, __be32 daddr, __be32 saddr,
23742380
rth->rt_mark == skb->mark &&
23752381
net_eq(dev_net(rth->dst.dev), net) &&
23762382
!rt_is_expired(rth)) {
2383+
rth = ipv4_validate_peer(rth);
2384+
if (!rth)
2385+
continue;
23772386
if (noref) {
23782387
dst_use_noref(&rth->dst, jiffies);
23792388
skb_dst_set_noref(skb, &rth->dst);
@@ -2749,6 +2758,9 @@ struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *flp4)
27492758
(IPTOS_RT_MASK | RTO_ONLINK)) &&
27502759
net_eq(dev_net(rth->dst.dev), net) &&
27512760
!rt_is_expired(rth)) {
2761+
rth = ipv4_validate_peer(rth);
2762+
if (!rth)
2763+
continue;
27522764
dst_use(&rth->dst, jiffies);
27532765
RT_CACHE_STAT_INC(out_hit);
27542766
rcu_read_unlock_bh();

0 commit comments

Comments
 (0)