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: 13198823 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDCD9C76196 for ; Mon, 3 Apr 2023 21:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbjDCVg6 (ORCPT ); Mon, 3 Apr 2023 17:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233542AbjDCVf5 (ORCPT ); Mon, 3 Apr 2023 17:35:57 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52B2C2D4E for ; Mon, 3 Apr 2023 14:34:48 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id hg25-20020a05600c539900b003f05a99a841so971005wmb.3 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=doQYJ4ZKparZQv4D1FtEbDiaouhYnUZsihSEMGFIh9ikZbcM4KlSBeTKgQgjF88nPt AwNS/6Tk+lcquOaweVL/UFnK8UMSwf42SjHyfdoahFLV4ab385gzWR1OGkpNO35WU+7L m8rXXkUN9P5qpazNaBGg9ilBUBtfrGOexYF6XS3v16BzLeTyvsRIoJLu9hF0phqusflN onlySPZnQoRTzX6d7Sc/sVzyCBPlPNIPAlje1rWrIn8N3KmIbUD+yWOLNE41PbKHDTT9 mbC54LDlp6JT+pgUj+tRN0RyvibiJqG+lKWqSVEzuWB3z6ogtSxrD00noJUay41WTuXf vTNA== X-Gm-Message-State: AAQBX9c8vg4Yb2dBclpErI9XKXn1GOBRyIWzcPXzucM1kE78xAwgF8m8 uszZW0qHYrza/biU7xXHKHdhIg== X-Google-Smtp-Source: AKy350aDO3jFe8vsDWdTWWTsuDzHO8+LU8mBN+5X3bOkt8vgX+DYFJe5UO6BQbXfR1OtnyC9f/LklA== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 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) {