Skip to content

Commit

Permalink
Revert "xfrm: policy: Read seqcount outside of rcu-read side in xfrm_…
Browse files Browse the repository at this point in the history
…policy_lookup_bytype"

This reverts commit d7b0408.

This commit tried to fix a locking bug introduced by commit 77cc278
("xfrm: policy: Use sequence counters with associated lock"). As it
turned out, this patch did not really fix the bug. A proper fix
for this bug is applied on top of this revert.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Steffen Klassert committed Jul 2, 2021
1 parent 7c1a80e commit eaf2282
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
@@ -2092,15 +2092,12 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
if (unlikely(!daddr || !saddr))
return NULL;

retry:
sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
rcu_read_lock();

chain = policy_hash_direct(net, daddr, saddr, family, dir);
if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
rcu_read_unlock();
goto retry;
}
retry:
do {
sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
chain = policy_hash_direct(net, daddr, saddr, family, dir);
} while (read_seqcount_retry(&xfrm_policy_hash_generation, sequence));

ret = NULL;
hlist_for_each_entry_rcu(pol, chain, bydst) {
@@ -2131,15 +2128,11 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
}

skip_inexact:
if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
rcu_read_unlock();
if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence))
goto retry;
}

if (ret && !xfrm_pol_hold_rcu(ret)) {
rcu_read_unlock();
if (ret && !xfrm_pol_hold_rcu(ret))
goto retry;
}
fail:
rcu_read_unlock();

0 comments on commit eaf2282

Please sign in to comment.