From patchwork Fri May 12 20:22:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 93346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5371791vqo; Fri, 12 May 2023 13:24:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6udjMeIfY9nKBAZbk/Oiggiftv+w/Ig+9i1L9FTClraVSWbwjBmHcXXEPbf5fUl6AKPGZQ X-Received: by 2002:a05:6a20:4658:b0:f6:2287:e05d with SMTP id eb24-20020a056a20465800b000f62287e05dmr26338910pzb.10.1683923088551; Fri, 12 May 2023 13:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683923088; cv=none; d=google.com; s=arc-20160816; b=hcKisffaSL04U/9VwxIRQsJyDZuRmSVO+DNE6cMc/FZTqaZby9JPGhME7slPjJw7XU wOZgi860ZOENyGnIpyYq7erSEj+r3CGeHkMtFWNHMMk93HkQNOgIa4d8wwx/O3ww3YyE zFo3KkaprA5itkMKbuU/dwCvhAVUim73GAkNKvoS97X+a4teSTyYMTpfVYCKfmIUoBCs qp3kK7IrtOtFHmtGvBrhrmxykTrzaoFW1tfSKMbhc1qGVNxpW4VQ5A8iws+6EzpAWxie dh/30Ls4MGrbqCYNm+3LcAMhsTmV/KE6ttzUfDpIZBICvVUyUHpGpYN9dCdu4XwLsLNE f4xQ== 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=7up6x5aNmZiRP0AB3eiB7dGjlKNQl0GQ8l4XcaCN6rg=; b=vGaTWwCv0UV6PThtXSxUOn1VA/8eqw1/WQH/F5PIA5zoM002txZIzL37r/BLux0/4k kCD43ewgZKUqCULRDEa1GxZ9aLcj9uy2vlxiUvoda5QpQNzawv0Y4hW0UpDYhRGmzNG/ krJePHMtNY9uPlk74a8uNFoS4U1i1omzkNsFGJbtu90pKAsKUTAnOyWsshjxVFrYPx9O 6w10EEXFD6iRYRuS27HYB2rCkItaKj8Zhow9aKx1QySzDpHOgf0gBAJHDbzWGXJfMsBQ qX0VA3BBP4Xu7YRTWa/RzUz36Z1eWMUMVTykvzeLjLpLdO4pYyW0YWvPsrjRtJt+kqEW dJGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=NMYG7gGx; 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 z195-20020a6333cc000000b005304f692247si8442669pgz.458.2023.05.12.13.24.33; Fri, 12 May 2023 13:24:48 -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=NMYG7gGx; 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 S238888AbjELUXm (ORCPT + 99 others); Fri, 12 May 2023 16:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237721AbjELUX0 (ORCPT ); Fri, 12 May 2023 16:23:26 -0400 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 87B47658E for ; Fri, 12 May 2023 13:23:23 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f427118644so62139685e9.0 for ; Fri, 12 May 2023 13:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1683923001; x=1686515001; 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=7up6x5aNmZiRP0AB3eiB7dGjlKNQl0GQ8l4XcaCN6rg=; b=NMYG7gGxC1zcHt6vJzgcoBF7QWpGp88zGkFpOKAGZuNpOHUjlYe+7yEPUJMSsfu5F8 FjRowlMbXpBTmK4sO82NPxXVUhPa3JBLCper9OjgCPrSo7LUX2b1A3JaT+WksHMKDutw l5kjgZVc1ZHxBilMPkAvyEUGkv3MAon084s9ghyVqCqPiiK8Gn5Tp3wLyPSzvMmO9+OG LAb/9bYQFDzk5aUssOoS5Z0SGxh4E7j5MO/2zl/jLq0PzHdF7JlUb5cB3fZwNixb3+gJ sDWi1yX3++P7vO/fQLdPXGcK9r1E7U+NzZqTdAn+TioDCTMeyqF5BbhKC8Rtayz+4Vho Q7zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683923001; x=1686515001; 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=7up6x5aNmZiRP0AB3eiB7dGjlKNQl0GQ8l4XcaCN6rg=; b=VeyJqkWtveUIqsL7MYu8OMZ0lRoootG2s+rn3cqbBNvpdAw5uqZUtKcbl4VsmTEAqB 4gAmvqLRT1D2jqguyLqsyOmI0xUTdZB8hsjmosbuKlftbgrsHp7K8KpJC6SDx+wjLacN lC2AwelojdSMDr/dIe/YdUgov78qX+bqo0UBmA6Q3goRkYFln+TOV0XUUpBGe2GJ67sB ynLhrZjE5bMi1DrgTsmBjTAAo9/awMNpA+fPB9DTUVS/AOnamjh3aj87N5iOSeiMCleG 1U9F0ZSR/wG65VpgZkkuOzpm2WdrMUO7wRVnLbfVu28Vtgw8d4UXyzoaWyA+JIqqa4WC 2W5Q== X-Gm-Message-State: AC+VfDyswSpQHGt3sroRFGruaNhTO8t2HY8P/cCeTR89A0axlmMZ/3eI 5FVbuwLI8CpyKNvnnOYe/DRsc6z8HJGQHE1t7vk= X-Received: by 2002:a1c:7418:0:b0:3f0:8ed8:853c with SMTP id p24-20020a1c7418000000b003f08ed8853cmr20406616wmc.37.1683923001603; Fri, 12 May 2023 13:23:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:23:20 -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 02/21] net/tcp: Add TCP-AO config and structures Date: Fri, 12 May 2023 21:22:52 +0100 Message-Id: <20230512202311.2845526-3-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?1765721336527530662?= X-GMAIL-MSGID: =?utf-8?q?1765721336527530662?= 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 | 96 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/tcp.h | 2 + net/ipv4/Kconfig | 13 ++++++ 5 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 include/net/tcp_ao.h diff --git a/include/linux/tcp.h b/include/linux/tcp.h index b4c08ac86983..673b32e47c30 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -435,13 +435,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 b77cc2e0b8e6..b7c974f8f893 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1618,12 +1619,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..234ae371043b --- /dev/null +++ b/include/net/tcp_ao.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _TCP_AO_H +#define _TCP_AO_H + +#define TCP_AO_MAX_HASH_SIZE 64 +#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; + u16 port; + u8 prefixlen; + u8 family; + u8 keylen; + u8 keyflags; + u8 sndid; + u8 rcvid; + u8 maclen; + u8 digest_size; + 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_sizeof_key(const struct tcp_ao_key *key) +{ + return sizeof(struct tcp_ao_key) + (TCP_AO_MAX_HASH_SIZE << 1); +} + +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; +} + +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; + u32 snd_sne; + u32 snd_sne_seq; + u32 rcv_sne; + u32 rcv_sne_seq; + 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..2bcda91462c8 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 # 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