Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1287737rwi; Thu, 27 Oct 2022 13:50:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HGXJjwbOtyDt7vPvagL3K5lszZqol5SU3ZPAwHPN7+fdILl5T9kJbxYgjdnaaOO8GZf9f X-Received: by 2002:a17:906:9bc8:b0:7ad:7e6a:50ac with SMTP id de8-20020a1709069bc800b007ad7e6a50acmr8954347ejc.66.1666903847188; Thu, 27 Oct 2022 13:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666903847; cv=none; d=google.com; s=arc-20160816; b=PCQhRmbSSeUruW4F9gBw8ryxphRi8Mvl3NSeaKLl3KyQhnFmbgy1EtXATLW8NtLKgI 4YTjR4syspRzM2F7D5o5Vb9aXJwuYxbCVcBL1kxRS1gyy1q3wOqOnljUl9UCdruDhJUm //mQXMRzjHXqWMizak/+5X99AclUlP7uE2hYUVQ3uNKCVDVKmQlpx2hKWGp4aUaF8LtM 2Qh/bTgQo7iG2iT41Q6/wR2P+eXFIBZuqxS0NEf/b+k6LsUnzYYfinN0gMxGQoufDVd+ 7wQDqAmnwNXV+1TEiyLJiTOE3E15jasqqGxJZi8NbylZvDEHkst/gj2/cJxBKCqlDuW5 HpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LVCplO2RHnjfrC7RtgmpM1L5+zWhF42z97+0t0sfJN8=; b=LBlh72ODW1PYAi+4b2Fm8eFaIkF80jfT4Zs0J0hRmUfeBMMQMx+6wgipE6o7un7pHW 51ORtpYcHpPTObN/tioL9pR0iF9qhl6PlKmUUL2zQs7eh4Ynlr8gzQf+FV5fqh9rdTgO MulJ56H98DRLMYDIL58VUt9pYoYHj3yXBw0pShfGXC7zXgFjJxoc9GtvA/UOJUrOiNma OYzG3Hs1RkI2Gjtdg+ASYzMfKAzuVbW5nHdXA0nRNm+KbgJENBvELsY2itFjQGPhcS8s XPhs7e0NIaqho3wV+pP6szuno577EXrW8Z0YaVHW2kH3i5KaoAtVCOwSUCjmzFSICDxN TS8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=QL6SzRsz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg8-20020a170907970800b0078dcd448f97si2780295ejc.801.2022.10.27.13.50.23; Thu, 27 Oct 2022 13:50:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@arista.com header.s=google header.b=QL6SzRsz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237077AbiJ0Usp (ORCPT + 99 others); Thu, 27 Oct 2022 16:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237082AbiJ0Ur1 (ORCPT ); Thu, 27 Oct 2022 16:47:27 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C269895E7E for ; Thu, 27 Oct 2022 13:44:25 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id i5-20020a1c3b05000000b003cf47dcd316so5037168wma.4 for ; Thu, 27 Oct 2022 13:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LVCplO2RHnjfrC7RtgmpM1L5+zWhF42z97+0t0sfJN8=; b=QL6SzRszsclV++kFI3bieAAVbkGgC2T/1v4taDU6gePMi0RQi/NEtAR7EBP0VuvzFX laiQ8UKgVGa/jhuL3yrkzunNKcqpMhg8x/w0tkOX+GBCqM1CNsKtTAiCh8eWYouRGsey VbwOC8LiruovXfGGw3u2DgxDXh58qAGHskwp37i5DYqtfJIZw4LkIxDIObyYjECbuBbY xlAaWqi+XSynChBBRleFOE65Dqg8qUX/9rKMzmrNmRHYTU4jjI0gSUtrs1oTjV2Oxptm PCuBbVnACirSe1tRG7OpgftGKmSD/FNqrw3C/R3YUloHoRQjm6v3Kfcvf2HbAazSXzW6 SuUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LVCplO2RHnjfrC7RtgmpM1L5+zWhF42z97+0t0sfJN8=; b=2A7Ch0rkXO9a3tlSUvN4LCXRLvD6Fou8mQ4Ppw4+1Y3105D5vvaNWUM5Vyltkcieay hBbqF7SgngXgNOK9MY/8tN6YKuoMd3Ef1K0+yVA/yHZtfv8PEzu4YBPFKKhg8KKrLcWk edGhQCttvq8ohxHQY049oMtIhYa2098J5YbSLJMQFVqYYUq1L34RHnSZnJfyTa5dBB5q rnbiIlysgto4g0mHmNx6Jj8z7/mlH/3UxjNEB7XrAR1G6ipy5tUax5XHerTrvB9Q+W7k eVNylAUWxqmLZvCwcShebymV+cpOjNDKWCxS1t4lh1C+aMZhpP7RdeBvkVm86U7Ucaeh 4JTA== X-Gm-Message-State: ACrzQf1sZG5tW43PMj7k9TZ0ToBRQYoP7w71bP2hEpiQo+K/225wRJZh jdT9sGfsISRdCrgiR/tgMq1xaQ== X-Received: by 2002:a05:600c:3592:b0:3c6:f9db:a954 with SMTP id p18-20020a05600c359200b003c6f9dba954mr7176562wmq.170.1666903463838; Thu, 27 Oct 2022 13:44:23 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n3-20020a5d6b83000000b00236644228besm1968739wrx.40.2022.10.27.13.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 13:44:23 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet Cc: Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , Dan Carpenter , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Biggers , "Eric W. Biederman" , Francesco Ruggeri , Herbert Xu , Hideaki YOSHIFUJI , Ivan Delalande , Jakub Kicinski , Leonard Crestez , Paolo Abeni , Salam Noureddine , Shuah Khan , netdev@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH v3 19/36] net/tcp: Add TCP-AO SNE support Date: Thu, 27 Oct 2022 21:43:30 +0100 Message-Id: <20221027204347.529913-20-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221027204347.529913-1-dima@arista.com> References: <20221027204347.529913-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-crypto@vger.kernel.org Add Sequence Number Extension (SNE) extension for TCP-AO. This is needed to protect long-living TCP-AO connections from replaying attacks after sequence number roll-over, see RFC5925 (6.2). Co-developed-by: Francesco Ruggeri Signed-off-by: Francesco Ruggeri Co-developed-by: Salam Noureddine Signed-off-by: Salam Noureddine Signed-off-by: Dmitry Safonov --- net/ipv4/tcp_input.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index df3087c8179f..2ba46d5db421 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3528,9 +3528,21 @@ static inline bool tcp_may_update_window(const struct tcp_sock *tp, static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack) { u32 delta = ack - tp->snd_una; +#ifdef CONFIG_TCP_AO + struct tcp_ao_info *ao; +#endif sock_owned_by_me((struct sock *)tp); tp->bytes_acked += delta; +#ifdef CONFIG_TCP_AO + ao = rcu_dereference_protected(tp->ao_info, + lockdep_sock_is_held((struct sock *)tp)); + if (ao) { + if (ack < ao->snd_sne_seq) + ao->snd_sne++; + ao->snd_sne_seq = ack; + } +#endif tp->snd_una = ack; } @@ -3538,9 +3550,21 @@ static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack) static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq) { u32 delta = seq - tp->rcv_nxt; +#ifdef CONFIG_TCP_AO + struct tcp_ao_info *ao; +#endif sock_owned_by_me((struct sock *)tp); tp->bytes_received += delta; +#ifdef CONFIG_TCP_AO + ao = rcu_dereference_protected(tp->ao_info, + lockdep_sock_is_held((struct sock *)tp)); + if (ao) { + if (seq < ao->rcv_sne_seq) + ao->rcv_sne++; + ao->rcv_sne_seq = seq; + } +#endif WRITE_ONCE(tp->rcv_nxt, seq); } @@ -6357,6 +6381,17 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, * simultaneous connect with crossed SYNs. * Particularly, it can be connect to self. */ +#ifdef CONFIG_TCP_AO + struct tcp_ao_info *ao; + + ao = rcu_dereference_protected(tp->ao_info, + lockdep_sock_is_held(sk)); + if (ao) { + ao->risn = th->seq; + ao->rcv_sne = 0; + ao->rcv_sne_seq = ntohl(th->seq); + } +#endif tcp_set_state(sk, TCP_SYN_RECV); if (tp->rx_opt.saw_tstamp) { -- 2.38.1