Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5136853iog; Wed, 22 Jun 2022 12:47:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1umXenT+1XzRAXzGRegyEyJ2/RtEFQ7cYCF++dbNWRPJfcjf9OAuLTZhjihUgO2M2gjBB/8 X-Received: by 2002:a63:3c08:0:b0:40c:f5b4:9674 with SMTP id j8-20020a633c08000000b0040cf5b49674mr4486209pga.152.1655927270344; Wed, 22 Jun 2022 12:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655927270; cv=none; d=google.com; s=arc-20160816; b=WkFusu28hUsI+61Ws5uCEY1g2DMh4zexw3OMODQ6As03VHX60ru9N/Q2bnS9AfhPue JSt2ZPPD5YfIUw8tmHtNS8YI0ZWVJY8SCEWHpNP6LLxG/AhholI91vD0r/fbscwu8O1l PZzpvVdlcAik0ghTmogwZUyFuMqlfornVJSVREphiPxJg61I3601q5RFsd3jxxkDf7+A ZNCNqtNEdbky7PpqhLxhcPPR+y4rfXR7PMfYPa30+6EIglLhaPqRP6Njp8T25BtvwNgD Kn5/6Jqshu9aY3hmp6EhuQxKywy7zZGcOCMQBUrfigKf8TC6cS0Rt6q0+FiXjO24OKYs peIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tGYC0JfVcEOklfcd5CHjY9rwrFmfl6TemJvfZU8qJxE=; b=PdpIgyGoC3mosrwMfXHnHF/IkoCpWUBjhYIkuKDVHgaSFzdViDqv7AGXfN0avTRZUD hF6wHfy6PqmkzsjFQzBBmP3ybyn4+tjN4eAFzc/fIshS1XdaSZ5/mgey2QWq9I6sDqQs DY8kd/LxUniDQ0rxxm/IAKd3c6oW0NeBYvXzMTJByss05ZlRi7D6GD7VJoaBcvgduC5d O4qSvk9R672ghrQwLv6tXjyawtZRZgMcgOT0v3wM/plOUquAfjJVc9GcSELcIw1kA8Fx S4hcT/c6BSPiUtyEJ8iRrp6BLcKiche7/qUDLtxnUIWGM38rjBF70t+1FEB1QS7iyDJu N4ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JT+oe4uv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a170902f78e00b00168ebc82df8si24171355pln.61.2022.06.22.12.47.37; Wed, 22 Jun 2022 12:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JT+oe4uv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355987AbiFVTEY (ORCPT + 99 others); Wed, 22 Jun 2022 15:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351124AbiFVTEW (ORCPT ); Wed, 22 Jun 2022 15:04:22 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB42835AAB for ; Wed, 22 Jun 2022 12:04:21 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id i7so14120997ybe.11 for ; Wed, 22 Jun 2022 12:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tGYC0JfVcEOklfcd5CHjY9rwrFmfl6TemJvfZU8qJxE=; b=JT+oe4uvxIqOfCEFWYz+8dmrf0ZlHKNGnw5N0DgM0ILmXnX87BVQPrcf5VGc71Q2zt Jn/KtlOsZPN/34WTySuutgwZgN78oklxy6ySoNm9XEimT50SmD3j5xqqxBouCCsEi1Sb WpSMFjdj/PPyHWvBPfMk4Gwt2J6EEdPUJVsm+Aw2z4pH4YFPacKVMvMtiU0sXS6Pmtkw 3HNRiWuyrPqWdW0CeYVzQI3YGiZX+Hq9yRntregBkx+e/OonyNF0kee0rwAKob4mT5Pm ENxQFVVnnj3X0Om0jWeb53E381Uq8d/CtmbLtPyp5bIBwJnpBdtqEqnzmv6lPHXEwdvB bzTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tGYC0JfVcEOklfcd5CHjY9rwrFmfl6TemJvfZU8qJxE=; b=5zt09xhPCm+65dIXUKejqHtYCaIq9lQ+YxzikD1u++EcHmzGmctjwQkTaON/f+8ThX Qh+l7XXMcu0RqMwUxdQzb4oWiMXfSOiFLkNEQu3nmByMSddWi6ta12+RwNvhlERsrk5L ucY6NuTRk9BI6OfX5WPFMHLjcSnrJrl65AqvQgmuuTaGxvzptHlznPve3z2CqLzP1xtg 0RVW7vfpHL5puk6dhNiF6O35Jxfky99gify3qL3EI3bYXBKRfgXJmzB6ePU7lF5PmT2l S38tRspWFtPZymmPjyqNLm+09kV68i4qtCqlMJ9e7aP1EghPWb/fxv+Sx3mtWAyJ/y2Z jQAQ== X-Gm-Message-State: AJIora9zLRI2ZoETaXvyfqdmTSR0Zh8DBovUKMlh+nNxJaXp/QsyrUmE G2bDEnB5zRIi2cJPASC37IKwnkbIcezlHoTvsU7tJg== X-Received: by 2002:a25:e211:0:b0:669:9cf9:bac7 with SMTP id h17-20020a25e211000000b006699cf9bac7mr2831225ybe.407.1655924660420; Wed, 22 Jun 2022 12:04:20 -0700 (PDT) MIME-Version: 1.0 References: <20220619003919.394622-1-i.maximets@ovn.org> <20220622102813.GA24844@breakpoint.cc> <068ad894-c60f-c089-fd4a-5deda1c84cdd@ovn.org> <673a6f2b-dab2-e00f-b37c-15f8775b2121@ovn.org> In-Reply-To: <673a6f2b-dab2-e00f-b37c-15f8775b2121@ovn.org> From: Eric Dumazet Date: Wed, 22 Jun 2022 21:04:08 +0200 Message-ID: Subject: Re: [PATCH net] net: ensure all external references are released in deferred skbuffs To: Ilya Maximets Cc: Steffen Klassert , Herbert Xu , Florian Westphal , netdev , "David S. Miller" , dev@openvswitch.org, LKML , Jakub Kicinski , Paolo Abeni Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 22, 2022 at 8:19 PM Ilya Maximets wrote: > > On 6/22/22 19:03, Eric Dumazet wrote: > > On Wed, Jun 22, 2022 at 6:47 PM Eric Dumazet wrote: > >> > >> On Wed, Jun 22, 2022 at 6:39 PM Eric Dumazet wrote: > >>> > >>> On Wed, Jun 22, 2022 at 6:29 PM Eric Dumazet wrote: > >>>> > >>>> On Wed, Jun 22, 2022 at 4:26 PM Ilya Maximets wrote: > >>>>> > >>>>> On 6/22/22 13:43, Eric Dumazet wrote: > >>>> > >>>>> > >>>>> I tested the patch below and it seems to fix the issue seen > >>>>> with OVS testsuite. Though it's not obvious for me why this > >>>>> happens. Can you explain a bit more? > >>>> > >>>> Anyway, I am not sure we can call nf_reset_ct(skb) that early. > >>>> > >>>> git log seems to say that xfrm check needs to be done before > >>>> nf_reset_ct(skb), I have no idea why. > >>> > >>> Additional remark: In IPv6 side, xfrm6_policy_check() _is_ called > >>> after nf_reset_ct(skb) > >>> > >>> Steffen, do you have some comments ? > >>> > >>> Some context: > >>> commit b59c270104f03960069596722fea70340579244d > >>> Author: Patrick McHardy > >>> Date: Fri Jan 6 23:06:10 2006 -0800 > >>> > >>> [NETFILTER]: Keep conntrack reference until IPsec policy checks are done > >>> > >>> Keep the conntrack reference until policy checks have been performed for > >>> IPsec NAT support. The reference needs to be dropped before a packet is > >>> queued to avoid having the conntrack module unloadable. > >>> > >>> Signed-off-by: Patrick McHardy > >>> Signed-off-by: David S. Miller > >>> > >> > >> Oh well... __xfrm_policy_check() has : > >> > >> nf_nat_decode_session(skb, &fl, family); > >> > >> This answers my questions. > >> > >> This means we are probably missing at least one XFRM check in TCP > >> stack in some cases. > >> (Only after adding this XFRM check we can call nf_reset_ct(skb)) > >> > > > > Maybe this will help ? > > I tested this patch and it seems to fix the OVS problem. > I did not test the xfrm part of it. > > Will you post an official patch? Yes I will. I need to double check we do not leak either the req, or the child. Maybe the XFRM check should be done even earlier, on the listening socket ? Or if we assume the SYNACK packet has been sent after the XFRM test has been applied to the SYN, maybe we could just call nf_reset_ct(skb) to lower risk of regressions. With the last patch, it would be strange that we accept the 3WHS and establish a socket, but drop the payload in the 3rd packet... > > > > > diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c > > index fe8f23b95d32ca4a35d05166d471327bc608fa91..49c1348e40b6c7b6a98b54d716f29c948e00ba33 > > 100644 > > --- a/net/ipv4/tcp_ipv4.c > > +++ b/net/ipv4/tcp_ipv4.c > > @@ -2019,12 +2019,19 @@ int tcp_v4_rcv(struct sk_buff *skb) > > if (nsk == sk) { > > reqsk_put(req); > > tcp_v4_restore_cb(skb); > > - } else if (tcp_child_process(sk, nsk, skb)) { > > - tcp_v4_send_reset(nsk, skb); > > - goto discard_and_relse; > > } else { > > - sock_put(sk); > > - return 0; > > + if (!xfrm4_policy_check(nsk, XFRM_POLICY_IN, skb)) { > > + drop_reason = SKB_DROP_REASON_XFRM_POLICY; > > + goto discard_and_relse; > > + } > > + nf_reset_ct(skb); > > + if (tcp_child_process(sk, nsk, skb)) { > > + tcp_v4_send_reset(nsk, skb); > > + goto discard_and_relse; > > + } else { > > + sock_put(sk); > > + return 0; > > + } > > } > > } >