Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4138915rdh; Tue, 28 Nov 2023 12:59:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuYd0UhfvH0IGezbVJE6+8wX8xgewMT1161EDSAMMqHMXs0VEx0AessB+kw+1Zgs4BfMgF X-Received: by 2002:a17:903:4d4:b0:1cf:636f:1bf8 with SMTP id jm20-20020a17090304d400b001cf636f1bf8mr23452728plb.24.1701205158909; Tue, 28 Nov 2023 12:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701205158; cv=none; d=google.com; s=arc-20160816; b=Ua2vSqtLrk/mv9InbpHIkr/b9Nnn/EY/4j+1k724Jsz8Gm1yY8SpEcHarSZV+Sm8Y4 mtWw4Dvu9VCbY5grBsNrh1cfwIeeEmuAwIQHZNK3MIk59NhJNCn1cA8nNrK2lSSmvHk2 BBTCEDg3UV7Hl5bVDjQ5FTPfiXo4Ur6D2D/EemjKSXQnPb3SQT7uB6pe90eMr95Qk+0E 5T0sGlvq9O+ARso12NZsn+S/IIqPxzbxWtVmqpjoCEC27Ae3pZIhxSbwn+zlx6n90Sfm P0OMpYStmvQoIiAdIplGMyscsGPQUlIlM6Y5p4B9mBKrOLYkFQjH9vEA9JOdl+N5Zn+U lnqw== 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=gU+yhXqKVHhVs+IYT9IgohYNUQjtqLoZ0jYqAIsCX6s=; fh=Yk/Quc8tqIb7VaGeTLaGy5uds5Cbik8MTMk6yfuC1TU=; b=iAzD4U3rBCu3pIdOJIeO/l9yEJkU/k9CYdlHySbtYyMhakzFZm5rDDj7sd0cuiUCuU zjkoNSfU7eV2m7R5ulMTDQm5qgd24SWQIedqhZSxlRaEgXrqRh/+k4lIPf7z01ihicTB eytiuU1x5nTRbZoocQwnsEeeY3yG+8jE/+wbafFvZdIOKUk9WVYQDJS8e/ZmvGyV6tO1 wNhA1cvLLJqpabOZy55FXMQ5ilEYyKlKrXERXg1NbqFefKk/5+cXsATeFcskaioC+PnJ ht1PBk4BdmU49/r6uBJs2gx85FCVP6XzoNoLDTPNt2XLpF2YlkilLOvC12DhPiZ4iUn1 kuAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=MO7xJVuT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b8-20020a170903228800b001cfd8c8c358si4257273plh.184.2023.11.28.12.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=MO7xJVuT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A34D080A8B82; Tue, 28 Nov 2023 12:59:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346330AbjK1U6R (ORCPT + 99 others); Tue, 28 Nov 2023 15:58:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346610AbjK1U6J (ORCPT ); Tue, 28 Nov 2023 15:58:09 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA88C19B7 for ; Tue, 28 Nov 2023 12:58:07 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40b4e35ecf1so8718545e9.1 for ; Tue, 28 Nov 2023 12:58:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1701205086; x=1701809886; darn=vger.kernel.org; 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=gU+yhXqKVHhVs+IYT9IgohYNUQjtqLoZ0jYqAIsCX6s=; b=MO7xJVuT8lA7/8O0ozrsoah9ij51r3B0sf8vjErFxYlh+H+eQwrEWb79q4+lXIQQDF hLFCngZ9Zp3mgsBkrtGrY26NA3AdvqPrZjTCwX9eXSolZPuwx9Frcgsm2kHSnvJfHwtK O05BwcYFOEWn9BL7/bgSTE27NCWVHaJ/BUfWp/DezJaFsoG8oVWymGNfp5G6rF2RrRuA mLGGz66zdoTg6XRPgfLnkAtA9IR4BquAoG1EQ2yMwbdwpQ7FgeRAovi0Zz/iP7ejhjZO JU2auAf4e8+Rc419S0tUtmaNdhDkEwqtOneVZDVQRORNvfTdB2l+GHbtkcm9JtUkjSYL Z4+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701205086; x=1701809886; 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=gU+yhXqKVHhVs+IYT9IgohYNUQjtqLoZ0jYqAIsCX6s=; b=vZx/REN8ZLyQE2j13IfniK2YB+BeOFpFQXMCMNRhkQSaTBiKnpoSRcdhXifIzW3y1q g+HSf1KVoW1TRzR/wo6D2J+mlsG/CyjZTSgWkdi2sTkedJS9x0C8iPno10lE5y/kgNXh gHCM9E/A8DDdoSCTh9U36w9QKOiZ6DcBq++raD8rxxVEnImIj1Rd0Lkc7I1EEws6Uz3l yS74cAIf3Qr1XOIl4iCY6X6+mtcN0NU/m58my558qw3c4vF4aXmw6LeYqP1ARHhwvL6b C6eJ5tOzhw2Dj9rLY/Wh4GMnbexBtMD7WDIy6psDxeRqccbI69ThqEH1ptTMGm3RjrAw 7Z3Q== X-Gm-Message-State: AOJu0Yx03ORb6V7vFHOMtv33XX7A9GNpTJ5RoDEeLryORIPDFVjmILUI RzKOX62YIYrFwLEmcbeqVyYDPQ== X-Received: by 2002:a05:600c:46d3:b0:405:1bbd:aa9c with SMTP id q19-20020a05600c46d300b004051bbdaa9cmr11148170wmo.34.1701205086447; Tue, 28 Nov 2023 12:58:06 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id o19-20020a05600c4fd300b0040b45356b72sm9247423wmq.33.2023.11.28.12.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:58:05 -0800 (PST) From: Dmitry Safonov To: David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" Cc: linux-kernel@vger.kernel.org, Dmitry Safonov , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Salam Noureddine , Simon Horman , netdev@vger.kernel.org Subject: [PATCH v3 7/7] net/tcp: Don't store TCP-AO maclen on reqsk Date: Tue, 28 Nov 2023 20:57:49 +0000 Message-ID: <20231128205749.312759-8-dima@arista.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231128205749.312759-1-dima@arista.com> References: <20231128205749.312759-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 28 Nov 2023 12:59:15 -0800 (PST) This extra check doesn't work for a handshake when SYN segment has (current_key.maclen != rnext_key.maclen). It could be amended to preserve rnext_key.maclen instead of current_key.maclen, but that requires a lookup on listen socket. Originally, this extra maclen check was introduced just because it was cheap. Drop it and convert tcp_request_sock::maclen into boolean tcp_request_sock::used_tcp_ao. Fixes: 06b22ef29591 ("net/tcp: Wire TCP-AO to request sockets") Signed-off-by: Dmitry Safonov --- include/linux/tcp.h | 8 ++------ net/ipv4/tcp_ao.c | 4 ++-- net/ipv4/tcp_input.c | 5 +++-- net/ipv4/tcp_output.c | 9 +++------ 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 68f3d315d2e1..b646b574b060 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -169,7 +169,7 @@ struct tcp_request_sock { #ifdef CONFIG_TCP_AO u8 ao_keyid; u8 ao_rcv_next; - u8 maclen; + bool used_tcp_ao; #endif }; @@ -180,14 +180,10 @@ static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req) static inline bool tcp_rsk_used_ao(const struct request_sock *req) { - /* The real length of MAC is saved in the request socket, - * signing anything with zero-length makes no sense, so here is - * a little hack.. - */ #ifndef CONFIG_TCP_AO return false; #else - return tcp_rsk(req)->maclen != 0; + return tcp_rsk(req)->used_tcp_ao; #endif } diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c index fe68983fcf26..88c0a858534e 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -846,7 +846,7 @@ void tcp_ao_syncookie(struct sock *sk, const struct sk_buff *skb, const struct tcp_ao_hdr *aoh; struct tcp_ao_key *key; - treq->maclen = 0; + treq->used_tcp_ao = false; if (tcp_parse_auth_options(th, NULL, &aoh) || !aoh) return; @@ -858,7 +858,7 @@ void tcp_ao_syncookie(struct sock *sk, const struct sk_buff *skb, treq->ao_rcv_next = aoh->keyid; treq->ao_keyid = aoh->rnext_keyid; - treq->maclen = tcp_ao_maclen(key); + treq->used_tcp_ao = true; } static enum skb_drop_reason diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0a58447c33b1..9bcbde89ab5c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -7187,11 +7187,12 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, if (tcp_parse_auth_options(tcp_hdr(skb), NULL, &aoh)) goto drop_and_release; /* Invalid TCP options */ if (aoh) { - tcp_rsk(req)->maclen = aoh->length - sizeof(struct tcp_ao_hdr); + tcp_rsk(req)->used_tcp_ao = true; tcp_rsk(req)->ao_rcv_next = aoh->keyid; tcp_rsk(req)->ao_keyid = aoh->rnext_keyid; + } else { - tcp_rsk(req)->maclen = 0; + tcp_rsk(req)->used_tcp_ao = false; } #endif tcp_rsk(req)->snt_isn = isn; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 3ddd057fb6f7..335ab90afe65 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3720,7 +3720,6 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst, if (tcp_rsk_used_ao(req)) { #ifdef CONFIG_TCP_AO struct tcp_ao_key *ao_key = NULL; - u8 maclen = tcp_rsk(req)->maclen; u8 keyid = tcp_rsk(req)->ao_keyid; ao_key = tcp_sk(sk)->af_specific->ao_lookup(sk, req_to_sk(req), @@ -3730,13 +3729,11 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst, * for another peer-matching key, but the peer has requested * ao_keyid (RFC5925 RNextKeyID), so let's keep it simple here. */ - if (unlikely(!ao_key || tcp_ao_maclen(ao_key) != maclen)) { - u8 key_maclen = ao_key ? tcp_ao_maclen(ao_key) : 0; - + if (unlikely(!ao_key)) { rcu_read_unlock(); kfree_skb(skb); - net_warn_ratelimited("TCP-AO: the keyid %u with maclen %u|%u from SYN packet is not present - not sending SYNACK\n", - keyid, maclen, key_maclen); + net_warn_ratelimited("TCP-AO: the keyid %u from SYN packet is not present - not sending SYNACK\n", + keyid); return NULL; } key.ao_key = ao_key; -- 2.43.0