From patchwork Tue May 9 22:16:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 91773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3205809vqo; Tue, 9 May 2023 15:18:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4k8hNKFir9dO29TdRumPGHaNHvbd02zO6loDaJiWusJfSHxnOSv7Rmy0vEul/dlWLEQLNc X-Received: by 2002:a05:6a20:394c:b0:ff:b564:c532 with SMTP id r12-20020a056a20394c00b000ffb564c532mr14812716pzg.43.1683670734682; Tue, 09 May 2023 15:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683670734; cv=none; d=google.com; s=arc-20160816; b=uMZIkIY8hbZexCyFcJ3Xy+VS1gMaxf32X9B5wAsjNQHjM8tDgHXLHGf/tNHEJ1q96P Af3dorxv+eZ1BsYmjbaod2g0ToeWqFFSrA+kw0UTRzs1lCIvEPykdKC6MPDtK8vmf+gi ZJ5j2a9fhVCgcyC3ISNhPiya9JgfO2kQXylNESM2pritlJ8hJn3+ylIryzTNWEV2qCKk dxgxkG/E3+ZHP3PTLOPHk4VS5yUDicdakXtbWdMQklRejBgCgFSrtVCmWu6Ud+hMOfLq 4tAJxcEkkfxr5KjS+2dfJhhvg5UkninK0P5ISf5p+CwCM5KFN3bV+LRmPyFkkat2yQmw vHbA== 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=TNaNVg3b0b9p/yqj32LHesflwoL6NjpvZvYZ6iwGQ4U=; b=IG/Wqz4QqBxdhZEUL6HcFDaEVlZr1nq5t8c4W0tPd5DA+oZZKOF6bPlbn0HN+f3ki3 OtqjhgRxsjQjqxMkbL2fHtVO/RAiQnulR8Orfbds6OcmDHxgXHF3J0BcajyrgHF0175z W4RCwbwxD11navvdpyLmWs7A00T7Y8lopUWvXXZ7OqKu+N4DfJhsv5BOR0TieRmgwbD7 SYuxAXRxy4O2Aimz2418JGdoVWUN55sDKR9Wg0iR5wnrI7f1Rb6InWGUIhdzohVlJgOp l4W3jf30o74SJuiJBKg0mU5k5Imzlq/gln5YU8zUEv/Gim45IiRseFJO61bpLckSpClJ tsBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="M7PTN/jP"; 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 z19-20020a63e113000000b0052c4fdb2c7fsi2456677pgh.635.2023.05.09.15.18.42; Tue, 09 May 2023 15:18:54 -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="M7PTN/jP"; 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 S235450AbjEIWQ1 (ORCPT + 99 others); Tue, 9 May 2023 18:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235134AbjEIWQV (ORCPT ); Tue, 9 May 2023 18:16:21 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918F63A91 for ; Tue, 9 May 2023 15:16:19 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f42c86543bso8570585e9.3 for ; Tue, 09 May 2023 15:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1683670578; x=1686262578; 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=TNaNVg3b0b9p/yqj32LHesflwoL6NjpvZvYZ6iwGQ4U=; b=M7PTN/jPtZaCbndrgKXB5fUCiuP/OVHWsN+jZdRGTMrM92yC/uBuA2QYkvFzTEhkgy a8lC+CIRThgZOMqbBUhknW9IB1HHR7iRUa64Eunab591Iahlk2tzjuEI5L4cDcYj4oA4 2JWmYcEBwsrPQE/8sTHxNUeBh3n618jO2ybsjbQdXiIeKcC5RNHNPK5Gn49bsx0BFGbv nyEdnlNxhDL2arE8+9mn41l+RC+anZPWyzKH8iAsyg/EPbD/YrHzxW8dqMtT+nX0BHYw ZYsQcxIt2tYSetXfh29BtDqXLzGEfSuhvtzL5WhBbV2wgKDUOaa123gVyZBNHGAQUyEf KCwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683670578; x=1686262578; 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=TNaNVg3b0b9p/yqj32LHesflwoL6NjpvZvYZ6iwGQ4U=; b=agoAmTuBqlkYjOhi8aOzIq3DQ29AKAfUFEEOHL7/Dg6BOTegCoVdap7wlBDB5T7DYD jEMDnN49Q5XBbCuYez43c9rboMfhOs6NOuck1J/pr5fI2NljkwBQeLUqfU2svUIeno4O mJyiwFk241h1l2+5jRPpMvr3m/uIR6FA+WX4i9Nw9H3s2LUwOTfxWOJ43hw8YpobKxyD aCiq9pK4LpeKBycOSUCqWXi3u4NCOZ/dl73NS3axPZtjBxxkzc6zuoqAs7p27P2vyksi dZ4glB17cDOvfUqYQdQwEJtzFITywzAYpiNHtDk1GLg3aTsAvVA6DbvA5RkOrQKhruDg 25Yw== X-Gm-Message-State: AC+VfDy5xaqI6dcSCA1A+NzGP8sP/Aw4evF+pQAoB1Gmsg0nEf7W5cJi G0QmhbR+QpqaqilHXV/4iQCbQ8YJyoQBkSPLc4A= X-Received: by 2002:a7b:c8d9:0:b0:3f4:2174:b284 with SMTP id f25-20020a7bc8d9000000b003f42174b284mr6687645wml.28.1683670577699; Tue, 09 May 2023 15:16:17 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id t25-20020a7bc3d9000000b003f42d3111b8sm2052888wmj.30.2023.05.09.15.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 15:16:17 -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 , Dmitry Safonov <0x7f454c46@gmail.com>, Hideaki YOSHIFUJI , Leonard Crestez , Salam Noureddine , netdev@vger.kernel.org Subject: [PATCH 2/5] net/tcp: Use tcp_v6_md5_hash_skb() instead of .calc_md5_hash() Date: Tue, 9 May 2023 23:16:05 +0100 Message-Id: <20230509221608.2569333-3-dima@arista.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230509221608.2569333-1-dima@arista.com> References: <20230509221608.2569333-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_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765456724085017444?= X-GMAIL-MSGID: =?utf-8?q?1765456724085017444?= Using af-specific callback requires the socket to be full (struct tcp_sock). Using tcp_v6_md5_hash_skb() instead, depending on passed family parameter makes it possible to use it for non-full sockets as well (if key-lookup succeeds). Next commit uses tcp_inbound_md5_hash() to verify segments on twsk. This seems quite safe to do, as pre-commit 7bbb765b7349 ("net/tcp: Merge TCP-MD5 inbound callbacks") ip-version-specific functions tcp_v{4,6}_inbound_md5_hash were calling tcp_v4_md5_hash_skb()/tcp_v6_md5_hash_skb(). Signed-off-by: Dmitry Safonov --- include/net/tcp.h | 11 +++++++++++ net/ipv4/tcp.c | 9 +++------ net/ipv6/tcp_ipv6.c | 6 ++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 04a31643cda3..e127fc685ca6 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1676,6 +1676,17 @@ struct tcp_md5sig_pool { /* - functions */ int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, const struct sock *sk, const struct sk_buff *skb); +#if IS_ENABLED(CONFIG_IPV6) +int tcp_v6_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, + const struct sock *sk, const struct sk_buff *skb); +#else +static inline int tcp_v6_md5_hash_skb(char *md5_hash, + const struct tcp_md5sig_key *key, + const struct sock *sk, const struct sk_buff *skb) +{ + return -EPROTONOSUPPORT; +} +#endif int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, int family, u8 prefixlen, int l3index, u8 flags, const u8 *newkey, u8 newkeylen); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 20db115c38c4..c1897a039ff5 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4570,7 +4570,6 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, const __u8 *hash_location = NULL; struct tcp_md5sig_key *hash_expected; const struct tcphdr *th = tcp_hdr(skb); - const struct tcp_sock *tp = tcp_sk(sk); int genhash, l3index; u8 newhash[16]; @@ -4601,13 +4600,11 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, * IPv4-mapped case. */ if (family == AF_INET) - genhash = tcp_v4_md5_hash_skb(newhash, - hash_expected, + genhash = tcp_v4_md5_hash_skb(newhash, hash_expected, NULL, skb); else - genhash = tp->af_specific->calc_md5_hash(newhash, - hash_expected, - NULL, skb); + genhash = tcp_v6_md5_hash_skb(newhash, hash_expected, + NULL, skb); if (genhash || memcmp(hash_location, newhash, 16) != 0) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 42792bc5b9bf..574398a89970 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -732,10 +732,8 @@ static int tcp_v6_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, return 1; } -static int tcp_v6_md5_hash_skb(char *md5_hash, - const struct tcp_md5sig_key *key, - const struct sock *sk, - const struct sk_buff *skb) +int tcp_v6_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, + const struct sock *sk, const struct sk_buff *skb) { const struct in6_addr *saddr, *daddr; struct tcp_md5sig_pool *hp;