From patchwork Mon Sep 18 19:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 141565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2935708vqi; Mon, 18 Sep 2023 13:32:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX6acbnt/n9hF8dO9oba2pg7sSwoy9PnOtKP2L5cDxJxccUk+GalAlhBswax3LtLE1Z8gY X-Received: by 2002:a17:903:234e:b0:1bf:c59:c944 with SMTP id c14-20020a170903234e00b001bf0c59c944mr10185713plh.22.1695069131283; Mon, 18 Sep 2023 13:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695069131; cv=none; d=google.com; s=arc-20160816; b=EKml3fUxwHEHLDXi6v5GFrmqIWwzDEaiuhc+qTaniDkfoyr69Q24BpLV0QtvNXlBl2 IGD1I4ckoJtYiv60AZHfodfYhjcbEX7FIeIMs1Wmx8QH4y99pYNDC5jgSTIRp4qjlY65 mYZ7Dj/rC809WlBaoxbf48sQJEAy5bWPS34xBoZSX9uJLnKXIfm7QRARPluTRUezJ8U5 epLC/Ts58pFMF6LhEZEhqK8I4bdhnlgL/AuuQ+SVNtT2hRX8/XantD/HkOeMroYeYlmr wVR0Xy8wFx/z07HeT5nK8gzHD/ykWhqtWfm8neWzq7pciK1i0rKnanfOENAboHkrkQ0v /feg== 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=EAvLANZVcBxI8K7JhIBl+yn9RfzdE+WIR2gbxPUGz7U=; fh=58X8Twod/aefd4Yph/F0FPyIOMSYi96Sqi5HmPAz0To=; b=Vksn9+BPda9vN4CIUm0LswU2a4x71+EnyVy0tk4jK1ofMjmBXAo7ZjwPePrnwwmNni dgT3dekWhRUDEsAoz3O/47DgC5GOucz1j/9kydBnC9O+FZrDRSe5k3n9RGmqcB1vkVSs WcpeMVF7wu/4kNeKmTelZNlxmRxoMwzO2JjieebZUXRek5POMZeC9aKHxDD5F4e4YIZ9 bdD8TTsNGz+FAo9Ze6qQZhSIjum3tx0Z0/iCBkGPbHnIzxvysHp3m++0YxDP7fwrteCN JNIoipMGyXMCu3SvDr949N6pFHGBqtkIXp7c89Rq9DQU2/boEal/NycTeIglTxsRwO2H xzzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="PY/Nwegl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u9-20020a170903124900b001c33d33975esi8928725plh.133.2023.09.18.13.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 13:32:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="PY/Nwegl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 735E48024601; Mon, 18 Sep 2023 12:02:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjIRTCR (ORCPT + 25 others); Mon, 18 Sep 2023 15:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbjIRTBd (ORCPT ); Mon, 18 Sep 2023 15:01:33 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 696B8E50 for ; Mon, 18 Sep 2023 12:01:08 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3ff1c397405so52797805e9.3 for ; Mon, 18 Sep 2023 12:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1695063667; x=1695668467; 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=EAvLANZVcBxI8K7JhIBl+yn9RfzdE+WIR2gbxPUGz7U=; b=PY/NwegljIPPgGmpG69G8kQNZeFLZdLpyYq3ld/uJTtKHVMFoaFZSfBFOvmtasUOrn H2mcsJQNMeAel7y9spv0/tgLOHnpVT+vppkNMt1SEAQ21gTxDKbK09ouHbXekbJPCWX2 Wo9eNsDR+tBBcoZhmXKIeEwwYBhwuxS+z+WU14X7NAsgR/s4giP67XyNmmS9AbfPQgxH C3CC7wCdu1plnOg3fZ8kj1SwPrygMQ5ma4rY4H4GlGjEK+mpg8MQPOsmEuKiHkCOldOo jcWoqNahUFRGgyzTefTyHdU8yNcYG3Wvj4/2OQK8hsdaWBElVuFYQplMjJpikMRB0Ta9 yIzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695063667; x=1695668467; 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=EAvLANZVcBxI8K7JhIBl+yn9RfzdE+WIR2gbxPUGz7U=; b=WuT6nrbKjvhrBOdtyimk7oH1r1ifhVTeevIVGlKuhiFKXqMR+lT0BGUAhWEwXUVpJt yMpxDaXQjwP78t60oTAW5bKovRT7CMxs1RGPKVXVEWpBxBF+WU4f5sck6hOtK6YAvOxI khC0PDPwalLF2PV+ThOXVjCRi4K4gJnpi9p22r51UsCGBadUP+k/GzXA5ki0sUQ54vLB HgVUAZoFRpEcEc/FWozdJL+hJQIIJEsPEaoCh/27ElBCDqeLIMaJmDTUVcypbGtQv+bF IjemVAGT08RLlF67/rTWEO6C14cb5OJ7DnywK+sZ+Tx538EhGJV3wYeU3r0sr/Fe4QuD KbfA== X-Gm-Message-State: AOJu0YxM41R2mtN3U6wQhYh7CzluCR+5ZU+BDul0Kfzo1S39GsMAFc2Q rEfl3thBAo1AOwEGvf/LHjSvJw== X-Received: by 2002:a7b:cd06:0:b0:3fe:22a9:907 with SMTP id f6-20020a7bcd06000000b003fe22a90907mr8388960wmj.20.1695063667313; Mon, 18 Sep 2023 12:01:07 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n9-20020a05600c3b8900b004047ac770d1sm10762707wms.8.2023.09.18.12.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:01:06 -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 v12 net-next 17/23] net/tcp: Add option for TCP-AO to (not) hash header Date: Mon, 18 Sep 2023 20:00:15 +0100 Message-ID: <20230918190027.613430-18-dima@arista.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918190027.613430-1-dima@arista.com> References: <20230918190027.613430-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_BLOCKED,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 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 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 12:02:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777408809758488436 X-GMAIL-MSGID: 1777408809758488436 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 a8af93972ee5..ecbf2e217f29 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)) @@ -1403,7 +1405,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)