Skip to content

Commit

Permalink
[IPSEC]: Fix potential dst leak in xfrm_lookup
Browse files Browse the repository at this point in the history
If we get an error during the actual policy lookup we don't free the
original dst while the caller expects us to always free the original
dst in case of error.

This patch fixes that.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Herbert Xu authored and David S. Miller committed Dec 11, 2007
1 parent 3f03e38 commit 75b8c13
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,9 @@ int __xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,

if (sk && sk->sk_policy[XFRM_POLICY_OUT]) {
policy = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl);
err = PTR_ERR(policy);
if (IS_ERR(policy))
return PTR_ERR(policy);
goto dropdst;
}

if (!policy) {
Expand All @@ -1330,8 +1331,9 @@ int __xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,

policy = flow_cache_lookup(fl, dst_orig->ops->family,
dir, xfrm_policy_lookup);
err = PTR_ERR(policy);
if (IS_ERR(policy))
return PTR_ERR(policy);
goto dropdst;
}

if (!policy)
Expand Down Expand Up @@ -1501,8 +1503,9 @@ int __xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl,
return 0;

error:
dst_release(dst_orig);
xfrm_pols_put(pols, npols);
dropdst:
dst_release(dst_orig);
*dst_p = NULL;
return err;
}
Expand Down

0 comments on commit 75b8c13

Please sign in to comment.