diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 78fcbb89cf3..3de1ac70019 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -929,10 +929,10 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid) err = -ESRCH; for (i = 0; i <= net->xfrm.state_hmask; i++) { struct xfrm_state *x; -restart: hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) { if (!xfrm_state_kern(x) && - xfrm_id_proto_match(x->id.proto, proto)) { + xfrm_id_proto_match(x->id.proto, proto) && + x->km.state != XFRM_STATE_DEAD) { xfrm_state_hold(x); spin_unlock_bh(&net->xfrm.xfrm_state_lock); @@ -940,11 +940,9 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid) xfrm_audit_state_delete(x, err ? 0 : 1, task_valid); xfrm_state_put(x); - if (!err) - cnt++; + cnt++; spin_lock_bh(&net->xfrm.xfrm_state_lock); - goto restart; } } } @@ -1557,6 +1555,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, #endif if (km_query(x, tmpl, pol) == 0) { spin_lock_bh(&net->xfrm.xfrm_state_lock); + BUG_ON(x->km.state == XFRM_STATE_DEAD); x->km.state = XFRM_STATE_ACQ; x->dir = XFRM_SA_DIR_OUT; list_add(&x->km.all, &net->xfrm.state_all); @@ -1722,6 +1721,7 @@ static void __xfrm_state_insert(struct xfrm_state *x) struct net *net = xs_net(x); unsigned int h; + BUG_ON(x->km.state == XFRM_STATE_DEAD); list_add(&x->km.all, &net->xfrm.state_all); /* Sanitize mark before store */