Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5136652iog; Wed, 22 Jun 2022 12:47:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urYb6VSBJaIs/mgA0CvDK++qCrjM76a0H8bFLicCvizbPjxGBk1B7S32neAVY1hFVNRLTS X-Received: by 2002:a17:902:8eca:b0:16a:285e:5878 with SMTP id x10-20020a1709028eca00b0016a285e5878mr16271729plo.59.1655927254100; Wed, 22 Jun 2022 12:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655927254; cv=none; d=google.com; s=arc-20160816; b=dKK4v+fqbqjneqzdJLhX0joOpJKdChyOK/ZclLxHFnVQH3+9wYsa6WuDv6bc/19MnP mpDoE+ntV0yfovnUJgX39w7QQlJXNb6p0hmxHySPvafY35KuAejxWXRjAYZNy9DA+Tp3 6zyYxezCazZ/J3OhaylHiO000bTAeNddxYn35Pll7eBvydrrEUXF1FDgCEBuFBTRwuJg fLLK2mCz50Bl9CFsZtNHx+8UR4bia67JcsjffZtuCMcuDukvr45/Ziol8UwJB79WrWkB cHjHdAuOeQptpbpg+mAI5CAFLc8w1Prv09fE18u9nGqYDj4xnWxO6HhZ5R8IRuWQyEQI k54A== 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=KkilKDpe8ThJRZsQJBgYTCpQiUJz1z4q2ZzFyMDTssQ=; b=js3kX2ip0Xgk4WOHeWLADH17O9fY8PtCkYxFwHAd+xa6aQQulwMxRu8CBk/Nmzqke8 C0N9BYDo1Gi0hQ/saRQqF51HLb4Dd1hzqc4/s+DiQSMiF0K6E7683CzettHlGQKwPPyQ Avmb57TBb69gQcNxQeQxOR/kusgRvp5Up/zMx2hNBQzmyZCPUvLaaLD3DLItvgYR7M4O yCiU0VVECqJJiLeFcyom+cld0bdunavb/ePq5o32DVabDRKbTX1Q3d0NXuzRprzINh6F JekN9NnTQ4CTJtul/1ldje6tcdrULh10LEK2aa6RtPAPQZPfrU7hjjhR7onM1xuos587 EM2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LFEgrMii; 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 a19-20020a056a000c9300b00510538e14f6si25335805pfv.364.2022.06.22.12.47.21; Wed, 22 Jun 2022 12:47:34 -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=LFEgrMii; 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 S1359235AbiFVT3l (ORCPT + 99 others); Wed, 22 Jun 2022 15:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357869AbiFVT12 (ORCPT ); Wed, 22 Jun 2022 15:27:28 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A6E13FD8D for ; Wed, 22 Jun 2022 12:27:24 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-3178acf2a92so139001947b3.6 for ; Wed, 22 Jun 2022 12:27:24 -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=KkilKDpe8ThJRZsQJBgYTCpQiUJz1z4q2ZzFyMDTssQ=; b=LFEgrMiixhjmjqAGOoh7j5oEeos/k5NQzAbkIIxEUX2OwntckqcTQESNwnXKhhmvky 45qUvKGOqU2sBjK1P4QNn4FBMGdBWVlZZc17iLU4Jsn1ghN3L9j/nsmjcL+tCzmfRkJx gLHJLX0SmjzwcfP53dU4pvXiYqWMSEv/2c526aTelmrd3UFjIfMHuSLDbgSEsouZJZqe qlkAQiB3k/jrr2XFu0JmtRp41lOT0aYnIhf4yEAtzNOFmr2TUMPzGSZyhdQ+edv5ja/3 Gj0b5hYMpRecL75lYmD8aYBqz+ILvQEa0WJnou428EjrJDXBJ+LEgBhA1Qk1J6M84FbO DiAA== 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=KkilKDpe8ThJRZsQJBgYTCpQiUJz1z4q2ZzFyMDTssQ=; b=c76bx4aAvZ7b6rS8dO9Faw6yzZYXEOXdTONduXnOiQ9jvx5xdWrb0AvH559KTh6GTW 5Wx2aL7rKfrGjiDIGWvmGdESZg8L0hrrswDwp5er7+/UAZFAUpQMTSnTJWxn79WW2y6D YSXgwHRXxwAoYtpuZRxS7HwRhPBZoRjKYejLVO3V2GqO2Lw212IhFR6bGDltLcuKGVS4 FdM8RAs5slmxnvuhir0pfrUE4MMX8iU1bbFOpC0GnDKc3JdbTw5t33a6gX9L0+QEa//q Moe7PlUXrCzDt8vhYLkeW4mi2lB1K0N8f3toj4hbRg49XwlvpdJDgQ2X2/TfUJiVY4Fe StwQ== X-Gm-Message-State: AJIora9k1ctpjdC32iLLj7xoXAzVQ70FWj1DKz7LulgPZYVfZWKHLp94 CGxlQvCWJXTR308jxO0GPIKhXql1GEkgFRGhsNXAABBPfN7PpQ== X-Received: by 2002:a0d:df50:0:b0:317:9c40:3b8b with SMTP id i77-20020a0ddf50000000b003179c403b8bmr6335286ywe.332.1655926042920; Wed, 22 Jun 2022 12:27:22 -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: From: Eric Dumazet Date: Wed, 22 Jun 2022 21:27:11 +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 9:04 PM Eric Dumazet wrote: > > 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... Ilya, can you test the following patch ? I think it makes more sense to let XFRM reject the packet earlier, and not complete the 3WHS, if for some reason this happens. Thanks ! diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index fe8f23b95d32ca4a35d05166d471327bc608fa91..da5a3c44c4fb70f1d3ecc596e694a86267f1c44a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1964,7 +1964,10 @@ int tcp_v4_rcv(struct sk_buff *skb) struct sock *nsk; sk = req->rsk_listener; - drop_reason = tcp_inbound_md5_hash(sk, skb, + if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) + drop_reason = SKB_DROP_REASON_XFRM_POLICY; + else + drop_reason = tcp_inbound_md5_hash(sk, skb, &iph->saddr, &iph->daddr, AF_INET, dif, sdif); if (unlikely(drop_reason)) { @@ -2016,6 +2019,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } goto discard_and_relse; } + nf_reset_ct(skb); if (nsk == sk) { reqsk_put(req); tcp_v4_restore_cb(skb);