Skip to content

Commit 2a9e5d6

Browse files
klassertJiri Slaby
authored andcommitted
xfrm: Generate queueing routes only from route lookup functions
[ Upstream commit b8c203b ] Currently we genarate a queueing route if we have matching policies but can not resolve the states and the sysctl xfrm_larval_drop is disabled. Here we assume that dst_output() is called to kill the queued 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 queueing routes only from the route lookup functions, here we can guarantee a call to dst_output() afterwards. Fixes: a0073fe ("xfrm: Add a state resolution packet queue") 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 e5a51bb commit 2a9e5d6

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

‎include/net/dst.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ extern void dst_init(void);
468468
/* Flags for xfrm_lookup flags argument. */
469469
enum {
470470
XFRM_LOOKUP_ICMP = 1 << 0,
471+
XFRM_LOOKUP_QUEUE = 1 << 1,
471472
};
472473

473474
struct flowi;

‎net/xfrm/xfrm_policy.c‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock);
4646
static struct dst_entry *xfrm_policy_sk_bundles;
4747
static DEFINE_RWLOCK(xfrm_policy_lock);
4848

49+
struct xfrm_flo {
50+
struct dst_entry *dst_orig;
51+
u8 flags;
52+
};
53+
4954
static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock);
5055
static struct xfrm_policy_afinfo __rcu *xfrm_policy_afinfo[NPROTO]
5156
__read_mostly;
@@ -1875,24 +1880,28 @@ static int xdst_queue_output(struct sk_buff *skb)
18751880
}
18761881

18771882
static struct xfrm_dst *xfrm_create_dummy_bundle(struct net *net,
1878-
struct dst_entry *dst,
1883+
struct xfrm_flo *xflo,
18791884
const struct flowi *fl,
18801885
int num_xfrms,
18811886
u16 family)
18821887
{
18831888
int err;
18841889
struct net_device *dev;
1890+
struct dst_entry *dst;
18851891
struct dst_entry *dst1;
18861892
struct xfrm_dst *xdst;
18871893

18881894
xdst = xfrm_alloc_dst(net, family);
18891895
if (IS_ERR(xdst))
18901896
return xdst;
18911897

1892-
if (net->xfrm.sysctl_larval_drop || num_xfrms <= 0 ||
1898+
if (!(xflo->flags & XFRM_LOOKUP_QUEUE) ||
1899+
net->xfrm.sysctl_larval_drop ||
1900+
num_xfrms <= 0 ||
18931901
(fl->flowi_flags & FLOWI_FLAG_CAN_SLEEP))
18941902
return xdst;
18951903

1904+
dst = xflo->dst_orig;
18961905
dst1 = &xdst->u.dst;
18971906
dst_hold(dst);
18981907
xdst->route = dst;
@@ -1934,7 +1943,7 @@ static struct flow_cache_object *
19341943
xfrm_bundle_lookup(struct net *net, const struct flowi *fl, u16 family, u8 dir,
19351944
struct flow_cache_object *oldflo, void *ctx)
19361945
{
1937-
struct dst_entry *dst_orig = (struct dst_entry *)ctx;
1946+
struct xfrm_flo *xflo = (struct xfrm_flo *)ctx;
19381947
struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
19391948
struct xfrm_dst *xdst, *new_xdst;
19401949
int num_pols = 0, num_xfrms = 0, i, err, pol_dead;
@@ -1975,7 +1984,8 @@ xfrm_bundle_lookup(struct net *net, const struct flowi *fl, u16 family, u8 dir,
19751984
goto make_dummy_bundle;
19761985
}
19771986

1978-
new_xdst = xfrm_resolve_and_create_bundle(pols, num_pols, fl, family, dst_orig);
1987+
new_xdst = xfrm_resolve_and_create_bundle(pols, num_pols, fl, family,
1988+
xflo->dst_orig);
19791989
if (IS_ERR(new_xdst)) {
19801990
err = PTR_ERR(new_xdst);
19811991
if (err != -EAGAIN)
@@ -2009,7 +2019,7 @@ xfrm_bundle_lookup(struct net *net, const struct flowi *fl, u16 family, u8 dir,
20092019
/* We found policies, but there's no bundles to instantiate:
20102020
* either because the policy blocks, has no transformations or
20112021
* we could not build template (no xfrm_states).*/
2012-
xdst = xfrm_create_dummy_bundle(net, dst_orig, fl, num_xfrms, family);
2022+
xdst = xfrm_create_dummy_bundle(net, xflo, fl, num_xfrms, family);
20132023
if (IS_ERR(xdst)) {
20142024
xfrm_pols_put(pols, num_pols);
20152025
return ERR_CAST(xdst);
@@ -2109,13 +2119,18 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
21092119
}
21102120

21112121
if (xdst == NULL) {
2122+
struct xfrm_flo xflo;
2123+
2124+
xflo.dst_orig = dst_orig;
2125+
xflo.flags = flags;
2126+
21122127
/* To accelerate a bit... */
21132128
if ((dst_orig->flags & DST_NOXFRM) ||
21142129
!net->xfrm.policy_count[XFRM_POLICY_OUT])
21152130
goto nopol;
21162131

21172132
flo = flow_cache_lookup(net, fl, family, dir,
2118-
xfrm_bundle_lookup, dst_orig);
2133+
xfrm_bundle_lookup, &xflo);
21192134
if (flo == NULL)
21202135
goto nopol;
21212136
if (IS_ERR(flo)) {
@@ -2222,7 +2237,8 @@ struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
22222237
const struct flowi *fl,
22232238
struct sock *sk, int flags)
22242239
{
2225-
struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk, flags);
2240+
struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk,
2241+
flags | XFRM_LOOKUP_QUEUE);
22262242

22272243
if (IS_ERR(dst) && PTR_ERR(dst) == -EREMOTE)
22282244
return make_blackhole(net, dst_orig->ops->family, dst_orig);
@@ -2496,7 +2512,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
24962512

24972513
skb_dst_force(skb);
24982514

2499-
dst = xfrm_lookup(net, skb_dst(skb), &fl, NULL, 0);
2515+
dst = xfrm_lookup(net, skb_dst(skb), &fl, NULL, XFRM_LOOKUP_QUEUE);
25002516
if (IS_ERR(dst)) {
25012517
res = 0;
25022518
dst = NULL;

0 commit comments

Comments
 (0)