Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2524368rdb; Tue, 12 Sep 2023 04:55:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk3zJw7ui9uEiZcH2ojh1FSiTmeSP0aaF+ZAnQdH1VR8mls0uFWTrLIvD834jkoRHop6gT X-Received: by 2002:a05:6a00:1896:b0:68f:a92a:8509 with SMTP id x22-20020a056a00189600b0068fa92a8509mr3607808pfh.7.1694519744749; Tue, 12 Sep 2023 04:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694519744; cv=none; d=google.com; s=arc-20160816; b=RX3ouiTJWmVBuMtUIJYn3TyaHDvqGgR61KMBUk10cq+b/dbYwwM/7UNjiYLMHDmUlg H9HBtWC9d0B/jiEfWbjTmHsGarnznVLAVHAMkl/Wh1Lj5RF0N4FUHbm2PpMhTuEJ1Th/ fUQkJHjUsbK8iMsEWPI1QKbpwcjR1RoCOLSNteiMwHfXHE/jSsAgfRyAc3yFmBtyWD97 YfyYkenF2czuSpXL5qZzDU2vQmIsnCTjpg/D+DlVxRjcC4+TopZivhS60zY3et+pxvK7 qrVjzhkexSe9su8UqQrgHVccOHjaxaW+FpZ5kYZ2A95f51OgWB/CVpOKr6lWVNvRqFgq vbgQ== 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=GxcjFGD+jaDNbQ3HetMsY1czDUww95WsTPfCc1TTmj0=; fh=58X8Twod/aefd4Yph/F0FPyIOMSYi96Sqi5HmPAz0To=; b=g7nSk7NUNlm9oKHpjVFwqm1lMjGl2lZAQRJsL9qkJ7zbfkkinlk/PrNnJtCTchWjFS RvphYc8Kpb8wXfW40fN200I0pt+KuAkEe6qe2zvqpU2/W9FnDSV/emenX60Q0bDMo/Az aOEeu+5rqNoApfw+IUMMEn6Dkv7bfVCF3AsTxqpV9WGThlT24icHZq6wqercuoAEiNfa 73+fuhUKPAtugRwdGOwAX0ESW93MsiP0VLyiGvellpo3A5V659eYkYTNK2TlR9L/P7IJ ZxqBrhiJzwlX9dPpnSQmL0jXmcDfKUYBbhh2BWULO28m6bcTwiPeL8Bz0kMVz+rBCT0P Btww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=gKmBQvdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n67-20020a632746000000b0056a750ed799si7824778pgn.239.2023.09.12.04.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 04:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=gKmBQvdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 D1219831DBE4; Mon, 11 Sep 2023 21:30:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241173AbjILC5i (ORCPT + 99 others); Mon, 11 Sep 2023 22:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241174AbjILC5R (ORCPT ); Mon, 11 Sep 2023 22:57:17 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B63F16090 for ; Mon, 11 Sep 2023 18:24:35 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-9a9d82d73f9so626578966b.3 for ; Mon, 11 Sep 2023 18:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1694481874; x=1695086674; 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=GxcjFGD+jaDNbQ3HetMsY1czDUww95WsTPfCc1TTmj0=; b=gKmBQvdz2vrNNijATMJPTIdLUkoClsnnmF7skv2NrVIgHxiQrlMhb1sumsgg2bPfKx cVsBz+SPHG+SruLicqMgyLU77fcflZU42Gw4j53IqpJKqLAE1q5gv++w3FbC7/cH3Jch 4IecU846pQIJYCpQEO+jbYtY9zMnP5hUE9zEDTv66BC+a79pGKue5TFluQOIJ3M8F9vq 4dW+6eFpI79Kq4j2cg4clEpanbgikkNLWOy0ld+5AL3BFMwKyEMTQ08m35hCKdIK9xcc L2muArB3zSliPIzCb5LAQQAj1DKmm/kLmqa/DpNdDcH54YkiS+8LA625C0aa2OPC4VxU rAWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694481874; x=1695086674; 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=GxcjFGD+jaDNbQ3HetMsY1czDUww95WsTPfCc1TTmj0=; b=NEeawl8tMIalKWoGdwMGhxqhuNaCuyaRlvE2kH6dfqdnXBGChjAW7q9BHXn+hwqHBO N+fWj+hOzKpYueZq5GpFactq7USV0HHwAMargQ6wUo9dFkQBbmTXPWBtcaua0rT0/wNn e+iHAKE7SkxfUnWfMP1pV0AEUcVz3I2GEJ3qazbOv9AsqI4yuocAPs2xnvt3XOZ8Cd2w YkjW9g/u5y7cHJbGIiyecIwwedmHtD0ermSQfihZNXFBTgzI12nX46XKP/dfEtqOGN2q XSrJp91czOISj1KfOSDxt4aluAqNv6fWwirUcooHUs+InX0WhShPyB0/JvRbOOb3wani qr1g== X-Gm-Message-State: AOJu0YxWy15dNtl9Nj7Og0YxSwOwyJ1u/mVL6qvfip2BQRovwxjSQ/4A OTxidKk4XEXC4iIJIF3kvB9A2WSFWbufZCMbk1U= X-Received: by 2002:a05:600c:2116:b0:3fb:b008:2003 with SMTP id u22-20020a05600c211600b003fbb0082003mr9221692wml.38.1694466238094; Mon, 11 Sep 2023 14:03:58 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id z20-20020a1c4c14000000b00402e942561fsm14261699wmf.38.2023.09.11.14.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 14:03:57 -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 v11 net-next 02/23] net/tcp: Add TCP-AO config and structures Date: Mon, 11 Sep 2023 22:03:22 +0100 Message-ID: <20230911210346.301750-3-dima@arista.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911210346.301750-1-dima@arista.com> References: <20230911210346.301750-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, 11 Sep 2023 21:30:06 -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 3c5efeeb024f..fc98c7d63360 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 cb8fadde8c5c..cd93b2aa88c8 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1650,12 +1651,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 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