From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5283C77B7F for ; Fri, 12 May 2023 20:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239470AbjELUYu (ORCPT ); Fri, 12 May 2023 16:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238982AbjELUXp (ORCPT ); Fri, 12 May 2023 16:23:45 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E4F86BE for ; Fri, 12 May 2023 13:23:44 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-30626f4d74aso6817934f8f.0 for ; Fri, 12 May 2023 13:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1683923022; x=1686515022; 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=tDKxu7Q3BnVyZ56o/a9J4JKFOGYoGaGixVIZp1vuIS4=; b=LQ2Gz7RYkZ5dYj/IN8jUZJcUuipI+jiIy8BN50xXxIYdsaP0hY0SVBpA5R8OMXmZa0 4ySCC5oC+NPwTFSQDb1IyIvgsoJ1z76Klit4oz6LK742Vnm1J8D/1BBQQdzdt0eRitaC pMscTQ8as51JxRy9pN0DHumYFpyfrDW2LiOvC9gva9zEaVPi3UC9UVIUdSBoSc0yAFYq Z6PzE37wxxfDx86fC7eRTGShF7BSSM1acmg1VKqYm7YU/hVtWthIOIy4bRCzAN7lfqFy iGJ2kK4cWX0nPfndKtPj2RqJG8pzjEcNC8+sDbPJSMaKYlaACPOKxvKbExFtcZhh14Fz ZvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683923022; x=1686515022; 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=tDKxu7Q3BnVyZ56o/a9J4JKFOGYoGaGixVIZp1vuIS4=; b=ATsf4xP1lgHiIpJ+cSsPJY466BYdqvnmYv49nTZ2Zz+TAOZ94sI0FdeqxMXfFjq6yZ n+B8pcUywbIxpiXOrkdY1jklSYwKoS8EhptyVKLq2YCRBM+Qop+iz3fC2ZEg9SFJWCsQ kpCln8CPOpBrY7oZvxfawCQ0ISfiv79V4ISCxYZs7VDSvhc5CR//x6HkQdNHN005A/MC Z6phV5CjCVeSBzaU+RrffmmONoHgqaZRY8agvgW1w3QRMuvUCLFwxdI8biu/cQW84rMr NQ4Rg72qgXOxiqoG9NxE5Jxz3QiGb2kLmXHbefYBnXega8JheDUtNjK15y/E6ioUaeVE Ydpw== X-Gm-Message-State: AC+VfDzrI/MhEcX8bcwcEKRZHUWTMlneFQ+XenXLw0mIAU50CUHOmNTy Br6oTC5VGa3te10ZjpC93TCjuECRP+bVoMpdcUo= X-Google-Smtp-Source: ACHHUZ7hNI1VFax5WAmBbyhkyQ/JW/ECwHYwfan16j+e9IJZKkPnDnHsoKL2lXPDwjufURngofhaWw== X-Received: by 2002:a5d:440a:0:b0:306:2b5f:8d0a with SMTP id z10-20020a5d440a000000b003062b5f8d0amr17626411wrq.56.1683923022689; Fri, 12 May 2023 13:23:42 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n9-20020a05600c294900b003f423508c6bsm17304527wmd.44.2023.05.12.13.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:23:42 -0700 (PDT) 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 Subject: [PATCH v6 17/21] net/tcp: Add option for TCP-AO to (not) hash header Date: Fri, 12 May 2023 21:23:07 +0100 Message-Id: <20230512202311.2845526-18-dima@arista.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230512202311.2845526-1-dima@arista.com> References: <20230512202311.2845526-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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 ca7ed18ce67b..3275ade3293a 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -354,6 +354,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 fdba3e1c80cc..890f48a97490 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -566,7 +566,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, tmp_hash, 0); @@ -609,7 +610,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)) @@ -1339,7 +1341,7 @@ static inline int tcp_ao_verify_ipv6(struct sock *sk, struct tcp_ao_add *cmd, } #endif -#define TCP_AO_KEYF_ALL (0) +#define TCP_AO_KEYF_ALL (TCP_AO_KEYF_EXCLUDE_OPT) static int tcp_ao_add_cmd(struct sock *sk, unsigned short int family, sockptr_t optval, int optlen) -- 2.40.0