Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1439094rda; Mon, 23 Oct 2023 12:36:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE83v57HZRP3kMsLjVIuzeafSV1bPefPIVSQ6EpiXpspXrat1GZdqYw4CJFbFij2vBIaOhe X-Received: by 2002:a17:902:cad5:b0:1c8:791c:d78b with SMTP id y21-20020a170902cad500b001c8791cd78bmr8735116pld.29.1698089780464; Mon, 23 Oct 2023 12:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698089780; cv=none; d=google.com; s=arc-20160816; b=vuGhU2kuDyjchcWzsWtsEi6gXMSqfiTfA7wvxKR2R5fvXq9q9b4ugaSbbY8Ycw0DYe pstFJi9CiMG4pnpcRKYisQ8wQzvorIiO2GlhhGnhRzCCAVvt4aSV38pKiR0zoDXPUoFL MRVAk+mh4HYrcz78KPYWErie51qJW1WbBtSN8oHPpb8M7bcOl0PABVquJNnCG5am3GK1 X+uVgdOwN5M9sd0wwYooprW/+toSqVnumHL890qzd1GzJVOuoNAJUHnUUbBG0i5/ZGRN eVxoPgJb0tUN8/GNNUUgSHjvw16O8QZVYMBfMgG3+QYYxXULOh4oaKKhsKngcJF/ytVN b1Ng== 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=Tnf1iX1DkpNXzc0ZSSfJXKOAq0XBa5++Rmv1hxBzDY8=; fh=a8JK1LlV6fjkJ2GExjvEHYBwBHtgXArNx6ms6Kac6b4=; b=yDmNQDqp3Ckp/WDnc4JGqA8JhuJ5skoR3ysjQCJb3X0SkhsTTqhOJgSfNvP792Clms hr1a7nn4kXqXXu22h4McvXK/ul/sbqxobltA2aWDf8O2gtpgRkrge0l+y+jbDseRnHN2 HzBLjG2igNvRZdaBC1id18qfVHk29IcKXxmCp+FuRGT97SI3jOmQSQ5imgAcHP48AzaU gQgTca/0s9/XfR3yoj9FMHX4sOAmjqP7VEF6gC16fwivowEgUB/wCph1X14nxig0ABsP hUd/cQoiyAFSPSJjG+t90ifWlYW060WtGtS2tE+RBUZkpok2APe27hCuOpt6Bb/qV3r3 DoGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=bUsxq9Us; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id r11-20020a170902c60b00b001b8039317cesi6584823plr.301.2023.10.23.12.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 12:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=bUsxq9Us; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 56BE8805B20F; Mon, 23 Oct 2023 12:36:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbjJWTfx (ORCPT + 99 others); Mon, 23 Oct 2023 15:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230432AbjJWTWe (ORCPT ); Mon, 23 Oct 2023 15:22:34 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67343FD for ; Mon, 23 Oct 2023 12:22:31 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c16757987fso53846391fa.3 for ; Mon, 23 Oct 2023 12:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1698088949; x=1698693749; 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=Tnf1iX1DkpNXzc0ZSSfJXKOAq0XBa5++Rmv1hxBzDY8=; b=bUsxq9UsEX+DhwdbUUKIqGeqqh7eMK2mWmlVX7UlGsc2fervEA7reB+MmmPxeSvcw1 26XUhHq3Jt7G5tROZ5ujX0SV7vnU9gqTxGl9SX58RqCFtKynpzuWx5hPFh1Ef5+cUqeW ULLv2di2OZsvkR2oXv+vAUVQODwiUVpd/AbGypxaEVZdwH3u50WtAidBWt3AYaSNJcgt PpANnMUp4sK2wQ3OATS0qp2cRJ5RoKInI5BiVnid1kttYHZ8UEzYc7xNUReKQaO32L0l +xUqMCY6XQGrl8CE2vCOhlpiQB7Srq0z7dSjWa+BfP3nELmzHf4x9BBXvE0NTYcEQvY0 /odQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698088949; x=1698693749; 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=Tnf1iX1DkpNXzc0ZSSfJXKOAq0XBa5++Rmv1hxBzDY8=; b=gOGxCnMv2FVouWEtc3f54AthngJ1klpKGJ8uehp3rKooGUFtsb1gKaNuFUV5du5LKF FEmbzvdM33IlGVN7V3YFkK5S1S4OojhFppvyLrrTR4H+5yMlud3FclfSdcd6P3O/RM+H XapGF/jogYk1mV+zmtaFIKQ9MDmhJtqKGrmYoRP/bsZidl3atzw85/lqwaOcCAcDGvKF rBcDEDySghxW/3e16Dxu1ev+73yDQRjdwv4RnSz8+h4btAmQbxVs5D78HObRc1oKMGrW TORBiFGGzLbsBupUfyd/SjhiXwK6ny4LoH7zpBrFcI7qfaNzQyiA1sWZiAIbr6V0oQer FzWg== X-Gm-Message-State: AOJu0YxnpKV1ZGJOxYSuQ+wvjHCHJCtcdOdg/EL+XF4wP5KlwlK8DXNW IXSNA8H/ArF6NA8mmKwgU9ZRkQ== X-Received: by 2002:a2e:be2b:0:b0:2c5:1e3f:7379 with SMTP id z43-20020a2ebe2b000000b002c51e3f7379mr7013992ljq.48.1698088949604; Mon, 23 Oct 2023 12:22:29 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id ay20-20020a05600c1e1400b00407460234f9sm10142088wmb.21.2023.10.23.12.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 12:22:29 -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 , "Nassiri, Mohammad" , Salam Noureddine , Simon Horman , "Tetreault, Francois" , netdev@vger.kernel.org Subject: [PATCH v16 net-next 02/23] net/tcp: Add TCP-AO config and structures Date: Mon, 23 Oct 2023 20:21:54 +0100 Message-ID: <20231023192217.426455-3-dima@arista.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231023192217.426455-1-dima@arista.com> References: <20231023192217.426455-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 12:36:07 -0700 (PDT) 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 Acked-by: David Ahern --- include/linux/tcp.h | 9 +++- include/net/tcp.h | 8 +--- include/net/tcp_ao.h | 90 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/tcp.h | 2 + net/ipv4/Kconfig | 13 ++++++ 5 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 include/net/tcp_ao.h diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 6df715b6e51d..64e7b560fa79 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -447,13 +447,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 1c52cf2e3f63..200e4b2e3898 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1686,12 +1687,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..af76e1c47bea --- /dev/null +++ b/include/net/tcp_ao.h @@ -0,0 +1,90 @@ +/* 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; + 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 8aa3916e14f6..74a1267baac5 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -361,6 +361,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.42.0