History

xfrm: do not assume that template resolving always returns xfrms

xfrm_resolve_and_create_bundle() assumed that, if policies indicated presence of xfrms, bundle template resolution would always return some xfrms. This is not true for 'use' level policies which can result in no xfrm's being applied if there is no suitable xfrm states. This fixes a crash by this incorrect assumption.

Timo Teräs committed 16 years ago

Commit d809ec81 parent ab83a381 file · +13 −2Browse files

Unified · Split

net/xfrm/xfrm_policy.c+13−2
@@ -1594,8 +1594,8 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols, · 1593 unmodified lines
15941594
15951595 /* Try to instantiate a bundle */
15961596 err = xfrm_tmpl_resolve(pols, num_pols, fl, xfrm, family);
1597− if (err < 0) {
1598− if (err != -EAGAIN)
1597+ if (err <= 0) {
1598+ if (err != 0 && err != -EAGAIN)
15991599 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR);
16001600 return ERR_PTR(err);
16011601 }
@@ -1678,6 +1678,13 @@ xfrm_bundle_lookup(struct net *net, struct flowi *fl, u16 family, u8 dir, · 76 unmodified lines
16781678 goto make_dummy_bundle;
16791679 dst_hold(&xdst->u.dst);
16801680 return oldflo;
1681+ } else if (new_xdst == NULL) {
1682+ num_xfrms = 0;
1683+ if (oldflo == NULL)
1684+ goto make_dummy_bundle;
1685+ xdst->num_xfrms = 0;
1686+ dst_hold(&xdst->u.dst);
1687+ return oldflo;
16811688 }
16821689
16831690 /* Kill the previous bundle */
@@ -1760,6 +1767,10 @@ restart: · 76 unmodified lines
17601767 xfrm_pols_put(pols, num_pols);
17611768 err = PTR_ERR(xdst);
17621769 goto dropdst;
1770+ } else if (xdst == NULL) {
1771+ num_xfrms = 0;
1772+ drop_pols = num_pols;
1773+ goto no_transform;
17631774 }
17641775
17651776 spin_lock_bh(&xfrm_policy_sk_bundle_lock);