From patchwork Mon Oct 9 23:06:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 150382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2167257vqo; Mon, 9 Oct 2023 16:07:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG8PdVWGmr5IWnUYYUy1tce6SpEKxz6b0FCW4I0JR+AAITCqJwW+nSl5Rh4qXfcrtrJfMP X-Received: by 2002:a17:903:509:b0:1bf:557c:5a2c with SMTP id jn9-20020a170903050900b001bf557c5a2cmr13490731plb.44.1696892865738; Mon, 09 Oct 2023 16:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696892865; cv=none; d=google.com; s=arc-20160816; b=PCwe9w8R5E0e0e3lH3Fu8mXLlGfBltrYqWyxdnFDzzuq98yKQqdEUorBegpzWIIjwd 8X5adWXkg9I7AIkKJZ3j/O/xmGfzBJQSodg8eUJHaPWttelXjZ6GLrnYqlTkyi++jtn4 qt6PmyiG3gtirM46fGnURf1KF4g54Bd7nwL0xSnLJRtsPNZzZ0diPW92eguJVoxguQJ5 rQwns8bAqJWszoqUGXLOkYBpnkyBfaqqSoJjuNXVRuOf+MiIrNmPRodM5neghLpOz++o tHcu7XKz+kh+00afInUSCiZCudUzHUDlXFVadW8z3QMMOZNwupNYP27NeIePGoTNTCMw E6jA== 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=tQCf3/Z7DYHirLRKcl30B+T1/fH3iao/Y8idxKYx3gU=; fh=58X8Twod/aefd4Yph/F0FPyIOMSYi96Sqi5HmPAz0To=; b=O356i6micjWhnpPgK1b0Bmqju9zE1WS1cDA+BSvkeCQmFRw5REOu+uUDYBrT6hG8Vi bUR4CYPdQ1cf79DNeblK5OpY7Uc3RiIUglm1GjZhB2ToRWHa6tTeJFQkwVxjNKU6oETE 1O8JipBF+TW53AgDLYeTdMa+0EUOP67mMNrLVgvra2+58dy4wtwGhMJafzP0EMi3xWxt 1xBpsI3Y+82uglwvUo9dI/aG3ESIymMUPf+d2vkwNnWrhYYwoWE0dZqCvieeM2wR9f3i OBhiEWTxLTa5bUU66r8dKuIhQGVRoD53lcCS56xSA8bwCeaCDE05PNjHxesclNFN/D4A /6nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Fq04vv22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u3-20020a170902b28300b001b9ed021929si5115247plr.225.2023.10.09.16.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Fq04vv22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id E5568804DD8E; Mon, 9 Oct 2023 16:07:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378969AbjJIXHj (ORCPT + 19 others); Mon, 9 Oct 2023 19:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377234AbjJIXHg (ORCPT ); Mon, 9 Oct 2023 19:07:36 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B489A4 for ; Mon, 9 Oct 2023 16:07:34 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40535597f01so47796595e9.3 for ; Mon, 09 Oct 2023 16:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1696892852; x=1697497652; 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=tQCf3/Z7DYHirLRKcl30B+T1/fH3iao/Y8idxKYx3gU=; b=Fq04vv2265sOluYGCjnEOF2P0DHsh55RC9D6GwgJQHfSJZX9tqmYYFohiV7nlngsIU 8Nrom32jEm4ZkJSGN4KiAQdG6w/J7vNSwa9eLSfzNASKqOICP/ASx69owXs2WowcDDhV dnYbZvNCHzQPaX03pxT3DmNLZOFCS5iOHk7ec60nKBoftOevspCnoLB2kMSwIZ4/rWfa eJ8y/RApzo3pLNaJs1SozKlu+3xrou0g/de0E186HozfvvEavM9VENzwuUyTn7z7ZZ9v PzgiPrArKzVVDWPe8Hwt2TxzOj5pAtUpGLvGVVT2I6Coyv+ZJ9VSDJhj82Kdfp8ERox5 r+Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696892852; x=1697497652; 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=tQCf3/Z7DYHirLRKcl30B+T1/fH3iao/Y8idxKYx3gU=; b=Fdyl5ddyRcZ7SEhz8qQtp6Bu6Le8C+rA9j0+3CvGSJF6opqxBiVX2FfSk/LkTOLzfX ZHmaPeedbjq9TLEQ1BXpfmKNN9b0tL0nNtc9O+gglGWoe3TXZDSwnBSkqU6Hkh3BusVS Fci/h4VQZP85yvATRq+1qAcuWHYmVzhVz0IEkS5W1hVDcpo4UMNDsqSEeolAvq+YDN0d B32Ep0wiVKfhZ0mj0ZLXydV+nr8RHd+fyVjNDUG+N71aEIcEdj33auWaCJWZ2L6R7N31 qFsJN5Stj3SUEA08D0z9GdUV6w7zpqXFPw05LczQiP7hTFt5fjayes8ERWv8pTb8it7x 5HOg== X-Gm-Message-State: AOJu0Yy6PJ3op0ABmT/dgbukaL8oLqonnk/oIuzYEFCEiYEMQIYTBRTf g8Qy+JwJmV6A5udc2M3xir0ZzQ== X-Received: by 2002:a1c:4b11:0:b0:405:3455:e1a3 with SMTP id y17-20020a1c4b11000000b004053455e1a3mr15383230wma.17.1696892852708; Mon, 09 Oct 2023 16:07:32 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id t24-20020a7bc3d8000000b004042dbb8925sm14592104wmj.38.2023.10.09.16.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:07:32 -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 v14 net-next 02/23] net/tcp: Add TCP-AO config and structures Date: Tue, 10 Oct 2023 00:06:53 +0100 Message-ID: <20231009230722.76268-3-dima@arista.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231009230722.76268-1-dima@arista.com> References: <20231009230722.76268-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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 16:07:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779321133753919203 X-GMAIL-MSGID: 1779321133753919203 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 e15452df9804..c38778b0baa0 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -445,13 +445,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 db25175c19c7..b384fbcf1628 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1654,12 +1655,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 d1d08da6331a..bf93a80809d6 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -360,6 +360,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