Skip to content

Commit e5a51bb

Browse files
klassertJiri Slaby
authored andcommitted
xfrm: Generate blackhole routes only from route lookup functions
[ Upstream commit f92ee61 ] Currently we genarate a blackhole route route whenever we have matching policies but can not resolve the states. Here we assume that dst_output() is called to kill the balckholed packets. Unfortunately this assumption is not true in all cases, so it is possible that these packets leave the system unwanted. We fix this by generating blackhole routes only from the route lookup functions, here we can guarantee a call to dst_output() afterwards. Fixes: 2774c13 ("xfrm: Handle blackhole route creation via afinfo.") Reported-by: Konstantinos Kolelis <k.kolelis@sirrix.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent d8cff32 commit e5a51bb

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎include/net/dst.h‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,16 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,
478478
int flags)
479479
{
480480
return dst_orig;
481-
}
481+
}
482+
483+
static inline struct dst_entry *xfrm_lookup_route(struct net *net,
484+
struct dst_entry *dst_orig,
485+
const struct flowi *fl,
486+
struct sock *sk,
487+
int flags)
488+
{
489+
return dst_orig;
490+
}
482491

483492
static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
484493
{
@@ -490,6 +499,10 @@ extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig
490499
const struct flowi *fl, struct sock *sk,
491500
int flags);
492501

502+
struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
503+
const struct flowi *fl, struct sock *sk,
504+
int flags);
505+
493506
/* skb attached with this dst needs transformation if dst->xfrm is valid */
494507
static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
495508
{

‎net/ipv4/route.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,9 +2270,9 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
22702270
return rt;
22712271

22722272
if (flp4->flowi4_proto)
2273-
rt = (struct rtable *) xfrm_lookup(net, &rt->dst,
2274-
flowi4_to_flowi(flp4),
2275-
sk, 0);
2273+
rt = (struct rtable *)xfrm_lookup_route(net, &rt->dst,
2274+
flowi4_to_flowi(flp4),
2275+
sk, 0);
22762276

22772277
return rt;
22782278
}

‎net/ipv6/ip6_output.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
994994
if (can_sleep)
995995
fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
996996

997-
return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
997+
return xfrm_lookup_route(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
998998
}
999999
EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
10001000

@@ -1030,7 +1030,7 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
10301030
if (can_sleep)
10311031
fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
10321032

1033-
return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
1033+
return xfrm_lookup_route(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
10341034
}
10351035
EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
10361036

‎net/xfrm/xfrm_policy.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
21432143
xfrm_pols_put(pols, drop_pols);
21442144
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
21452145

2146-
return make_blackhole(net, family, dst_orig);
2146+
return ERR_PTR(-EREMOTE);
21472147
}
21482148
if (fl->flowi_flags & FLOWI_FLAG_CAN_SLEEP) {
21492149
DECLARE_WAITQUEUE(wait, current);
@@ -2215,6 +2215,22 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
22152215
}
22162216
EXPORT_SYMBOL(xfrm_lookup);
22172217

2218+
/* Callers of xfrm_lookup_route() must ensure a call to dst_output().
2219+
* Otherwise we may send out blackholed packets.
2220+
*/
2221+
struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
2222+
const struct flowi *fl,
2223+
struct sock *sk, int flags)
2224+
{
2225+
struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk, flags);
2226+
2227+
if (IS_ERR(dst) && PTR_ERR(dst) == -EREMOTE)
2228+
return make_blackhole(net, dst_orig->ops->family, dst_orig);
2229+
2230+
return dst;
2231+
}
2232+
EXPORT_SYMBOL(xfrm_lookup_route);
2233+
22182234
static inline int
22192235
xfrm_secpath_reject(int idx, struct sk_buff *skb, const struct flowi *fl)
22202236
{

0 commit comments

Comments
 (0)