Re: [PATCHv4 net 1/3] bonding: move IPsec deletion to bond_ipsec_free_sa
From: Cosmin Ratiu
Date: Thu Mar 06 2025 - 08:37:40 EST
On Thu, 2025-03-06 at 10:02 +0000, Hangbin Liu wrote:
> > For bond_ipsec_add_sa_all(), I will move the xso.real_dev =
> > real_dev
> > after .xdo_dev_state_add() in case the following situation.
xso.real_dev needs to be initialized before the call to
xdo_dev_state_add, since many of the implementations look in
xso.real_dev to determine on which device to operate on.
So the ordering should be:
- get the lock
- set xso.real_dev to real_dev
- release the lock
- call xdo_dev_state_add
- if it fails, reacquire the lock and set the device to NULL.
Unfortunately, this doesn't seem to protect against the scenario below,
as after dropping the spinlock from bond_ipsec_add_sa_all,
bond_ipsec_del_sa can freely call xdo_dev_state_delete() on real_dev
before xdo_dev_state_add happens.
I don't know what to do in this case...
> >
> > bond_ipsec_add_sa_all()
> > spin_unlock(&ipsec->x->lock);
> > ipsec->xs->xso.real_dev = real_dev;
> > __xfrm_state_delete x->state = DEAD
> > - bond_ipsec_del_sa()
> > - .xdo_dev_state_delete()
> > .xdo_dev_state_add()
Cosmin.