Skip to content

Commit

Permalink
xfrm: policy: increment xfrm_hash_generation on hash rebuild
Browse files Browse the repository at this point in the history
Hash rebuild will re-set all the inexact entries, then re-insert them.
Lookups that can occur in parallel will therefore not find any policies.

This was safe when lookups were still guarded by rwlock.
After rcu-ification, lookups check the hash_generation seqcount to detect
when a hash resize takes place.  Hash rebuild missed the needed increment.

Hash resizes and hash rebuilds cannot occur in parallel (both acquire
hash_resize_mutex), so just increment xfrm_hash_generation, like resize.

Fixes: a7c4424 ("xfrm: policy: make xfrm_policy_lookup_bytype lockless")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Florian Westphal authored and Steffen Klassert committed Jan 9, 2019
1 parent 355b00d commit 7a474c3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ static void xfrm_hash_rebuild(struct work_struct *work)
} while (read_seqretry(&net->xfrm.policy_hthresh.lock, seq));

spin_lock_bh(&net->xfrm.xfrm_policy_lock);
write_seqcount_begin(&xfrm_policy_hash_generation);

/* make sure that we can insert the indirect policies again before
* we start with destructive action.
Expand Down Expand Up @@ -1334,6 +1335,7 @@ static void xfrm_hash_rebuild(struct work_struct *work)

out_unlock:
__xfrm_policy_inexact_flush(net);
write_seqcount_end(&xfrm_policy_hash_generation);
spin_unlock_bh(&net->xfrm.xfrm_policy_lock);

mutex_unlock(&hash_resize_mutex);
Expand Down

0 comments on commit 7a474c3

Please sign in to comment.