From patchwork Thu Aug 18 16:59:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 12947515 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 20D90C00140 for ; Thu, 18 Aug 2022 17:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345436AbiHRRDS (ORCPT ); Thu, 18 Aug 2022 13:03:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344052AbiHRRAx (ORCPT ); Thu, 18 Aug 2022 13:00:53 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B04C9E8B for ; Thu, 18 Aug 2022 10:00:42 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id n7so2430997wrv.4 for ; Thu, 18 Aug 2022 10:00:42 -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; bh=GNv1RskNujyBLlEJZ/l2OkjVUhos86+Endv5PP7heCA=; b=V7B4qDLspyMNioIqNcce76DZkwGXmeAqHLvPpeYHyMY38Eh4dEcY9CZY/1z6evNTv0 qDwdpqtzTWDUE2EDNhapkcvgGam8pPGLbhJyIFY4jfztmWhbkiyhMSFtvo9+ajAi2GwB 4ihpXweGFVY8TrkPwzQ4XHzXnhLmqsxuHIyILH15ufQE/vgUUeKvS0T7LYfY3VrndZcY CvVi8H/f5shpwSA8sqA8JYBEF8QA/j2VNWLISQ+9C6sJmkuwj2QJdcymOyWOrSfHeFhn HHISisxYUfg3cVl7di5oXw4XANtL+W0Eb47RYd3ZUkOU9gUUc4BFIAYgJzFmAGKQM+2R uUBg== 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; bh=GNv1RskNujyBLlEJZ/l2OkjVUhos86+Endv5PP7heCA=; b=VgknfFOToG9PBzupUPayC5ovJ/1VOV+1mpgg8+i3GZNS+5rjxFgm/QDiTzs2AUogCj EceSQ9Dg98NzvtQtHjUzFhPyi+v8RyjcBBT2kH/EGx+bw482a0/Ow16i8V4V9mqxx6wM BeZzZNB/tUnS7b1JJb2QG3d7qdDsQAlKRpbpRTAPQBXIhowa4rNMxgj6RrlHOh4ys3sD XR4qxnLdnTDDOJ0XAsahohBrumqMOt8qyFQB1xzvf2v7xZdP1jlp0no7sj+kve62SnKS BP6mjltjD2pF0/t/SBgYfZEGw2PslWHf2S6/vhTF8OvNSyx/fhVAK4rfFGFx35WR4g1w 57vQ== X-Gm-Message-State: ACgBeo2R27eTlTfLb6PKgcsfW8l42kqxfKx0l7hj4lAKg0t/MiOicOx5 7JNv7Ir1JSCGuLedQVAQuKDcqg== X-Google-Smtp-Source: AA6agR7hcC47yzehMcstwrPMELLbYsiLv869zPn2gYRwkgFethD1Vgf6vR5HtCO7Fyr4cGpETlVFOg== X-Received: by 2002:a05:6000:1f1d:b0:221:6c4c:4995 with SMTP id bv29-20020a0560001f1d00b002216c4c4995mr2209810wrb.675.1660842041703; Thu, 18 Aug 2022 10:00:41 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id be13-20020a05600c1e8d00b003a511e92abcsm2662169wmb.34.2022.08.18.10.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 10:00:41 -0700 (PDT) From: Dmitry Safonov To: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org Cc: Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , David Ahern , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Biggers , 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 19/31] net/tcp: Add TCP-AO SNE support Date: Thu, 18 Aug 2022 17:59:53 +0100 Message-Id: <20220818170005.747015-20-dima@arista.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220818170005.747015-1-dima@arista.com> References: <20220818170005.747015-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 b8175ded8a70..8d326994d1a1 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3516,9 +3516,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; } @@ -3526,9 +3538,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); } @@ -6344,6 +6368,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) {