From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from a.mx.secunet.com (a.mx.secunet.com [62.96.220.36]) (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 33DC041C72 for ; Sun, 21 Apr 2024 22:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.96.220.36 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713737609; cv=none; b=qW0kcelBzNLjvk5ft3Ys+nvxsrhUkZJFgbHTavdpxEIDGksHpZv8pDPq163Wmba9daqtYHgXugoLbHfW++mIs9UWVw37LcTXfp2HMAj+8Rz3ukV46q2C5r2ibHREgQ3GmMSW7Oo+AgR2/nxhb0/+JRnTGWs6oKKweiPWYnXznDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713737609; c=relaxed/simple; bh=guOH+788HGffbWRcGxG7qQiHhl8BbTmYuc5RXT8nnKc=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H8D8wGVvw9N2q004my4X83BCrm57WOUnaFQzjjqQE5qAPfjRIBsIncsPem067OR4jQyAcujqeWuQPvSbg6fGtEv2Jh+o4KR2lCIOSxPtb20zB2agexd824tpWcQcuxJjg9JvtgtVWWobc3vGSsr3iBqTRDrCmTIdH1JGjbEG0bA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.b=Gm0OwYYT; arc=none smtp.client-ip=62.96.220.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.b="Gm0OwYYT" Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 5D2BC205CF; Mon, 22 Apr 2024 00:13:18 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NL5YYbxphcKe; Mon, 22 Apr 2024 00:13:17 +0200 (CEST) Received: from mailout1.secunet.com (mailout1.secunet.com [62.96.220.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id BE11F201AA; Mon, 22 Apr 2024 00:13:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 a.mx.secunet.com BE11F201AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1713737597; bh=cAQ+eo99JBABv119eDVt9AUpGeLXrovzi5xylxwTGK0=; h=Date:From:To:CC:Subject:Reply-To:References:In-Reply-To:From; b=Gm0OwYYT7CBe1boR6lqY0/WbmgD9Ht2qDAkpAC7GYm6XIE9em7hh8vmdvm/wCrbLn ghHVbvHKiYk5OjzJRH0hZVPERsWjl9HMu8nnFh+rE05AOEt6mnoXAE0kc6m8YduVf3 m1KwVnuxeRxlvAmuX5ypOKpnDq3+dWgRnw5F1upvnVgiyjT29srZ3TRWwC6nc5KBc+ 7idOoGtlFxvg79BOdWKKnoEqM2tV88AChpnIYptvnqI6FngpZ87jku4KYh3GmYnNKC WmPaLXzA/sLpuxL4DDihr501RMwxRw4nGJnFtODDRlwJDmeJEMXl9Te8ZIpdaCx+1H hsGuJpIcasoLg== Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout1.secunet.com (Postfix) with ESMTP id A74C880004A; Mon, 22 Apr 2024 00:13:17 +0200 (CEST) Received: from mbx-essen-01.secunet.de (10.53.40.197) by cas-essen-01.secunet.de (10.53.40.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 22 Apr 2024 00:13:17 +0200 Received: from moon.secunet.de (172.18.149.1) by mbx-essen-01.secunet.de (10.53.40.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Mon, 22 Apr 2024 00:13:16 +0200 Date: Mon, 22 Apr 2024 00:13:04 +0200 From: Antony Antony To: Simon Horman CC: Antony Antony , Steffen Klassert , Herbert Xu , , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , , Leon Romanovsky , Eyal Birger , Nicolas Dichtel , Sabrina Dubroca Subject: Re: [PATCH ipsec-next v10 2/3] xfrm: Add dir validation to "out" data path lookup Message-ID: Reply-To: References: <0e0d997e634261fcdf16cf9f07c97d97af7370b6.1712828282.git.antony.antony@secunet.com> <274c82dfea0d656f59f69ccaab46d4319f0ef54c.1712828282.git.antony.antony@secunet.com> <20240418092421.GA3974194@kernel.org> 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: <20240418092421.GA3974194@kernel.org> Precedence: first-class Priority: normal Organization: secunet X-ClientProxiedBy: cas-essen-01.secunet.de (10.53.40.201) To mbx-essen-01.secunet.de (10.53.40.197) Hi Simon, On Thu, Apr 18, 2024 at 10:24:21 +0100, Simon Horman wrote: > On Thu, Apr 11, 2024 at 11:42:13AM +0200, Antony Antony wrote: > > Introduces validation for the x->dir attribute within the XFRM output > > data lookup path. If the configured direction does not match the expected > > direction, out, increment the XfrmOutDirError counter and drop the packet > > to ensure data integrity and correct flow handling. > > > > grep -vw 0 /proc/net/xfrm_stat > > XfrmOutPolError 2 > > XfrmOutDirError 2 > > > > Signed-off-by: Antony Antony > > ... > > > diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c > > index 6affe5cd85d8..7deeb21dae15 100644 > > --- a/net/xfrm/xfrm_policy.c > > +++ b/net/xfrm/xfrm_policy.c > > @@ -2489,6 +2489,12 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl, > > > > x = xfrm_state_find(remote, local, fl, tmpl, policy, &error, > > family, policy->if_id); > > + if (x->dir && x->dir != XFRM_SA_DIR_OUT) { > > + XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTDIRERROR); > > + xfrm_state_put(x); > > + error = -EINVAL; > > + goto fail; > > + } > > Hi Antony, > > the line below assumes that x may be NULL, > but the new code above dereferences x unconditionally. > Is this ok? probably not. I added a fix in v11. > > Flagged by Smatch. thanks. > > > > > if (x && x->km.state == XFRM_STATE_VALID) { > > xfrm[nx++] = x; > > ...