From patchwork Wed Oct 18 20:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 155158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp5063643vqb; Wed, 18 Oct 2023 14:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfYdqR6tMbz38zij/aojwa58zOZl3nrGlpzTYNQpWmKatXmljf1VKNEvi/AB1DN8FxvmTb X-Received: by 2002:a05:6358:c62a:b0:142:fd2b:d30c with SMTP id fd42-20020a056358c62a00b00142fd2bd30cmr128620rwb.23.1697662855872; Wed, 18 Oct 2023 14:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697662855; cv=none; d=google.com; s=arc-20160816; b=z8E6VeaSGkxEwZG6LX1TXDnr+zk47aT/2aQY45FD+41+ib43PaMAwj2L3/B7f0hy6d E/4sLrMrIJ1UpHUijZ3hyRLQHBPhLr6snzQWAAPB4WvIIE0g523SZvl88c7tItt8avAk 3hNshsGRjpvdDiTW/tpWcGib0Bz+AwGTUfUwSpp5RwdFDdTaS62KA+S0ajyi59+70yH+ tRGuvZ7h0NYKnLfpxBO6ht9gQrTA2/cwmfnH2fer6/UXngN/2p9vj1jMvqAN78E+lamk e7ufKSJ9FubbAteUWcnD3ZYwMDkppX7GC/WqUZUKrQM59Mmp6BtNJGZMuSoH5IueYHZL mfxg== 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=yQBllu3Ykjk7R9nnF+2uSCxMiVr14uA0qq+2C/piekk=; fh=a8JK1LlV6fjkJ2GExjvEHYBwBHtgXArNx6ms6Kac6b4=; b=h+l2g+IKB872XLtVXoXLhI4llOkB0enEGwxdyi8d8oxb/wpWwmla4UsI3AP51DFz9e 6MDWMEPq9vm6RpAjVb2Jy3i5SeZmZrzZpWmcaWfKUQHZ26xfA+nzoC2pVfimoT7tpX3R PlQlDpgquVKj4H8F1ZYqXVRVERVY4q3QJO5Wr9IIM3jqzYaaVLSBFqyKJkZL9jCsEvX9 LYgoxUMbHQBgVhtxILLlBUHifBwJFeuTEAOVK8QuB5IZVT5nOVbkFvAIPf9YtW2gMsHw R1uuEGA9ZdHFZxashlCjUHWBOkK2Xf9/YxzrS7ey2S5yqYVhH5k4cAKjEI5kpLJAs4cW WdVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="K/ByiLnr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id k77-20020a628450000000b0068e380c3654si4652216pfd.395.2023.10.18.14.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 14:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="K/ByiLnr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 81A3B80A7CF4; Wed, 18 Oct 2023 14:00:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbjJRU7s (ORCPT + 24 others); Wed, 18 Oct 2023 16:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344766AbjJRU7L (ORCPT ); Wed, 18 Oct 2023 16:59:11 -0400 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 C515AD7F for ; Wed, 18 Oct 2023 13:58:50 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4084095722aso6205335e9.1 for ; Wed, 18 Oct 2023 13:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1697662729; x=1698267529; 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=yQBllu3Ykjk7R9nnF+2uSCxMiVr14uA0qq+2C/piekk=; b=K/ByiLnrE4q8I6cyjNleXVcLHSHTNijuCgw/61AruP2K4Fd1N0IU7dy9L/jcbKaIDu 9fT0rFHyqcjw6HSkLpxUPUBEtc5195OOuEtAVKqWERHvZ1rtDamxBRphdGzlRvMK2QkK mpl/7fEzYzWnWyADdXe0aI3lt1hz2E18f6hRk60Xe33uDBo/K/7SkjzBlsRvkn1CzUWy OfITxcBUzlJNSpa6AeEwSZwfJ8iuKeKMjWFYqpFbeacW9dKuiApH1WuZFYZnSoSCJvoZ bUidtyva9qUsrLJcbX4OqQogCnO9gg6LzTM4IaeMO12sjX4TNJ87NZn/kc3Yp6ATfSk0 SNuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697662729; x=1698267529; 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=yQBllu3Ykjk7R9nnF+2uSCxMiVr14uA0qq+2C/piekk=; b=SYJbVNK0R+ZeQhPBdcYGOYoidSQ9zIuL2zEVu132Ou7DXBPkmzbZruLm41eTD4Wszf ScHhx/sLpQMPDZQjUtRq2DotuotgyBoXeqkjgxCuyvEahG2/Ru+qx1sSvgeBPDuHFW7W dIC4qRql/I/XUBllen4POK/k3Q4Vs6muPedNCAHrkbLUL9W9+msntcZ/4d88j9KA2hlr 63XM4O/SZ/FZvXy9I9mnlCndjD0a0eQwElpumKdjDs7TaJMwTHcfry1e5R/u+Fcxwao+ pJrBWBPLxSE9psNgQ5+H+fouBinFh9B40TC/+M3GPiLMy1nwPXjrT2Y8LVNFmoq/ZHFc MoqA== X-Gm-Message-State: AOJu0YxY630/CcoF9NyjFcFW7iDxo8R+aJh/W5p6sULbxD1pXRCwtRUR z1DfJuIikfwa/Z6DoQl1NmEnDQ== X-Received: by 2002:a05:600c:5254:b0:407:8e68:4a5b with SMTP id fc20-20020a05600c525400b004078e684a5bmr356636wmb.38.1697662728836; Wed, 18 Oct 2023 13:58:48 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id x19-20020a05600c421300b003fc16ee2864sm2569006wmh.48.2023.10.18.13.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:58:48 -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 v15 net-next 17/23] net/tcp: Add option for TCP-AO to (not) hash header Date: Wed, 18 Oct 2023 21:57:31 +0100 Message-ID: <20231018205806.322831-18-dima@arista.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231018205806.322831-1-dima@arista.com> References: <20231018205806.322831-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 14:00:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780128526851360741 X-GMAIL-MSGID: 1780128526851360741 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 223af5c9eaf3..10cc6be4d537 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)) @@ -1454,7 +1456,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)