Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3359810pxb; Mon, 1 Nov 2021 12:22:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqfAaPxa0bnxKM7E9KpiOH6Z3H8iY1hvR/VJo0ygeCblwrbO1/AiddNKrT4a9A0GCmaCZi X-Received: by 2002:a6b:7f06:: with SMTP id l6mr15362467ioq.141.1635794569248; Mon, 01 Nov 2021 12:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635794569; cv=none; d=google.com; s=arc-20160816; b=LWzVeWDM0O2+cEnToP582S+QPMaX8rone9r34cZC4FNcXEVNFv4DMJuGFcGGbJ4Xjy h1AAiVwoK2F9f/ohiUX6iLFeFhMldBkjMy/cPvO9uTN09gIf/1/fkY7EeTeZM/SBU+Ql 9h9kDEQ1PmyFHvpoO7fMGRm3+jTO1aM2nuJBwVgDFXbBYTEUKVy5DkcojBoEEj8oxY3P JqruEId/MQKj6sAAqXslAT0sKVRgL4p/IO7vX8YgqCTe8Y+ZvZ29J1ZwKaUe1IWrEvHb wjWFi+Np0DUhxH5XGtAU9wE4pHLH3umHHtOIxmud6Ps/RaZkxrs0XVldotScWqbVqTVR z4jg== 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=Cn68F3AcLYrb8nMJ8xSM0TLR9A80m1LXeQBBE0KZNgo=; b=E+Gf9kzSeMRZdA1vbIT5jjq9VPfnhIH4/RwMotuRcPQDLbgzLTY1u5E9GIg1RBCHam KiGQdHAuOdI76QD4YeBdfpQBcmO4PHBPMqI+QxggobvFTl/5Syb6GPZLvz7pE5svZ/6R 8+YP+T2v32P7MDHrSqmfauJD0lL/IMkLxekBkp8sv+xMuL1FN8STlB8+zaOQxp9buvOF RrEg0KjtfSm5mxXDG/gpjkeenkpTu9kdWM+PHSIeGxPeK2NJcFgcVDBhdAru6LjsEYQT O1lgLbXzc7c/Nlmv55iuHiRb4Tl+sqdND8v0szx1BOPYkTLGM7yYe9PXJAmxHT9myoYq vBhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="dGTnH6/3"; 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 u4si29182501jad.91.2021.11.01.12.22.36; Mon, 01 Nov 2021 12:22:49 -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="dGTnH6/3"; 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 S232578AbhKATZD (ORCPT + 99 others); Mon, 1 Nov 2021 15:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231639AbhKATZC (ORCPT ); Mon, 1 Nov 2021 15:25:02 -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 B235BC061764 for ; Mon, 1 Nov 2021 12:22:28 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id bl12so3296201qkb.13 for ; Mon, 01 Nov 2021 12:22:28 -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=Cn68F3AcLYrb8nMJ8xSM0TLR9A80m1LXeQBBE0KZNgo=; b=dGTnH6/3QpH80bmiWodCiS0jeBeJ7NTIywierL6ecDg1Zz9sdXSKmOOdB95NkLUK21 4flfcpTie3pys4AEg/g1DTWuc2TixYzJA2e27DrbqjVf4e48F4afmUAegjwnUAJa7QCk qqOMxC+n5QXWwdNOM0rN1sSpvdDnHQlK/xPnKRuwY1+hWrHU6OnxFjE/Fq0TxTlbSpqg P3fioCEwJqvosl7eP36fgLJWPcRDhtAXLF/DnJWmmE7IPTLWQ+d2B/9lGrXLetdfYAdh +Yv2NaM9V/VYbmzO3uaWdLNXVjfy178VILbHAba6UVggo0FQsi9lT1SfqeFO/li5RB/4 yVtA== 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=Cn68F3AcLYrb8nMJ8xSM0TLR9A80m1LXeQBBE0KZNgo=; b=DoEoT8EAGFppgeRXLLJu0ydDSO6FCLfbVOU8FfLbZ1s6wQkRanW0y0x0SvAt0dZ76t nnrTplyBJA9RqRxuKpv0itYjtUOC05xBlcFTAIkUWDRFW+8iPQzsOyDMA+gGxpfKnw3G C2yMTOiPG6QUzhbkXh8liRX6fjlLQFFzMQ22yESJcmVnfOjSAIbGlN1KkFpV76onzZbY IX+C/6JxXsuXC0tLbBdDcEoWlMjUloNnJAghuMLBvVWns0JPedg9opifZocABu46qcRt P3ulwgTZkRUemuvrB/s2q2aSmDvKctil3vcY5kX+oZeEg3MWuLUv6A+LSurE0ANAmILm MLmg== X-Gm-Message-State: AOAM531wj1Afu83dbC83oDWBnTA1vV9YoNtwNBGNglgJ2g2oTCsvAeTx lbASa8ISscoOpUQv1V9w240WXFYnK32Omr9PNIexiA== X-Received: by 2002:a37:b7c6:: with SMTP id h189mr24717038qkf.377.1635794547806; Mon, 01 Nov 2021 12:22:27 -0700 (PDT) MIME-Version: 1.0 References: <6097ec24d87efc55962a1bfac9441132f0fc4206.1635784253.git.cdleonard@gmail.com> In-Reply-To: <6097ec24d87efc55962a1bfac9441132f0fc4206.1635784253.git.cdleonard@gmail.com> From: Francesco Ruggeri Date: Mon, 1 Nov 2021 12:22:17 -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 > +/* 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? > static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq) > { > u32 delta = seq - tp->rcv_nxt; > > sock_owned_by_me((struct sock *)tp); > + tcp_authopt_update_rcv_sne(tp, seq); > tp->bytes_received += delta; > WRITE_ONCE(tp->rcv_nxt, seq); > } > Since rcv_sne and tp->rcv_nxt are not updated atomically, could there ever be a case where a reader might use the new sne with the old rcv_nxt? Francesco