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: 150397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2168400vqo; Mon, 9 Oct 2023 16:10:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNIyo2cIVop4i8XlpparQWSI43PhHE468nSTk5HMfpL8lmj/kwxbYohqnOYxTeMWt9pwAF X-Received: by 2002:a17:90a:2a08:b0:262:fc8a:ed1 with SMTP id i8-20020a17090a2a0800b00262fc8a0ed1mr14972766pjd.44.1696893016175; Mon, 09 Oct 2023 16:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696893016; cv=none; d=google.com; s=arc-20160816; b=yP6MzgjS9X4aS1KOp/PXZ2B6DCWaMUpcKgmOJUpGFAyvye8XXtqW+Be5F8Axc5E8/D YopVOmyJpBEJ+3hGsovSEWdDCxGAJzXh4QCNGaJwG+gh5amBpGy8/XBcbXCQeLdGbtU4 oxd6QRjpkvvxwCq8W79XkWKUUqh1nOq72D9IeRmXU2o2MAd0N9ZIOgOwwBZJcaaMJyy+ MOeCgetwTA54jHso4lEy60JL9heP1HONlNrDW4z+iuxPpQI7k3IojWcW/rIfiIDeWX4C P5Sh2MYupq0XVxXk0MKGkS0ehzsPwvaMw+a4a9DKsFYIk99TOk8TWqdfbv2jvfhqpzSa UQ7g== 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=/kek+IpSSyHROs5GlGdGf6GIiZ0a+NpAchKDoFinfg8=; fh=58X8Twod/aefd4Yph/F0FPyIOMSYi96Sqi5HmPAz0To=; b=zpWI4PMeLlmEbcRgdswyvM4zoqbyfZ3t+fwPFbIGw/Z2qDcrl0Ze+vycCJ32YsRRGw cdJnMfeDFI7xPc4PUfkgLgBHgaspFBmfAwxZ7kVSj85XZFwP+3rrL0AWwduzCF7yS20J lO3KeWkIU1TVtIo+Neb4a/Gxw4xKcn9S49c1ZT7AnDEpEvtq/cVboJHszbdIRhjL3cNF knD3JGnoPGozGT5D8VgHXjk7bRFfcXllqGp+DgKJiRjTR1Ts+0jCcYAP7NB0FOXYqO9w lzcI0rzFqpzhK3OOLz9gNn/O/iWdTtqInGT1GDeKmbAla+lOybheWlT8ZN9E/XFvQimG E0Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=eLWWIyF0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ot8-20020a17090b3b4800b0026b71fdd505si11649723pjb.177.2023.10.09.16.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=eLWWIyF0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id DB22480BA427; Mon, 9 Oct 2023 16:10:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379112AbjJIXJV (ORCPT + 19 others); Mon, 9 Oct 2023 19:09:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379151AbjJIXI5 (ORCPT ); Mon, 9 Oct 2023 19:08:57 -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 27A02FC for ; Mon, 9 Oct 2023 16:08:03 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-406618d0992so49457665e9.0 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=j544sCpXKmPRnZPDl2Dbiz+kOOrHIJ3L0ghggI+RJ5pQqdjxWaBtfYKDeJHIq6b6zH KeMeizqY+C0A8XXAXmTLRV9JhgTNIbpCDLZeiAP/RDmqA1M24LgQuyA5kXoPads2nXU6 Wt4XpoIUI53MNy/vgmL7rTsFomnWehGsHlxPigED9Ypv7auoKMut3gkcm2PGc6ycHYOR CnMTGRxx3+ViIQLAw/A1ojAFsQXLqT9uIbaU3seJET3L/XtAOTvxt1hnvSDdiLdZSAaW L5Js0+fr+7SPV7t1O2R5QDgUhO5Sep7k91Md9xykAGOdOFsNY8WahhswmzLlvpLjSQmE u2Xw== X-Gm-Message-State: AOJu0Ywll9x2COUFvrfFN/VxuedsRfZoILIE/q9mscA7xCqKGNNS36GI V4AFz4T+Tse1EWFFIblFYqbDhg== 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> MIME-Version: 1.0 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Mon, 09 Oct 2023 16:10:00 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779321291626893062 X-GMAIL-MSGID: 1779321291626893062 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)