Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp176980rwo; Fri, 21 Jul 2023 10:07:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlFS1AqnP0C7eF/OwDnvkDypMcAGNqbvkIrD9X6KcvjQQteL155LdZUtdDW0Lx6RHQ17W0aE X-Received: by 2002:a05:6358:9214:b0:132:ce1f:6793 with SMTP id d20-20020a056358921400b00132ce1f6793mr468679rwb.21.1689959228094; Fri, 21 Jul 2023 10:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689959228; cv=none; d=google.com; s=arc-20160816; b=bNme16f/+sHruOwnC9SluvzdPgr3L1xKnMF9omBDZnLe/u0tk/6e0QA6ofXU4LYJ0S RpxQfwDvRC1pHcOuozh5+30s+Gj3wHqS4XNZYDhJr79DeHL+AJ1AjX+oy//WaTKzXDB4 f5HetgOiTYxtL5IdIZDenJVoIYC0W2oeRP4y/FI9NyJMGH/H+Ncsre10avSiSumRGhxm fDwFafX3bGm66zf3V5dtsvCBI12pKYLUlq/dW38/vPH/BLgGo2/EM4F3CRDSA9EVd/SZ w+lhqunyOHJ9pe9t8FrKa7jpsjL1hpTPecEQdeq7b1I4UX35hSmpEcLUmjmLxpz6wrpZ gKaQ== 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=SXko8P6r7e8uerkdDw+CjI2zgl0TQ49mqHOxxtoLcMU=; fh=+1v2wpWL3SwC67MevmNFbsOkJ0jlpe0KMhkxFTuop+s=; b=UA+/O+2Z+jL+7lLvENS2PFEpX5Ocw5DYkETVmGPV62R5KNZmVUhl5PiCLwsYs4Ocif rQoYAKLwm+2m30tVJMT1qp8NKGNOSL4OBm8icfUDaSQWvbZERh7D2x/VG6AsbZAcx+26 cXn4X+KBKhOSrmxCyXgM4otDgrB/U1WI9x+GDtbCc/qdhLXzbYqcx4lloiGV+AJvW7f0 XpiqfWMajGlpQHXB+APFMrdTDkmvOjlelsQxnLI1aruDQb8sEqhFWFmPnV2/Bzf1/J3R eoWSkg+6DLtr03hGTi+sCiS+frxyoQpallm5Zzaiqx+SOCYVP6BWGtUYYlhDeKXTjHTH 9zhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=TCjvhh5Y; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o13-20020a637e4d000000b00557807d78e2si3298135pgn.555.2023.07.21.10.06.55; Fri, 21 Jul 2023 10:07:08 -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=TCjvhh5Y; 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 S232712AbjGUQVt (ORCPT + 99 others); Fri, 21 Jul 2023 12:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232790AbjGUQVQ (ORCPT ); Fri, 21 Jul 2023 12:21:16 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B188949C0 for ; Fri, 21 Jul 2023 09:19:29 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b6f943383eso31218501fa.2 for ; Fri, 21 Jul 2023 09:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1689956368; x=1690561168; 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=SXko8P6r7e8uerkdDw+CjI2zgl0TQ49mqHOxxtoLcMU=; b=TCjvhh5YZl5Fs71DrHekt0EQrMBxfzWHIzsBcYRCkov27vrAzqcAJM6JH+9PYy4dcq 7JqaOS79lh8CWgzGkZJBYLhYJeLW0JE/R3ydBVYAxrfnEN7ghlq4bgiO0MbJVVZqlyOA 3znu6TquT8ZDLwfNqFfWN+5sd+6KIL1QvmUlhS3wMAsdl3cyPkkRoqrrzgUzqL9C4P32 vSa774TofALarjjbFVpDesw/PejAQlwvv8X7LvJC1DLRsfNUXjeoaYJjFS14GZ5eir93 +wr/4x+jBDAyBK2AAf8ZU0eRpadO1v46lzAPhxNvi0RL7ial+PJa3lRg4Wnf9x4mi7ME 0b+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689956368; x=1690561168; 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=SXko8P6r7e8uerkdDw+CjI2zgl0TQ49mqHOxxtoLcMU=; b=gG2LPCgQIOSu1Dt5W61EPoC4fn910h/LuTGELvf786r1TJyKrsKUQUO5S/tNZwtO90 nstz/n92sxBWUD/GLm8AEisfiOJhGQh46tnszibOQuKIt6btgWhTbI6mUYnUMJ2slqi3 +e3dtF9oTgORC7TOYVoz6LXQPPy8aSXP88xQq57Uzj00oh15Ru2EJ6yqxPDOg7jTuRiN IAypldu49qEkzf4Zd6iTn1QHe/2SPrTUAgBCK9Vdo9CYl8SgfgWw1sTSWpTeGUw44FIe 4+T2MvkfaG60ZYBnb9JwF/OSDi0o+sdiFYCWmH0+OIRwm2gJLwEQ4RWBDrQjUkj+lkP4 q02Q== X-Gm-Message-State: ABy/qLb0xSp3w1eQl1Sgxm5+Q+qw7xP6RIBdfmYscR9yAqte4x66B136 l0cHelogo25SyVSdDTBuhV39od2jtFl3Q9UeWV4= X-Received: by 2002:a2e:98d3:0:b0:2b6:e3d5:76a7 with SMTP id s19-20020a2e98d3000000b002b6e3d576a7mr2009258ljj.24.1689956367695; Fri, 21 Jul 2023 09:19:27 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id l19-20020a7bc453000000b003fbc681c8d1sm6390210wmi.36.2023.07.21.09.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:19:27 -0700 (PDT) From: Dmitry Safonov To: David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" Cc: linux-kernel@vger.kernel.org, Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , Dan Carpenter , David Laight , Dmitry Safonov <0x7f454c46@gmail.com>, Donald Cassidy , Eric Biggers , "Eric W. Biederman" , Francesco Ruggeri , "Gaillardetz, Dominik" , Herbert Xu , Hideaki YOSHIFUJI , Ivan Delalande , Leonard Crestez , Salam Noureddine , "Tetreault, Francois" , netdev@vger.kernel.org Subject: [PATCH v8.1 net-next 02/23] net/tcp: Add TCP-AO config and structures Date: Fri, 21 Jul 2023 17:18:53 +0100 Message-ID: <20230721161916.542667-3-dima@arista.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721161916.542667-1-dima@arista.com> References: <20230721161916.542667-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=ham 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 Introduce new kernel config option and common structures as well as helpers to be used by TCP-AO code. 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 --- include/linux/tcp.h | 9 +++- include/net/tcp.h | 8 +--- include/net/tcp_ao.h | 91 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/tcp.h | 2 + net/ipv4/Kconfig | 13 ++++++ 5 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 include/net/tcp_ao.h diff --git a/include/linux/tcp.h b/include/linux/tcp.h index d16abdb3541a..9eb15e798c32 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -437,13 +437,18 @@ struct tcp_sock { bool syn_smc; /* SYN includes SMC */ #endif -#ifdef CONFIG_TCP_MD5SIG -/* TCP AF-Specific parts; only used by MD5 Signature support so far */ +#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO) +/* TCP AF-Specific parts; only used by TCP-AO/MD5 Signature support so far */ const struct tcp_sock_af_ops *af_specific; +#ifdef CONFIG_TCP_MD5SIG /* TCP MD5 Signature Option information */ struct tcp_md5sig_info __rcu *md5sig_info; #endif +#ifdef CONFIG_TCP_AO + struct tcp_ao_info __rcu *ao_info; +#endif +#endif /* TCP fastopen related information */ struct tcp_fastopen_request *fastopen_req; diff --git a/include/net/tcp.h b/include/net/tcp.h index 95651f9c9242..d1230ee888fd 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1643,12 +1644,7 @@ static inline void tcp_clear_all_retrans_hints(struct tcp_sock *tp) tp->retransmit_skb_hint = NULL; } -union tcp_md5_addr { - struct in_addr a4; -#if IS_ENABLED(CONFIG_IPV6) - struct in6_addr a6; -#endif -}; +#define tcp_md5_addr tcp_ao_addr /* - key database */ struct tcp_md5sig_key { diff --git a/include/net/tcp_ao.h b/include/net/tcp_ao.h new file mode 100644 index 000000000000..3870cc29af10 --- /dev/null +++ b/include/net/tcp_ao.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _TCP_AO_H +#define _TCP_AO_H + +#define TCP_AO_KEY_ALIGN 1 +#define __tcp_ao_key_align __aligned(TCP_AO_KEY_ALIGN) + +union tcp_ao_addr { + struct in_addr a4; +#if IS_ENABLED(CONFIG_IPV6) + struct in6_addr a6; +#endif +}; + +struct tcp_ao_hdr { + u8 kind; + u8 length; + u8 keyid; + u8 rnext_keyid; +}; + +struct tcp_ao_key { + struct hlist_node node; + union tcp_ao_addr addr; + u8 key[TCP_AO_MAXKEYLEN] __tcp_ao_key_align; + unsigned int tcp_sigpool_id; + unsigned int digest_size; + u16 port; + u8 prefixlen; + u8 family; + u8 keylen; + u8 keyflags; + u8 sndid; + u8 rcvid; + u8 maclen; + struct rcu_head rcu; + u8 traffic_keys[]; +}; + +static inline u8 *rcv_other_key(struct tcp_ao_key *key) +{ + return key->traffic_keys; +} + +static inline u8 *snd_other_key(struct tcp_ao_key *key) +{ + return key->traffic_keys + key->digest_size; +} + +static inline int tcp_ao_maclen(const struct tcp_ao_key *key) +{ + return key->maclen; +} + +static inline int tcp_ao_len(const struct tcp_ao_key *key) +{ + return tcp_ao_maclen(key) + sizeof(struct tcp_ao_hdr); +} + +static inline unsigned int tcp_ao_digest_size(struct tcp_ao_key *key) +{ + return key->digest_size; +} + +static inline int tcp_ao_sizeof_key(const struct tcp_ao_key *key) +{ + return sizeof(struct tcp_ao_key) + (key->digest_size << 1); +} + +struct tcp_ao_info { + /* List of tcp_ao_key's */ + struct hlist_head head; + /* current_key and rnext_key aren't maintained on listen sockets. + * Their purpose is to cache keys on established connections, + * saving needless lookups. Never dereference any of them from + * listen sockets. + * ::current_key may change in RX to the key that was requested by + * the peer, please use READ_ONCE()/WRITE_ONCE() in order to avoid + * load/store tearing. + * Do the same for ::rnext_key, if you don't hold socket lock + * (it's changed only by userspace request in setsockopt()). + */ + struct tcp_ao_key *current_key; + struct tcp_ao_key *rnext_key; + u32 flags; + __be32 lisn; + __be32 risn; + struct rcu_head rcu; +}; + +#endif /* _TCP_AO_H */ diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index 879eeb0a084b..5655bfe28b8d 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -348,6 +348,8 @@ struct tcp_diag_md5sig { __u8 tcpm_key[TCP_MD5SIG_MAXKEYLEN]; }; +#define TCP_AO_MAXKEYLEN 80 + /* setsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, ...) */ #define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1 diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig index 89e2ab023272..8e94ed7c56a0 100644 --- a/net/ipv4/Kconfig +++ b/net/ipv4/Kconfig @@ -744,6 +744,19 @@ config DEFAULT_TCP_CONG config TCP_SIGPOOL tristate +config TCP_AO + bool "TCP: Authentication Option (RFC5925)" + select CRYPTO + select TCP_SIGPOOL + depends on 64BIT && IPV6 != m # seq-number extension needs WRITE_ONCE(u64) + help + TCP-AO specifies the use of stronger Message Authentication Codes (MACs), + protects against replays for long-lived TCP connections, and + provides more details on the association of security with TCP + connections than TCP MD5 (See RFC5925) + + If unsure, say N. + config TCP_MD5SIG bool "TCP: MD5 Signature Option support (RFC2385)" select CRYPTO -- 2.41.0