From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Safonov Subject: [PATCH] net/xfrm: Fix lookups for states with spi == 0 Date: Wed, 2 May 2018 03:02:20 +0100 Message-ID: <20180502020220.2027-1-dima@arista.com> Cc: 0x7f454c46@gmail.com, Dmitry Safonov , Steffen Klassert , Herbert Xu , "David S. Miller" , netdev@vger.kernel.org To: linux-kernel@vger.kernel.org Return-path: Received: from mail-wm0-f66.google.com ([74.125.82.66]:34819 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750743AbeEBCCX (ORCPT ); Tue, 1 May 2018 22:02:23 -0400 Received: by mail-wm0-f66.google.com with SMTP id o78so21576302wmg.0 for ; Tue, 01 May 2018 19:02:22 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: It seems to be a valid use case to add xfrm state without Security Parameter Indexes (SPI) value associated: ip xfrm state add src $src dst $dst proto $proto mode $mode sel src $src dst $dst $algo The bad thing is that it's currently impossible to get/delete the state without SPI: __xfrm_state_insert() obviously doesn't add hash for zero SPI in xfrm.state_byspi, and xfrm_user_state_lookup() will fail as xfrm_state_lookup() does lookups by hash. It also isn't possible to workaround from userspace as xfrm_id_proto_match() will be always true for ah/esp/comp protos. So, don't try looking up by hash if SPI == 0. Cc: Steffen Klassert Cc: Herbert Xu Cc: "David S. Miller" Cc: netdev@vger.kernel.org Signed-off-by: Dmitry Safonov --- net/xfrm/xfrm_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 080035f056d9..6b38503255c8 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -681,7 +681,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net, int err; u32 mark = xfrm_mark_get(attrs, &m); - if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) { + if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY) && p->spi) { err = -ESRCH; x = xfrm_state_lookup(net, mark, &p->daddr, p->spi, p->proto, p->family); } else { -- 2.13.6