From patchwork Wed Feb 15 18:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 57664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp355680wrn; Wed, 15 Feb 2023 10:41:18 -0800 (PST) X-Google-Smtp-Source: AK7set+2hmsr2FGiYGRsADxiIut6tSd3U3x4JrSMkWUtuG+VUIg4TYD+LG2Oj2wm1JyvYuBxSYT5 X-Received: by 2002:a17:906:3b15:b0:8b1:2998:6474 with SMTP id g21-20020a1709063b1500b008b129986474mr3362645ejf.16.1676486477732; Wed, 15 Feb 2023 10:41:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676486477; cv=none; d=google.com; s=arc-20160816; b=Ci0kGSEGa5gi8umYMngVdOjFeeL75B8UzthUE3pRzUnLSsPImSIQ4Lkvr2kc0wjYCL j/3QaHUnxV/SomnY+cBzC2c1nUTYlvY7zk6qt/GAhDOSdkSe8xHXTJbpovU5YZBG2SbZ S2NLvxDuGDozk4/5xnobVgtesnRdyTOrjA0tD4w5AZZkwSJhDpJ1EPDXecUrnxiAB0dT PMWx2lMs+4Hk/jsfKmM7eF5LVbza6Uik4b8Go+QzyZB6TjgJWvxNH0m9YaiRTm60nJSf u0UyxuP2AwaT41D1qbWni71ldAfk1n0vN3R2IAmmO6OqURGQeupGmIauPHtwm2WqxeEY cC4Q== 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=OGskyb7pJ6ELCDekkQO9Fpll4hie2FaxctextYDdWfk=; b=1C6O32PHEEzhtdJXM8ynoFQSGxmadE6pA3q8K4lUZs2cM3U4BzTS0/9/mT5zt5El0y tDKliFhenC6alOuT0YRe8/gvuzeyz1D3eVpaZ61Iphg6zcBMeSSQV5AAXF5NqXXyGnao 78f5YtOYIH2yqWJDEdPRpl7V3Tp/h9H8bxvm9LIr0DL2vOVAyDDy4kBsGwesKCQnvwdi yxOPhvKuFHhKanu5SvQF25uEf0z/kM7ly5mSGUhxQXalXD+KOzYOIhdK3/JAkczVWuBG Mkqytx1F8WIhCOLtMNkqEg077j81EWalqTy9LakPwbz9nBoT64b7DauuQgH5rkQl1m9J mVXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=CvkYkGoj; 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 fd23-20020a1709072a1700b008b14d5eb8a8si459671ejc.153.2023.02.15.10.40.53; Wed, 15 Feb 2023 10:41:17 -0800 (PST) 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=CvkYkGoj; 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 S229822AbjBOSgC (ORCPT + 99 others); Wed, 15 Feb 2023 13:36:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbjBOSee (ORCPT ); Wed, 15 Feb 2023 13:34:34 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF1663D919 for ; Wed, 15 Feb 2023 10:34:10 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id y1so20129668wru.2 for ; Wed, 15 Feb 2023 10:34:10 -0800 (PST) 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=OGskyb7pJ6ELCDekkQO9Fpll4hie2FaxctextYDdWfk=; b=CvkYkGojRTF1eT48EAhOGxpKFAfJuXXxWbY2N2vR/d8PSdGwxRi0RhW/cnfkVMsAZb UgHEANYfWje/SIme3N1mvQJEZSkYoSwbgquxz1tXaWeUi4PNJrl9un3ZY5OMUqjUY586 +msL/Q7rs8Wuc9bFSUsEEH7usaRTGp6bWjN/mRrqceDp5Lhr/kjq6tl1jvImVNoNV5On jJOLzL+XV2hTym2JzS0CDZwnAi2GDxFeZlJheO4GsR02YAiEkdHATqcmYeJUBrTiEXgX CXSkyvtQjYwMTZybAeuCRcwnfVb3cDKh5mVveIt6xB2uxt3QdXYVJMAIAesQ7jF4/Lz3 rcCg== 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=OGskyb7pJ6ELCDekkQO9Fpll4hie2FaxctextYDdWfk=; b=iWB6J2Px0dNVvI5CA6gUg7ZZyIA6A6UFKevOqkWgkIDVW0ne1RoxCGalm9beLnKOpr 7SwFjRe86JaZZj/I0uNPBNvzqSg7uUph+tO9pvs5XGepfe8LIkQajLjZh9e3EMtAxXV6 qcF2EOZT0A4xm1rCcHwSC0iENoliroebdRZFDlf/vT8DfBM3NTAcLT3uHNOSpPkAIeIz 4mnuC3Q8bnRnbweFyLlU4W4reO1XLH5S52gg01aCqf5/nyvw84ejWtBJ4FQHAP+M26QH LhGwjwPV1I2WLzFcRVl+0ancZKqaQ7pe1qxKSShXNT76tH76v5hQw9lX0S65wsANdFZT cYCA== X-Gm-Message-State: AO0yUKVQJRqhhGXJulg384r8HcUoEWGdRTD1vvp0NkddovZtdFWRlAFY TPCtRNczViw57/2KBEyA/W8HOruKc6qaeSp2 X-Received: by 2002:adf:ef91:0:b0:2c5:4d16:8d73 with SMTP id d17-20020adfef91000000b002c54d168d73mr2693168wro.40.1676486049201; Wed, 15 Feb 2023 10:34:09 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id s9-20020a05600c45c900b003e00c9888besm3196306wmo.30.2023.02.15.10.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 10:34:08 -0800 (PST) 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 v4 14/21] net/tcp: Add TCP-AO SNE support Date: Wed, 15 Feb 2023 18:33:28 +0000 Message-Id: <20230215183335.800122-15-dima@arista.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215183335.800122-1-dima@arista.com> References: <20230215183335.800122-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 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?1757923484970105912?= X-GMAIL-MSGID: =?utf-8?q?1757923484970105912?= 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 264db761153b..9f23cab1e835 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) {