From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D579C4332F for ; Mon, 1 Nov 2021 19:22:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5DE660FC4 for ; Mon, 1 Nov 2021 19:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbhKATZH (ORCPT ); Mon, 1 Nov 2021 15:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232577AbhKATZC (ORCPT ); Mon, 1 Nov 2021 15:25:02 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED58BC061766 for ; Mon, 1 Nov 2021 12:22:28 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id bp7so12338559qkb.10 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=QSSxL0BT+460sciwOc5gojR7+g08+My8bU/zWAgEHtaXklFspJD9eq0NnYIZqr5UGu c2x6LSHzBoIVorkAtwGHYTSg0jtlP2yo9/qwqzhsMXpQh/Oq3JW/bGbA94RbJfimndUR /BSH6BFJKSVwzXIFxDP67kKc9OMCv504/u+cPXfWADLlwoNAB5ppdQWMvZAd5GMzVw4r x4/0kQw2AKSPwj96bUydXok6gdVCViiSBIxwUje45d7Fw7O/U1LvQEesSJR4S0ZZZOxy L3DjgKe4HuxrQJB9CBCUJZk0F6qmfgchktYALtuM5f3VzDYbsrgDeRwcVqYiwQcyKGnL LVOg== X-Gm-Message-State: AOAM530qVmgUVKKqfsWbqUrzmV/PoRpPeIb9aI224wL7dqXduMmII48Y 4L/Jy4xS2P/sKZBB5S2CgOflPOqwr8F7IT6+1yuyYA== X-Google-Smtp-Source: ABdhPJyE7RArczaNdL0D1S1vAPyecuDc91E8gExiBs5AeCrNh8tSBwoegLoi41Fs09DtHsZzljDdRZzMUnILF1z5YGI= 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-kernel@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