Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4599531pxb; Tue, 2 Nov 2021 12:26:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeNEAghQEXzTnx1NYF7rpG7VDJg5Q3OMWOt/tx61N+atRNin2NE5Y/UbvXzMxDQGl4s/t5 X-Received: by 2002:a05:6e02:1809:: with SMTP id a9mr5962426ilv.203.1635881176576; Tue, 02 Nov 2021 12:26:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635881176; cv=none; d=google.com; s=arc-20160816; b=N+y8gCD03AYgHK7htmH2xBnIs6SewVPhg21fv9ItawN5JY6ENsoJY50P/z1XOZv2Sn UyVYsW32KwLvST2f1C/SS6vRnHhYoUV8XUF0saeD//EDIgyuC4ZiRwRbZedL+Hr13xdF 9AcjahPHI1VApVHJiADGsAoRSTLPBaVoBMRR8JFHeMH77GVh+fJDirkX1PJD+w4g3iuq Inu8+59pgKs5gdYMEm+ZCARyapkZQaeUzd9+GFjBnwWQvd7ttT3SmcFLM8aSwEN41AR7 3t1u5kDDxksePoUXb/lMutJJG8kZiixNegqkoh6rOD+QVDy9SWw6QyjvkhocwPapMfq6 mMGw== 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=WBuZwnr+5bcLsCP355FoQ/4BAq59hOrIy0vTMjfrBb8=; b=O4ZnmYnGZK0EPwxdiFtT+Kd95U+DOflAaMVkZBmVMcL6SRkWmW3uuiAVexh3irmjx8 +S+h3q0eNYrDqO6gyQmQBVF6JzinnQSNn0p+c73s8+U1rI/V9+YXHj2BXFSuE/6F3+nc xOUoGmuGL50YI6SRo39mfMLOXcOJSIAY9xXxxY5ZlSitc3WOjFBKGNELJE7u38Lumx0I hSkDkvRr20CSlnL3bNj1DEwubcAuHbP+R9Gbl/xs2TJ21rJDVSj0v4ZZDIcs6n6KW6cx VQou2kSFz7yj34Zm42Ia7eiRovtPa6+OtTxyIhbIFx+JgP22yVoH3Wjcnz6HujL4FPXM 0uxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=ALlpwX4U; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 15si21780781ilt.5.2021.11.02.12.25.50; Tue, 02 Nov 2021 12:26:16 -0700 (PDT) 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; dkim=pass header.i=@arista.com header.s=google header.b=ALlpwX4U; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbhKBTYZ (ORCPT + 99 others); Tue, 2 Nov 2021 15:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbhKBTYY (ORCPT ); Tue, 2 Nov 2021 15:24:24 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAE16C061714 for ; Tue, 2 Nov 2021 12:21:49 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id az8so118663qkb.2 for ; Tue, 02 Nov 2021 12:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WBuZwnr+5bcLsCP355FoQ/4BAq59hOrIy0vTMjfrBb8=; b=ALlpwX4Ukti+ianWKoWCIEQelRKQDPprVmMyF7bY3MLoaTiwrVTK5iB5Dj/dZaHq3W KZV8OTzfuS/or+8PvImBgX4G6dn8bORZKLQieLhsR0VakaYdhiVDHPhqE0DAc6DgI3YP qOUG2tDX/JOnvl9Fs5gLfeQrOTTSOwWxomvDyz5A1EYf5j/a4RtkxXLXKZ7lUnzZknTT 5KOSyYc907dONlMc0xlMGtReevrX7GYR1ReSD+XzKCg7O/fxvgDH2qzJ+0nVPEV/GhfQ soNobREkXIq9xmUImY+ilfq91wSTK1/k0Vy+HjHldzm/1iR0gqxelWZNN2L5Z0Kc/FGn z0VA== 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=WBuZwnr+5bcLsCP355FoQ/4BAq59hOrIy0vTMjfrBb8=; b=Ec3jRPG4vW9N3tPzWV5GBOnfoIxVLrQ9xG+ZXqBsEEaeVoN459dk9ztgN8av734E7q pcIdfl5y1jtt94v98b0rL/vVBJ2GykXSjpZvXQccqGeo5jC2WvC6uJyDVw8MzJZpqFk3 nS7yGowJAqGpg1K3V31ye/Xixx6kxX0FMeLMme1jxy7iaKLtdfJf9HrrSMqs5fjllI59 7Kh8VuZdJYj1Y+q0QKxoWKzDWpRwy6IU0r/aPmCfQrXggDGrkqAKCT3IkWi1qEsIcU9w l14elcVxXvD+WmXysF8srKOF8+hmglCTGBREV9pzy1Xuc5P99jKbrhuhZtR+oZi+lPfn qheg== X-Gm-Message-State: AOAM530ECSdhUUs8Tak51ZsDa9AvPh3rz/obu8xpo4L2IFULiNckGC/5 DvGilmsiU9G/OZkwfluuMwjT+47nAv9peljDvfNhSA== X-Received: by 2002:ae9:edc6:: with SMTP id c189mr30616528qkg.183.1635880908773; Tue, 02 Nov 2021 12:21:48 -0700 (PDT) MIME-Version: 1.0 References: <6097ec24d87efc55962a1bfac9441132f0fc4206.1635784253.git.cdleonard@gmail.com> <876f0df1-894a-49bb-07dc-1b1137479f3f@gmail.com> In-Reply-To: <876f0df1-894a-49bb-07dc-1b1137479f3f@gmail.com> From: Francesco Ruggeri Date: Tue, 2 Nov 2021 12:21:38 -0700 Message-ID: Subject: Re: [PATCH v2 11/25] tcp: authopt: Implement Sequence Number Extension To: Leonard Crestez Cc: David Ahern , Shuah Khan , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Dumazet , "David S. Miller" , Herbert Xu , Kuniyuki Iwashima , Hideaki YOSHIFUJI , Jakub Kicinski , Yuchung Cheng , Mat Martineau , Christoph Paasch , Ivan Delalande , Priyaranjan Jha , netdev@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Nov 2, 2021 at 3:03 AM Leonard Crestez wrote: > > On 11/1/21 9:22 PM, Francesco Ruggeri wrote: > >> +/* Compute SNE for a specific packet (by seq). */ > >> +static int compute_packet_sne(struct sock *sk, struct tcp_authopt_info *info, > >> + u32 seq, bool input, __be32 *sne) > >> +{ > >> + u32 rcv_nxt, snd_nxt; > >> + > >> + // We can't use normal SNE computation before reaching TCP_ESTABLISHED > >> + // For TCP_SYN_SENT the dst_isn field is initialized only after we > >> + // validate the remote SYN/ACK > >> + // For TCP_NEW_SYN_RECV there is no tcp_authopt_info at all > >> + if (sk->sk_state == TCP_SYN_SENT || > >> + sk->sk_state == TCP_NEW_SYN_RECV || > >> + sk->sk_state == TCP_LISTEN) > >> + return 0; > >> + > > > > In case of TCP_NEW_SYN_RECV, if our SYNACK had sequence number > > 0xffffffff, we will receive an ACK sequence number of 0, which > > should have sne = 1. > > > > In a somewhat similar corner case, when we receive a SYNACK to > > our SYN in tcp_rcv_synsent_state_process, if the SYNACK has > > sequence number 0xffffffff, we set tp->rcv_nxt to 0, and we > > should set sne to 1. > > > > There may be more similar corner cases related to a wraparound > > during the handshake. > > > > Since as you pointed out all we need is "recent" valid > > pairs as reference, rather than relying on rcv_sne being paired > > with tp->rcv_nxt (and similarly for snd_sne and tp->snd_nxt), > > would it be easier to maintain reference pairs for send > > and receive in tcp_authopt_info, appropriately handle the different > > handshake cases and initialize the pairs, and only then track them > > in tcp_rcv_nxt_update and tcp_rcv_snd_update? > > For TCP_NEW_SYN_RECV there is no struct tcp_authopt_info, only a request > minisock. I think those are deliberately kept small save resources on > SYN floods so I'd rather not increase their size. > > For all the handshake cases we can just rely on SNE=0 for ISN and we > already need to keep track of ISNs because they're part of the signature. > Exactly. But the current code, when setting rcv_sne and snd_sne, always compares the sequence number with the rcv_sne, tp->rcv_nxt> (or snd_sne, tp->snd_nxt>) pair, where info->rcv_sne and info->snd_sne are initialized to 0 at the time of info creation. In other words, the code assumes that rcv_sne always corresponds to tp->rcv_nxt, and snd_sne to tp->snd_nxt. But that may not be true when info is created, on account of rollovers during a handshake. So it is not just a matter of what to use for SNE before info is created and used, but also how SNEs are initialized in info. That is why I was suggesting of saving valid pairs (initialized with <0, ISN>) in tcp_authopt_info rather than just SNEs, and then always compare seq to those pairs if info is available. The pairs could then be updated in tcp_rcv_nxt_update and tcp_snd_una_update. Regards, Francesco