Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1384480pxu; Fri, 27 Nov 2020 06:11:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMRhAoL8rNfr1eLDK4hqxRciUhEwyvUi4wbqr7XeA2HjC2BtcTNVmH8csQwhik6cKBr94R X-Received: by 2002:aa7:ca49:: with SMTP id j9mr3603420edt.34.1606486301610; Fri, 27 Nov 2020 06:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606486301; cv=none; d=google.com; s=arc-20160816; b=oR16afotmF1idZSoBfthrmLO8IyZKkxR/WqVnb7No90mlV8kzpyunGtAPOezfvy6x8 qsYUR8eCZFrpUCesz9QoAUVBGphfJ66DYsrn5+q4NxTbouSrIRhaG11SjH8Ytk9yIFVd W037PY/UY9tdXY6KgHer/A8OP5cuoIJN20P6P7TJIvhviURpkJHwXmEcbXoL+6Ysl7uX nTLiCZ3A3AWdpxBtMveODy3V0mZ1diQPAleR17irGXUZywj0eSSLOl8bMMEFs9wv6qtL ceIzpsSOhcSDapd0vZNHj2tkdbNU495E0f3J1+O/P0SpnzxkUu5dQ8QtnbyL8/FsjqAy nSaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date; bh=Js9wrUNsD2uzHYeNdp4s0ZbJTKyeIwQERniPsn7zG3o=; b=Jt0G1/MCNwcNfNA5TGf6rkMeC7YYtgggcDzE68HhrW6LHYhxuX/V3s45RZu4ANDbvK t/sTzoQi8mQahsVtxXXWa5wvtmknJfKHKJde6/k3osJuk2XvvgfsspZZ0cnrlG8x2tO4 02tCwUL7O12qv3FN7LX1qp4dZm0ACUonhzPxremOZ+6lyOGS6Y38yBus9plEsA43zK3s P+1R7POTuXiMqJvbpr+bxN3VJ4XEq0zulgc63O7cJFDIhxGP/+n11x2oeJTzXmHOvTMe VbvaeBKxI7rBsQiRTPWbSeHlNcbDXiowULMaGLQpyn3py9WdfxF3u02ibzttvZb66TMO 8/uA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si5129956edg.60.2020.11.27.06.11.04; Fri, 27 Nov 2020 06:11:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730452AbgK0OKz (ORCPT + 99 others); Fri, 27 Nov 2020 09:10:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730041AbgK0OKz (ORCPT ); Fri, 27 Nov 2020 09:10:55 -0500 Received: from orbyte.nwl.cc (orbyte.nwl.cc [IPv6:2001:41d0:e:133a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79BFEC0613D1; Fri, 27 Nov 2020 06:10:54 -0800 (PST) Received: from n0-1 by orbyte.nwl.cc with local (Exim 4.94) (envelope-from ) id 1kieSW-0003ZF-6o; Fri, 27 Nov 2020 15:10:48 +0100 Date: Fri, 27 Nov 2020 15:10:48 +0100 From: Phil Sutter To: Steffen Klassert Cc: linux-crypto@vger.kernel.org, netfilter-devel@vger.kernel.org Subject: Re: XFRM interface and NF_INET_LOCAL_OUT hook Message-ID: <20201127141048.GL4647@orbyte.nwl.cc> Mail-Followup-To: Phil Sutter , Steffen Klassert , linux-crypto@vger.kernel.org, netfilter-devel@vger.kernel.org References: <20201125112342.GA11766@orbyte.nwl.cc> <20201126094021.GK8805@gauss3.secunet.de> <20201126131200.GH4647@orbyte.nwl.cc> <20201127095511.GD9390@gauss3.secunet.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201127095511.GD9390@gauss3.secunet.de> Sender: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Nov 27, 2020 at 10:55:11AM +0100, Steffen Klassert wrote: > On Thu, Nov 26, 2020 at 02:12:00PM +0100, Phil Sutter wrote: > > > > > > > > Is this a bug or an expected quirk when using XFRM interface? > > > > > > This is expected behaviour. The xfrm interfaces are plaintext devices, > > > the plaintext packets are routed to the xfrm interface which guarantees > > > transformation. So the lookup that assigns skb_dst(skb)->xfrm > > > happens 'behind' the interface. After transformation, > > > skb_dst(skb)->xfrm will be cleared. So this assignment exists just > > > inside xfrm in that case. > > > > OK, thanks for the clarification. > > > > > Does netfilter match against skb_dst(skb)->xfrm? What is the exact case > > > that does not work? > > > > The reported use-case is a match against tunnel data in output hook: > > > > | table t { > > | chain c { > > | type filter hook output priority filter > > | oifname eth0 ipsec out ip daddr 192.168.1.2 > > | } > > | } > > > > The ipsec expression tries to extract that data from skb_dst(skb)->xfrm > > if present. In xt_policy (for iptables), code is equivalent. The above > > works when not using xfrm_interface. Initially I assumed one just needs > > to adjust the oifname match, but even dropping it doesn't help. > > Yes, this does not work with xfrm interfaces. As said, they are plaintext > devices that guarantee transformation. > > Maybe you can try to match after transformation by using the secpath, > but not sure if that is what you need. Secpath is used for input only, no? I played a bit more with xfrm_interface and noticed that when used, NF_INET_LOCAL_OUT hook sees the packet (an ICMP reply) only once instead of twice as without xfrm_interface. I don't think using it should change behaviour that much apart from packets without matching policy being dropped. What do you think about the following fix? I checked forwarding packets as well and it looks like behaviour is identical to plain policy: diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c index aa4cdcf69d471..24af61c95b4d4 100644 --- a/net/xfrm/xfrm_interface.c +++ b/net/xfrm/xfrm_interface.c @@ -317,7 +317,8 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) skb_dst_set(skb, dst); skb->dev = tdev; - err = dst_output(xi->net, skb->sk, skb); + err = NF_HOOK(skb_dst(skb)->ops->family, NF_INET_LOCAL_OUT, xi->net, + skb->sk, skb, NULL, skb_dst(skb)->dev, dst_output); if (net_xmit_eval(err) == 0) { struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats); Thanks, Phil