From patchwork Mon Apr 3 21:34:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 78761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2600994vqo; Mon, 3 Apr 2023 14:43:19 -0700 (PDT) X-Google-Smtp-Source: AKy350bcdkZrLC3Q5e1z97T7RnQvGjlvKrtfTatxsoHj97lNuloH6fweJio/z2Dd8fGHChyyn7jd X-Received: by 2002:aa7:8ec1:0:b0:622:7e20:71d with SMTP id b1-20020aa78ec1000000b006227e20071dmr50529pfr.17.1680558199723; Mon, 03 Apr 2023 14:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680558199; cv=none; d=google.com; s=arc-20160816; b=d9cUf64E7WpK+qXRD3DBih85SG8Aotup1ih6K3Gdp9PKKfGibq/lt3bcDE+FfknWvo asnfgz7leehoCh07UBHLWfo2BmVrByWL6JYFe+sd1GGRmRTaLmmCR3EnMVMe4TnZ1YuG bOgohtqIKLQjjznu53RcrbtnLKPTqGeGIN+xeECYyUl01iWeFDDSNpey4CA2eW3edft1 i1q28O656O4Hm4ltlH/yWqn+YjxnjK3a0DsWPSswspvvAjjtLALLWF5VlyPivU9mYg5H iLn9GlpvibdJVvYdpszKPbg69CFD4Z+MTBRtKXH71JTUohEz6BrZ0GZw3EVmuw0VOWEp x66w== 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=+Ge40um6T0c9VlT3HJFZRzMlpAJZfWTZ9vxKJINGVLI=; b=u/FkNuHjJQ9IMe0pZUvGrdUV/YeCbK4WkgVyKJa3Q7bWGTsRiEstF7Fszcbnt83PNZ 1AzQUtDdpb1yViKO3MHXeMePOIXUQePS3X2g06dneCrWcOUeECH3vfwnaU6GesDOEM1J DfFUUYe0Cuy6OGPqcSYe6Ne2r6wefj3e8WcRrdX4PI7ouz0rdye1FAEfM/X9X5QoCTQE Ss9T76W/NHNRfgcmM+cdm2o7zF1KaWwf1fb5mEQs/H+TaCmtRtNKYCobXvj7A8O9N4+/ pTzILpnxgJ+wEHKv74H5viZVxVQiNXarACTwU15SJkcVsVV/eoyT3cLLc5zAVTrACjpf 2weA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="j/rHAfQE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b27-20020aa7951b000000b005a8f259220asi9149380pfp.66.2023.04.03.14.43.07; Mon, 03 Apr 2023 14:43:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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="j/rHAfQE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S233701AbjDCVgv (ORCPT + 99 others); Mon, 3 Apr 2023 17:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233294AbjDCVf5 (ORCPT ); Mon, 3 Apr 2023 17:35:57 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A7D4EC2 for ; Mon, 3 Apr 2023 14:34:48 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n10-20020a05600c4f8a00b003ee93d2c914so20333779wmq.2 for ; Mon, 03 Apr 2023 14:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1680557686; 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=+Ge40um6T0c9VlT3HJFZRzMlpAJZfWTZ9vxKJINGVLI=; b=j/rHAfQEw4t1Yoax9U9Rd1BAvFvAhJblOK41bFFaQg7pupUYAtB6fMw0dC54rPTOS+ bvEaERG8OidAzn+ig0SG18ebWq3FW4gB/YQzoXVRZmsGBjw4IQ042yqyQR74cZ9dAAeO sT2b+yqbJ12eklhpqpqc7lh+AyF8O6iRwAf50E2qz95OMPE/mlbTBr74YSMZNd4p4qbG baqKCIbPKOa9pCMQg8xdzs873wBgRHBse/r226drwM/khtO65GysmZjwwh3JQHzZ47xV VOFTCydK5R1wlTiKK+TMgPmJFZ6yp6qfNVfk73zgr/GrwN19OBo86j5cnFKlT3/C3/AG KEuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680557686; 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=+Ge40um6T0c9VlT3HJFZRzMlpAJZfWTZ9vxKJINGVLI=; b=tMk8SdX+nL7BfDos4yGcyL9BjeHOBZXW1Yi47FoomjHoMei+9Z1ua25A+F+BW3j12r 439ozoGA79m+c5O5lATsbt/+tDWDxH4XJ96W/rk67M0HxjBh2WyU05CstAl0qxUP6VRm cvqKlOQBuUxG0MvtqCSKa9qUWS9wX9hWqzgPZK4/WY0qIn9l5Dv9A0eFRCnXyuHB6o8Q 8a+oaA2uCVU27DZnJviNjmb6/KcVjAZ8jyuYLeTgpU6xIGv0FVe8f/2h6uMzunhOV5qL yPeYcSS5yFCk5Nyh/LZYfXz2b573bK3GPiPwVq9mMXz0vK5wXOTBJtEJWywT1+bgA9DS Df3g== X-Gm-Message-State: AAQBX9cqqs4qSu0xrTGcAEY8O96+gdZvFCGvE2kAhubab3cGQgh8fs4M J2huh6Wo1L3MfihiLxX+PQwSIa/Aj//sOtdN98E= X-Received: by 2002:a1c:cc15:0:b0:3ed:9a37:acbf with SMTP id h21-20020a1ccc15000000b003ed9a37acbfmr490341wmb.31.1680557686726; Mon, 03 Apr 2023 14:34:46 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id o5-20020a5d4a85000000b002c3f9404c45sm10682740wrq.7.2023.04.03.14.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 14:34:46 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" Cc: Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , Dan Carpenter , David Laight , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Biggers , "Eric W. Biederman" , Francesco Ruggeri , Herbert Xu , Hideaki YOSHIFUJI , Ivan Delalande , Leonard Crestez , Salam Noureddine , netdev@vger.kernel.org, Francesco Ruggeri Subject: [PATCH v5 14/21] net/tcp: Add TCP-AO SNE support Date: Mon, 3 Apr 2023 22:34:13 +0100 Message-Id: <20230403213420.1576559-15-dima@arista.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403213420.1576559-1-dima@arista.com> References: <20230403213420.1576559-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762192994468259760?= X-GMAIL-MSGID: =?utf-8?q?1762192994468259760?= 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 9e7e5ee57137..d0a604b05518 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); } @@ -6369,6 +6393,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) {