From patchwork Mon Apr 3 21:34:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 78774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2602885vqo; Mon, 3 Apr 2023 14:47:53 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJzo2rx690hSHf1L4vZDcs7lrswnUGPBhWKR+wbCrzZa+yBAzsznBvvUTCXXq+FyBKIQD0 X-Received: by 2002:a17:907:c789:b0:8b1:7fa:6588 with SMTP id tz9-20020a170907c78900b008b107fa6588mr130762ejc.12.1680558472977; Mon, 03 Apr 2023 14:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680558472; cv=none; d=google.com; s=arc-20160816; b=cTFDkPI4FQ8MmjZIaFwsQmtrPSBDPK7nhPaRwOUsYR1ysN/+omrqQm5GZ+LIyKEDRC hk7V8pY3NOWPy0UI1eDDEnoruyv5ifJiOFPQ+R9bXjCjeIcDqOaqAH8FS/l4MMKNdE3I 3bVDrLUY0w4iGpc75CRCdrJ6ziCTbgRo86N2liHYfHcfEneO6w5FYKaYJ9Ij/g9Z/aUp gbtcjHAZ8pohL4XZBVtvGsDlCaADA6EUsJJakyR9iscyNOoipXSCROW6T8fzGcIMvHvF 8kNDN297v0QasAw/4xiSSeGC1FC++OcvKReGCk8c2Fl6OF+JmDWCbKFxkhnAXvUzJZaZ MS3g== 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=kQA9a3ZeayisGBzT8fhn5X49xOz5ia7I/tP/67NAQZc=; b=GZ6t9USTDQnhLsMYW1BIMIywRnaspCFxTyXwrMXir9FONa9UfQXpoPxzkuRINdzSfh 2qLflOrqLabNI4KL8bkhyzQS0hIbK1aGNdyjgnYTuXdxcArqixXuRQIMdPcNm+b3fEvt ua7tH/7lJM9s44+ZgujNn8vBoDbRvGBZlTWsR/eiAf4n+Xuoi/qiH7YDSrHM0fRKViYU RHmf48uFNBzj2Y6W/QkcC3dTx2i5lW/IdOHS1D4Q3KSzj1BT2uK9YH5S/2Z6wt7W/wwp jHPlR7GczgiXwKW9hIZmmHpwgI04gwoaBbtKc9Zg5hrvidQOTy2D9vAZ8XJQ0pxIK1IO EiiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=WSzUbnas; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o13-20020a17090608cd00b0093c96e490a8si8272977eje.202.2023.04.03.14.47.27; Mon, 03 Apr 2023 14:47:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=WSzUbnas; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbjDCVhO (ORCPT + 99 others); Mon, 3 Apr 2023 17:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbjDCVgE (ORCPT ); Mon, 3 Apr 2023 17:36:04 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FF5C2D60 for ; Mon, 3 Apr 2023 14:34:52 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id hg25-20020a05600c539900b003f05a99a841so971080wmb.3 for ; Mon, 03 Apr 2023 14:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1680557690; 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=kQA9a3ZeayisGBzT8fhn5X49xOz5ia7I/tP/67NAQZc=; b=WSzUbnasHaUCCyvcJgAXMRCqnSDtsi/u+Di2nN3K7GLHE+EbMsHbGfc8vTn4pKaqQL maMag0CeHrobXwaE2DEBV7+FAhSa9lhdlwtCuhqb4hBSPZ6IbyHwbtV6H2Ccb5Mpcbwr FLuFoAMxXLMVZQ0Y97P5XbGN1znIAbAhM4oeNku4jj0BehFLzsfjZOUzZe6u+Ov+Dr4o kqm12ywJU56MCYYIq5//Ltcz14jB+gpzXtbBFeirFdSseHxb844VqUs1Vmd7NLA8Vbgb DX5pTV0E9wZ/igBv03dOdmI+9zaSwK4m184PsA1KTsh3AArBaaTMzvpdCpEGQ6Gfo1cS YLTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680557690; 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=kQA9a3ZeayisGBzT8fhn5X49xOz5ia7I/tP/67NAQZc=; b=nnmtDEHJ2HxhLpFJpr6PjEaRhuRHsmfxPvlhxyCQHxrTEXN4LijX8azi8kO4FdgEM9 99/1htvyjO6dHnn17qPXIYGx8Yy7LK1ntMwKT2gtZpjL9lWdEiR687vFTbpaRwUPnEAt 4fRVHQd+sNY6Gz8swsSy+gyJwCtyCJWy+s+yvXIMjlIhkHZv3ne21mpCkfIIaFiFcQgz IZSJzbYtv6Iq7KlwvZzPZ8BssOZJGsjKKmrcQlTj7EUSB5I+nVQQPVQU9lTTU0DDclst 0s3BVOlC4Z+G0Ll1V6qZ0kFwB8BKJDmOTrzvK/JrI/ymwQJnGNWCEON6t6QZXMm6n0S1 sMFA== X-Gm-Message-State: AAQBX9eVhbqBhJBnv2VyqAkQ3MU3GB6QOwImGEKN8yLAyv+C0Y/n1j8n 44hM64340YrI6y1W8nAoVWaeQ6Jxn28J11xO88o= X-Received: by 2002:a05:600c:2259:b0:3ed:b4e8:630f with SMTP id a25-20020a05600c225900b003edb4e8630fmr555639wmm.10.1680557690749; Mon, 03 Apr 2023 14:34:50 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id o5-20020a5d4a85000000b002c3f9404c45sm10682740wrq.7.2023.04.03.14.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 14:34:50 -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, Francesco Ruggeri Subject: [PATCH v5 17/21] net/tcp: Add option for TCP-AO to (not) hash header Date: Mon, 3 Apr 2023 22:34:16 +0100 Message-Id: <20230403213420.1576559-18-dima@arista.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403213420.1576559-1-dima@arista.com> References: <20230403213420.1576559-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762193281394110009?= X-GMAIL-MSGID: =?utf-8?q?1762193281394110009?= 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 32c4cf2efb8f..0550bc0fe09d 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)) @@ -1345,7 +1347,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)