Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6078964rdb; Mon, 18 Sep 2023 03:39:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7hjiLBn/9+5bdbtR18f1bkkmjbvoFIGn9doNuYgl6kanJvAIs4cvFBMayszX3COQUBrfA X-Received: by 2002:a17:902:bb8f:b0:1c3:6018:fda4 with SMTP id m15-20020a170902bb8f00b001c36018fda4mr8271826pls.64.1695033549417; Mon, 18 Sep 2023 03:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695033549; cv=none; d=google.com; s=arc-20160816; b=PKqWi016PXtsm41G3OfMCGEiX2aKvmPc47VN0O45a/cIqi1jfVMVOR2mA3tOUOX2UK c3t+0jfcAC/NVLj41W+hcXJSBUsemJfW15+iLpkaBx97KJqwZZnZq29SDtqZd69sYiFR Eq/6T6D8p2CYnLPWkPdRB2ATB/fKuBDVkEAqqakRbIfda95iUSgul5J8IcEYsVj7gKKr aC3W4sXSs2/4SnpIFicnoE0erJCOmGdgX1CNq1wGFvxxZrWIqIVI98l97QXX6utx/nBm yPtnuLsWbMSeB0HQ0HRacTZ9VxGwgSl34l4HplNN6dKCiSYGPsrBYXAwHK579CrF0e1O rCQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=xYhG2A61Mc/mN15tOMjlKfifxhGFXOSzfbzq6dhZFFk=; fh=xfdLYZ+xTM3soJ/fGfj6pbOLOG+uI2xdobPFOHZNdM0=; b=GK39zR9Fzmn+zQ2uERsrNn8kN0quBr9TIppgPeORqz47gGE5XeBMz5T1ulLMs8utvP MK37g4D653o4azvj39qCLoQxv/HFzgzapQ2rhTdcS3xJIQ8/YCznqSuSWOZ0dYN3bb9f X49eIFjK1RP5EIdrWYJwwiyaHYfYxI+VvalWEShsOttLS/BTgQp3pxFKkcUkXMcLq7Ub G5HNpwo9/1znq8NdC0HwreT11Co1nvLSsSyrXxoOObtJk/Qad0DqmSsZXINppW+uXUPu BcKS1KyYcOHVX9pvfeYvcTQNaBgQgtwYTEkXm+EF2pLchOWDtRGBq8fg4cY9rYIB3KY0 X6mQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id o5-20020a17090323c500b001bbc6846a21si7731445plh.429.2023.09.18.03.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:39:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D4C6B822E553; Mon, 18 Sep 2023 03:24:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239570AbjIRKXr (ORCPT + 99 others); Mon, 18 Sep 2023 06:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241195AbjIRKXP (ORCPT ); Mon, 18 Sep 2023 06:23:15 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F77121; Mon, 18 Sep 2023 03:22:57 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1qiBOj-0005r4-FR; Mon, 18 Sep 2023 12:22:33 +0200 Date: Mon, 18 Sep 2023 12:22:33 +0200 From: Florian Westphal To: George Guo Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] tcp: enhancing timestamps random algo to address issues arising from NAT mapping Message-ID: <20230918102233.GA9759@breakpoint.cc> References: <20230918014752.1791518-1-guodongtai@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230918014752.1791518-1-guodongtai@kylinos.cn> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:24:23 -0700 (PDT) George Guo wrote: > Tsval=tsoffset+local_clock, here tsoffset is randomized with saddr and daddr parameters in func > secure_tcp_ts_off. Most of time it is OK except for NAT mapping to the same port and daddr. > Consider the following scenario: > ns1: ns2: > +-----------+ +-----------+ > | | | | > | | | | > | | | | > | veth1 | | vethb | > |192.168.1.1| |192.168.1.2| > +----+------+ +-----+-----+ > | | > | | > | br0:192.168.1.254 | > +----------+----------+ > veth0 | vetha > 192.168.1.3 | 192.168.1.4 > | > nat(192.168.1.x -->172.30.60.199) > | > V > eth0 > 172.30.60.199 > | > | > +----> ... ... ---->server: 172.30.60.191 > > Let's say ns1 (192.168.1.1) generates a timestamp ts1, and ns2 (192.168.1.2) generates a timestamp > ts2, with ts1 > ts2. > > If ns1 initiates a connection to a server, and then the server actively closes the connection, > entering the TIME_WAIT state, and ns2 attempts to connect to the server while port reuse is in > progress, due to the presence of NAT, the server sees both connections as originating from the > same IP address (e.g., 172.30.60.199) and port. However, since ts2 is smaller than ts1, the server > will respond with the acknowledgment (ACK) for the fourth handshake. > > SERVER CLIENT > > 1. ESTABLISHED ESTABLISHED > > (Close) > 2. FIN-WAIT-1 --> --> CLOSE-WAIT > > 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT > > (Close) > 4. TIME-WAIT <-- <-- LAST-ACK > > 5. TIME-WAIT --> --> CLOSED > > - - - - - - - - - - - - - port reused - - - - - - - - - - - - - - - > > 5.1. TIME-WAIT <-- <-- SYN-SENT > > 5.2. TIME-WAIT --> --> SYN-SENT > > 5.3. CLOSED <-- <-- SYN-SENT > > 6. SYN-RECV <-- <-- SYN-SENT > > 7. SYN-RECV --> --> ESTABLISHED > > 1. ESTABLISH <-- <-- ESTABLISHED > > This enhancement uses sport and daddr rather than saddr and daddr, which keep the timestamp > monotonically increasing in the situation described above. Then the port reuse is like this: We used to have per-connection timestamps, i.e. hash used to include port numbers as well. Unfortunately there were problem reports, too many devices expect monotonically increasing ts from the same address. See 28ee1b746f49 ("secure_seq: downgrade to per-host timestamp offsets") So, I don't think we can safely substitute saddr with sport.