From patchwork Wed Feb 15 18:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 57655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp354775wrn; Wed, 15 Feb 2023 10:39:07 -0800 (PST) X-Google-Smtp-Source: AK7set874kCut8ovJKkAvsVcAxs2YcSdizovjS7tMopXMWUAOsc/UEn7pbimjDgmvDzifMG9XaLM X-Received: by 2002:a17:907:f93:b0:8b1:7fa:ba22 with SMTP id kb19-20020a1709070f9300b008b107faba22mr3754101ejc.27.1676486347601; Wed, 15 Feb 2023 10:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676486347; cv=none; d=google.com; s=arc-20160816; b=lN0xNRx7UVPBVqccGKze7bXtlQKnkgM22s3op5/c3SLKml+9jZs0kasA0PoefV1P79 pcnyOeZZHf4JJxDydfgEvC/Jt6eDk2kHDV3TVTUkxaCTxmzQeoQHqEPtY561eAuFRD3Y FGYSfm5DB1mL8B1sFon3/ct33nXLoZuwT8Rxr1VsJClJzQK4NBqvXt4BjHmp4gjecHUE 6aNnSBxy/GHi/m2+iMc/kO42DtkzE0gZQauoLbuZa23pxsyCVLogupZh8XX/wFWX5cSD YPLZTi+rL8hlfxBAaL0pMyy8BZrq0y56xD6HjDqp11cvRuxj9eaXPE7nyN9aLmfSHcBf p9tw== 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=e9pks7/AIVF620Cp0OiOwRGXcuPgKxA3s+/9rsq6ezA=; b=dHJ4wLDm4FtNJj+BjUtPaTQbxDGK7bFrMo8KzmNCjp/dZhZOIKGbByUPudjSKVe+6b elvoVs+hkLIY8VMZ+08wLPEWsoUHyF/DMiiVcP1w/8XgewUnep8q6BGlJFkR7OXeyOZp 09hsE2BiVieBfFsSIyUQSExOP63UXO7eUOI4Vl6g3lrjG3eSNSIeafawQALQy7Ez0qtV dYk8RbnkzVvM5snbP6L3qJGu7lnnB8S/ap9yNjIu0fI5DH2Kv3VEoauHxH3rsfyE0KG4 NeellJj3DCK27HzzTx5gRW502hO5nUu/ShO/5dMB4KAbpz7tcEKH1s7cPGX982HOsqsR 9w+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=BYwUZEH9; 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 et19-20020a170907295300b008af3fd67d4bsi17522125ejc.651.2023.02.15.10.38.43; Wed, 15 Feb 2023 10:39:07 -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=BYwUZEH9; 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 S230212AbjBOSeX (ORCPT + 99 others); Wed, 15 Feb 2023 13:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbjBOSdz (ORCPT ); Wed, 15 Feb 2023 13:33:55 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB013A865 for ; Wed, 15 Feb 2023 10:33:48 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id he5so6199582wmb.3 for ; Wed, 15 Feb 2023 10:33:48 -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=e9pks7/AIVF620Cp0OiOwRGXcuPgKxA3s+/9rsq6ezA=; b=BYwUZEH9SkgOKulUPV2icH/2v6TruPfxPoFvMNm4CtyUZdcyvWLLTK2ADMchVLgatB 3tGFdRMceJi2GWFTOzIumlau/HdtmHjqOPmU9NHZY3kQK1lP/jBsE88pDzdz6bmh9dbx Bvw24VxIzKo8dK8hUHq6NsTP8CRmOSUxImjNaizeV4NeXWRKGJUqZEQDHMmREdfEs15o mI0WoqtqDQngRBWTfig1X1zh3Q5KiKYMDCp7n5oIOBMCRlphBwzGJXiyXrOK0FwZS6Jl v75cWDFUwlFMj/h1Wz9rlStwOXkCPcK0BOes1SnpygPhBIZ6VIJ1ESrRDjFekc1dFcmA dllg== 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=e9pks7/AIVF620Cp0OiOwRGXcuPgKxA3s+/9rsq6ezA=; b=G5RF8CSI28w0nhiLPnizS2pWzNAAxTMxBadc+yWP37yk3UGFQLu1/JDW469BRkJ/+f bkZnZcifzXso7bE/uQjqeRNY5XZHSMjlIHVnUldIORQvoyahzMqbgwPZ3dlTquBcPo2b T4L/AcoMGGIkUYi9fp1jWOTcesd0mQYnhH26Ov+ghZ+HjNK5j9+j6qgyGEI7vU4f2YKj +cAvL8/rMyZXFBrV8NAbb8cFNSYOzGG3UN10SjiqkOIYjgWhBHZP3hg+2VbfbP/ruPyb 6xajMlYpsLwX6pAA0pf1Q1TEHOjhj/95/v32KYgQwASo5oeSvTEe+hg6yETrA0UPEvwY /J/g== X-Gm-Message-State: AO0yUKXmMxd0EoMN8W3M9C9DOgvbc1rWlBQzkBSPWCClt0qYkDwvOKxC XAjdOQjLtNXLwuKqp1yoypX1XB6S42IQA5Yx X-Received: by 2002:a05:600c:444b:b0:3dd:1c46:b92 with SMTP id v11-20020a05600c444b00b003dd1c460b92mr2871329wmn.16.1676486027071; Wed, 15 Feb 2023 10:33:47 -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.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 10:33:46 -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 02/21] tcp: Add TCP-AO config and structures Date: Wed, 15 Feb 2023 18:33:16 +0000 Message-Id: <20230215183335.800122-3-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?1757923348357319643?= X-GMAIL-MSGID: =?utf-8?q?1757923348357319643?= 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 | 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 ca7f05a130d2..ac742427bb39 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 e77080003800..2d9ca039edc7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1615,12 +1616,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..27d8b4abef22 --- /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_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 { + struct hlist_head head; + struct rcu_head rcu; + /* 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. + */ + struct tcp_ao_key *volatile current_key; + struct tcp_ao_key *rnext_key; + u8 ao_flags; + __be32 lisn; + __be32 risn; + u32 snd_sne; + u32 snd_sne_seq; + u32 rcv_sne; + u32 rcv_sne_seq; +}; + +#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