diff options
| author | Cosmin Ratiu <[email protected]> | 2025-04-11 07:49:58 +0000 |
|---|---|---|
| committer | Steffen Klassert <[email protected]> | 2025-04-16 09:02:49 +0000 |
| commit | d2fddbd3479928e52061e1c8dd302006b6283ce8 (patch) | |
| tree | e8e20a650ca7aeb55410b9e00ce8f034924ae3c8 /net/core/dev_api.c | |
| parent | bonding: Mark active offloaded xfrm_states (diff) | |
| download | kernel-d2fddbd3479928e52061e1c8dd302006b6283ce8.tar.gz kernel-d2fddbd3479928e52061e1c8dd302006b6283ce8.zip | |
bonding: Fix multiple long standing offload races
Refactor the bonding ipsec offload operations to fix a number of
long-standing control plane races between state migration and user
deletion and a few other issues.
xfrm state deletion can happen concurrently with
bond_change_active_slave() operation. This manifests itself as a
bond_ipsec_del_sa() call with x->lock held, followed by a
bond_ipsec_free_sa() a bit later from a wq. The alternate path of
these calls coming from xfrm_dev_state_flush() can't happen, as that
needs the RTNL lock and bond_change_active_slave() already holds it.
1. bond_ipsec_del_sa_all() might call xdo_dev_state_delete() a second
time on an xfrm state that was concurrently killed. This is bad.
2. bond_ipsec_add_sa_all() can add a state on the new device, but
pending bond_ipsec_free_sa() calls from the old device will then hit
the WARN_ON() and then, worse, call xdo_dev_state_free() on the new
device without a corresponding xdo_dev_state_delete().
3. Resolve a sleeping in atomic context introduced by the mentioned
"Fixes" commit.
bond_ipsec_del_sa_all() and bond_ipsec_add_sa_all() now acquire x->lock
and check for x->km.state to help with problems 1 and 2. And since
xso.real_dev is now a private pointer managed by the bonding driver in
xfrm state, make better use of it to fully fix problems 1 and 2. In
bond_ipsec_del_sa_all(), set xso.real_dev to NULL while holding both the
mutex and x->lock, which makes sure that neither bond_ipsec_del_sa() nor
bond_ipsec_free_sa() could run concurrently.
Fix problem 3 by moving the list cleanup (which requires the mutex) from
bond_ipsec_del_sa() (called from atomic context) to bond_ipsec_free_sa()
Finally, simplify bond_ipsec_del_sa() and bond_ipsec_free_sa() by using
xso->real_dev directly, since it's now protected by locks and can be
trusted to always reflect the offload device.
Fixes: 2aeeef906d5a ("bonding: change ipsec_lock from spin lock to mutex")
Signed-off-by: Cosmin Ratiu <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Reviewed-by: Nikolay Aleksandrov <[email protected]>
Reviewed-by: Hangbin Liu <[email protected]>
Tested-by: Hangbin Liu <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
Diffstat (limited to 'net/core/dev_api.c')
0 files changed, 0 insertions, 0 deletions
