From patchwork Fri May 12 20:23:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 93362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5379316vqo; Fri, 12 May 2023 13:41:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/GRNkCXnW45Yenu2QojjK5ZhrVHIaGW5dMfJlLPTvG4MUnp7GF0fvLQojgmBX4la6UMqp X-Received: by 2002:a17:90a:fa85:b0:24d:eb38:bfa0 with SMTP id cu5-20020a17090afa8500b0024deb38bfa0mr26422916pjb.11.1683924075245; Fri, 12 May 2023 13:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683924075; cv=none; d=google.com; s=arc-20160816; b=DjxcDI/Le6OaPCCUohfhPJE0NNGw8XcdE+0/YXxrF+2YWxwTA5EQHIF7L/3gWaP3hl fozsBhLF0mHhZO8rtwFohiwiVQ2MQZQbZlD1/JMKBzJzhTD7wfK9sYtnQ/yrxTAi1Myt K0EwTeymF5RAApBhPi4BR6qirpDiMxuIquosO33M6kQ2WPngILlXy/N+KtSGzVtbWZ0K Hh51TB91nrVUFsMX+3sBWIhSI6telFHQajUqqeV0ZAPur2p1lTJP3Rk0Z1SH1fz5JQHt gqH2u5Ckh5bBW6HrZKc0Zvv4IO3fhQBlsMsrIZr2UOsLAiw1N3GdfwKP8VzH1zzSGCA9 IWmw== 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=0dcdpK+4JPNZxxVzldNr8pk+aoPnnitnkLpo5A6eng0=; b=qBb2cvnlVGffeAXqBFl5iWZQdPBAKn6LL4m3pyXBhfuFhhts3gRVClnZk3uCuctwmr Hl1uwLi+bkps5jFVazfAkzkCwo7rP37jFT4GCJnvDikl7Z/dKeQAKXhNO0SIbP76uOb2 A1vTdGoLqg+vjExUL6xYBoAv9S0HLID8jlaVC0/PhxZunnQlPqQ3JHb1jM14yatOHMsM 7P9sYcK9nQSLEEi4GO/l6qRUS516jG8swixUy+WRmo3j4pE/jCWdSmmJ0zPkEP/PE0z1 B0gVwofJEPdLwt9zU8uNVQK7eBqf0rrtaLwEV+laswNYFvJ1p7EdT+t0XJU8E0WW2n9l X2Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=TnTLwyUY; 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 f16-20020a17090aa79000b002529b789d5esi4110055pjq.178.2023.05.12.13.41.00; Fri, 12 May 2023 13:41:15 -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=TnTLwyUY; 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 S239368AbjELUYi (ORCPT + 99 others); Fri, 12 May 2023 16:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232844AbjELUXl (ORCPT ); Fri, 12 May 2023 16:23:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6180E40DD for ; Fri, 12 May 2023 13:23:40 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f41d087b3bso75324825e9.0 for ; Fri, 12 May 2023 13:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1683923018; x=1686515018; 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=0dcdpK+4JPNZxxVzldNr8pk+aoPnnitnkLpo5A6eng0=; b=TnTLwyUYyBKp6L7s2zA/vT9j9N1AJZVn3txxbyGSYdfk5AacAc6ygwncJqipMJLsZL XpvKRHeI4RSFTbjxuJgwNpHPZCdKlV/r6a4jA5732irT3esDDYQGyINTv6m2IA4Y2UmU aNA4I4QoXwsAxNzMtbr4tk0rI12BFEWt1mzex5rg8NYM2nyZm31duMLnaqIdcWMuTU6Z qpxoASOk5bLnav0nTZqdXzS6iGsWGpePw9/5/Tp8dEdjxqEU6rC5796d2CVR+REqqbBW OW78XoIJaETP0WyXFNKAmejmbpqEmUers+wpY6yTIFqJA5CJ63u7QEZYjXSL7UIGFR9W SIXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683923018; x=1686515018; 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=0dcdpK+4JPNZxxVzldNr8pk+aoPnnitnkLpo5A6eng0=; b=Yb85PQNjHunqXK+GqOM4dl9JXE2ILPjPkELuU7D8CzOvBU81378OQ6fUlRVLRzt2/O kSkIF3NOFaRpg23UUW8/qVPN49Siq+ga50wp+7ehm3XGcB2ecoHXfkNAzW6oXUxDn4MW mD5Dw575NIFuIGF+0tsXA9EF8SrV2ZJ0foUniSpncFPw2/VZhzhB1aCDCKh4hxJ+z8o3 /wcEM6KUfLfH7FvbHPcNUCl6X3WDrM8uH7E0IIVj6g6LRFSCseD8S7pL1LffM7rIfKk9 1b5L4AqU2NCPxwzbK9LdBfnx7WvCNrTcaHCUq1NsGffLQHPTkdUewXMznksw2jbwkYD4 OUTA== X-Gm-Message-State: AC+VfDwqckRl49CZwL5rnHvDe0HiML32p+z3PvHf+CSe0ihS1vJagRk7 vRUQu6DdCbocFTzfeB7FVM1qTYhPgL0zIsnQaAY= X-Received: by 2002:a1c:741a:0:b0:3f4:e7c2:607d with SMTP id p26-20020a1c741a000000b003f4e7c2607dmr5371380wmc.13.1683923018652; Fri, 12 May 2023 13:23:38 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n9-20020a05600c294900b003f423508c6bsm17304527wmd.44.2023.05.12.13.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:23:38 -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 Subject: [PATCH v6 14/21] net/tcp: Add TCP-AO SNE support Date: Fri, 12 May 2023 21:23:04 +0100 Message-Id: <20230512202311.2845526-15-dima@arista.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230512202311.2845526-1-dima@arista.com> References: <20230512202311.2845526-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1765722371073891054?= X-GMAIL-MSGID: =?utf-8?q?1765722371073891054?= 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 959e4bdf2906..d87c73346e8c 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); } @@ -6371,6 +6395,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) {