From patchwork Mon Oct 9 23:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 13414624 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31034450FA for ; Mon, 9 Oct 2023 23:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="eLWWIyF0" 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 8B580F2 for ; Mon, 9 Oct 2023 16:08:03 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-405524e6768so49282965e9.2 for ; Mon, 09 Oct 2023 16:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1696892875; x=1697497675; 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=/kek+IpSSyHROs5GlGdGf6GIiZ0a+NpAchKDoFinfg8=; b=eLWWIyF0rUTpyZyuypZd1D6eCFlkN3EcB1eK0Kx/zLqspqgDQQ9CjQmchZSM4rlW+e 0b+1jtfDM3KdN+ZuV+uCvGuqR8az4r2S1waomiqZYFj/u9lcqJM9VCXyc4OBnzDKNfa5 suhYbf8JZ28qqWCvyxtjbcC3rmqIHQDUNiAyYn6JgBM/S4JjkEGSeUNzGC6UkjS+lZr7 Zp7RF7R6laG8YEEta4m21qWM/XdAH8SD5yzqV2KOlLZ13ysdBM9Vq4Xed38Nq/aMDuaV /KZlkblrIhiYrGUxk5q/vT/yBPjsYKOuPfgoDtFbB2AbVxjZHmgu6/wq356HjWq6pygc ZEOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696892875; x=1697497675; 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=/kek+IpSSyHROs5GlGdGf6GIiZ0a+NpAchKDoFinfg8=; b=i3cSXKp6Ux9t92oWQwhxAfbYyN3RJRJ9uNS5X3k+Hib+mBSUUPTuzs3YebPyucEx8k Lzbo6Dla5RC3jlh66I684J3M9agK84cOZMHCa9IYwlp6sKYe8lxRlkdvuXQEWANqH4Pa 0k0FwxhNVRFLzTWYyYncwSppnUJOA35rnpj+Yv7vyn2dE7edvWUZCdJkXFdFOXuf65Fz Lg00BMw7kLw3rR6ToifVDdrOiUHNraFYgqhrGZtXbx114/6iUvOFpNcQnzgCMMg70cKc Rkd6RdXDKXPBMEfVI+FiaCwCvYG/GQ/eTup84MhGJmOWVMxXsa+fJommoWl0o1wlOjxq NcwA== X-Gm-Message-State: AOJu0Yx7yTgureIneAorwSNnYS96AZJkqjJBT2Ahhv2yfXjq5L5/NzPq UBSfwEAoHXYPKqGRszAx3pY9gQ== X-Google-Smtp-Source: AGHT+IFrCNE705rbVSkpHm76RyBzhf6csKxrkisUJd/QU4YwC3BWk/1ChJOpHJDaBXet3e8UkiF13w== X-Received: by 2002:a05:600c:21d1:b0:405:1c14:9227 with SMTP id x17-20020a05600c21d100b004051c149227mr14926186wmj.33.1696892875624; Mon, 09 Oct 2023 16:07:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:07:55 -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 17/23] net/tcp: Add option for TCP-AO to (not) hash header Date: Tue, 10 Oct 2023 00:07:08 +0100 Message-ID: <20231009230722.76268-18-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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Provide setsockopt() key flag that makes TCP-AO exclude hashing TCP header for peers that match the key. This is needed for interraction with middleboxes that may change TCP options, see RFC5925 (9.2). 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/uapi/linux/tcp.h | 5 +++++ net/ipv4/tcp_ao.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index e4ddca6178ca..7b9762ab4df8 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -366,6 +366,11 @@ struct tcp_diag_md5sig { #define TCP_AO_MAXKEYLEN 80 #define TCP_AO_KEYF_IFINDEX (1 << 0) /* L3 ifindex for VRF */ +#define TCP_AO_KEYF_EXCLUDE_OPT (1 << 1) /* "Indicates whether TCP + * options other than TCP-AO + * are included in the MAC + * calculation" + */ struct tcp_ao_add { /* setsockopt(TCP_AO_ADD_KEY) */ struct __kernel_sockaddr_storage addr; /* peer's address for the key */ diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c index 168073cd1c89..ba13e85fcabd 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -562,7 +562,8 @@ int tcp_ao_hash_hdr(unsigned short int family, char *ao_hash, WARN_ON_ONCE(1); goto clear_hash; } - if (tcp_ao_hash_header(&hp, th, false, + if (tcp_ao_hash_header(&hp, th, + !!(key->keyflags & TCP_AO_KEYF_EXCLUDE_OPT), ao_hash, hash_offset, tcp_ao_maclen(key))) goto clear_hash; ahash_request_set_crypt(hp.req, NULL, hash_buf, 0); @@ -610,7 +611,8 @@ int tcp_ao_hash_skb(unsigned short int family, goto clear_hash; if (tcp_ao_hash_pseudoheader(family, sk, skb, &hp, skb->len)) goto clear_hash; - if (tcp_ao_hash_header(&hp, th, false, + if (tcp_ao_hash_header(&hp, th, + !!(key->keyflags & TCP_AO_KEYF_EXCLUDE_OPT), ao_hash, hash_offset, tcp_ao_maclen(key))) goto clear_hash; if (tcp_sigpool_hash_skb_data(&hp, skb, th->doff << 2)) @@ -1451,7 +1453,7 @@ static struct tcp_ao_info *setsockopt_ao_info(struct sock *sk) return ERR_PTR(-ESOCKTNOSUPPORT); } -#define TCP_AO_KEYF_ALL (0) +#define TCP_AO_KEYF_ALL (TCP_AO_KEYF_EXCLUDE_OPT) static struct tcp_ao_key *tcp_ao_key_alloc(struct sock *sk, struct tcp_ao_add *cmd)