Commit 7fbbb01d authored by Herbert Xu's avatar Herbert Xu Committed by Chris Wright

[PATCH] IPSEC: Policy list disorder

The recent hashing introduced an off-by-one bug in policy list insertion.
Instead of adding after the last entry with a lesser or equal priority,
we're adding after the successor of that entry.

This patch fixes this and also adds a warning if we detect a duplicate
entry in the policy list.  This should never happen due to this if clause.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarChris Wright <chrisw@sous-sol.org>
parent 5624ef14
...@@ -615,19 +615,18 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) ...@@ -615,19 +615,18 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
struct xfrm_policy *pol; struct xfrm_policy *pol;
struct xfrm_policy *delpol; struct xfrm_policy *delpol;
struct hlist_head *chain; struct hlist_head *chain;
struct hlist_node *entry, *newpos, *last; struct hlist_node *entry, *newpos;
struct dst_entry *gc_list; struct dst_entry *gc_list;
write_lock_bh(&xfrm_policy_lock); write_lock_bh(&xfrm_policy_lock);
chain = policy_hash_bysel(&policy->selector, policy->family, dir); chain = policy_hash_bysel(&policy->selector, policy->family, dir);
delpol = NULL; delpol = NULL;
newpos = NULL; newpos = NULL;
last = NULL;
hlist_for_each_entry(pol, entry, chain, bydst) { hlist_for_each_entry(pol, entry, chain, bydst) {
if (!delpol && if (pol->type == policy->type &&
pol->type == policy->type &&
!selector_cmp(&pol->selector, &policy->selector) && !selector_cmp(&pol->selector, &policy->selector) &&
xfrm_sec_ctx_match(pol->security, policy->security)) { xfrm_sec_ctx_match(pol->security, policy->security) &&
!WARN_ON(delpol)) {
if (excl) { if (excl) {
write_unlock_bh(&xfrm_policy_lock); write_unlock_bh(&xfrm_policy_lock);
return -EEXIST; return -EEXIST;
...@@ -636,17 +635,12 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) ...@@ -636,17 +635,12 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
if (policy->priority > pol->priority) if (policy->priority > pol->priority)
continue; continue;
} else if (policy->priority >= pol->priority) { } else if (policy->priority >= pol->priority) {
last = &pol->bydst; newpos = &pol->bydst;
continue; continue;
} }
if (!newpos)
newpos = &pol->bydst;
if (delpol) if (delpol)
break; break;
last = &pol->bydst;
} }
if (!newpos)
newpos = last;
if (newpos) if (newpos)
hlist_add_after(newpos, &policy->bydst); hlist_add_after(newpos, &policy->bydst);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment