From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [91.216.245.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160132C11D9 for ; Tue, 10 Mar 2026 19:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.216.245.30 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773172187; cv=none; b=qOEG4YfXorXyL4gpkH9mWF1JRepWkjr14AKp5bTPHcwELuHCF0B+o2S1pHOzeA3iCkHt1hZU0BM+MWRrW8RfwHpWjlNzoNO2JfAkh+1c8Si7k7LFC/aJr96huEQxQl68hf6+OWvKTM8UTHloJKMd2i4vGAgZ4V6+Jl0zYvgJJvQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773172187; c=relaxed/simple; bh=Cbk+TPCTTua5crdvvKusCVU5CfZ4/K0YX1H9qIVTQBs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FdgGJW0jEMnEadYx5wep2wKElWpjWlMkLXDMbqluiAFjtBztz0EMpsY3AOVDVhCdCILT4cEbkO7NVZRYbgF33wUS6BU7SVqs3PPwRB54K5s6kCuyBxhw8T3heBZD+PQekcnoCQaBRqR55VZWffz/87+PJFueIxq+BARjcAEol0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de; spf=pass smtp.mailfrom=strlen.de; arc=none smtp.client-ip=91.216.245.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=strlen.de Received: by Chamillionaire.breakpoint.cc (Postfix, from userid 1003) id 6CBC760345; Tue, 10 Mar 2026 20:49:44 +0100 (CET) Date: Tue, 10 Mar 2026 20:49:44 +0100 From: Florian Westphal To: Leon Romanovsky Cc: Sabrina Dubroca , netdev@vger.kernel.org, Steffen Klassert , Herbert Xu Subject: Re: [PATCH ipsec-next 01/10] xfrm: state: fix sparse warnings on xfrm_state_hold_rcu Message-ID: References: <7388df7238672a92be0e4048f0225e6db294e736.1773051558.git.sd@queasysnail.net> <20260310103135.GB12611@unreal> <20260310182012.GF12611@unreal> <20260310194500.GO12611@unreal> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260310194500.GO12611@unreal> Leon Romanovsky wrote: > > You can only use xfrm_state_hold() if the refcount is already > 0. > > xfrm_state_hold uses refcount_inc(), so you get a UaF warn splat > > if this assuption doesn't hold true. > > I know it, the thing that bothers me is that it is unclear how > xfrm_state_hold_rcu() can have refcount equal to 0. > > xfrm_state_put() decreases refcount and when it is zero, it calls > to __xfrm_state_destroy(). The latter assumes that the state was > already removed from various hlists. Yes, insertion in the table means refcount is 1, but userspace can zap states at any time, e.g.: xfrm_del_sa -> xfrm_state_delete -> __xfrm_state_delete (which unlinks from hash lists). The last xfrm_state_put() in that function may cause 1 -> 0 transition. Parallel lookup can still observe that state, so it has to pretend it wasn't there to begin with.