Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8702946rwp; Wed, 19 Jul 2023 14:04:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9CFCm7ptHLeITUalTMkyBYoSFV0mcNQfPnWJzE/AjvL3J0Wue2akfGeHIBjOZKkzevYF2 X-Received: by 2002:a05:6402:51c6:b0:51e:5e3d:cb92 with SMTP id r6-20020a05640251c600b0051e5e3dcb92mr3485648edd.16.1689800687173; Wed, 19 Jul 2023 14:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689800687; cv=none; d=google.com; s=arc-20160816; b=piE7a6asb1buPiWs0nJW4khQVPBvJ4qL2DY5XYfqYl4uk0oLWtF5dvvIfYwwWe3WF+ +9SlCdESAUaKutEE5OE4IoMjN0MGOSeqh+Kb5DAa8Q6E6V1mAsybSf3E8tdTkYNGRX4I /u8CLsFBMf7ub4GfW06UrlcMOAnj8byn+2XnsVvzNaV369S+NtQBMciQja5m3pBZqqm6 +wI1mmjiENdC1KQf+0faJ2mVBbNSb7xHnomvKaj7+PDEO5GEHhN6vW/mgXzvk1Cq25kM h8tbxV27A9jTK7YlUARdMDsZitMoPHSH9gUiwaqOIw/iRonpSrcEQIgGr/feLLlPz2fL ngUQ== 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=Hyh5Pyti/0nkO+5v1kH0qWrNJavkuVSGm+KH+gsizAU=; fh=+1v2wpWL3SwC67MevmNFbsOkJ0jlpe0KMhkxFTuop+s=; b=XHld13iq32j4S3PEcaxVEXJChfUNVwbnKyKPvka/1IXjKSCwKAmFwdxGXwTyXblxiv pbdq2Bnjiem3Oe+L3gDD3GoQSohUlpRNX8SkLMTaL6WTnQDt3Vsw6SaVlg3BKmYkgdYy a38QiCzjn0ft7QzZkuW6f/Hi3KGwup8SiMQKffXRTXz/Fd3P6ZEwJxJZNN4VGf/gPvOx +vQgvK4livTZNDbOaOm15cJL5CiNjKxcEniwxf1RAYsK8jbfEfYyOwDmruS5G0gS6GI7 2JU4yOxpJoJHOodtM36Ui+OjDNMzmTDgJyD4dxe4EuNLGuvSrwNaIe9fbBOUk5js9Mq5 m7aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=dHEaHfFw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020aa7cac1000000b0051fde3f49cdsi3714613edt.531.2023.07.19.14.04.18; Wed, 19 Jul 2023 14:04:47 -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=dHEaHfFw; 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 S231308AbjGSU20 (ORCPT + 99 others); Wed, 19 Jul 2023 16:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbjGSU1o (ORCPT ); Wed, 19 Jul 2023 16:27:44 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736D92700 for ; Wed, 19 Jul 2023 13:27:06 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fd0f000f1cso726475e9.1 for ; Wed, 19 Jul 2023 13:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1689798424; x=1692390424; 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=Hyh5Pyti/0nkO+5v1kH0qWrNJavkuVSGm+KH+gsizAU=; b=dHEaHfFwqOSbq/TxuknG2TfGylxjVDaLh7vymzNDff7rsmzlRSwGkYLt+qxWQnzDwB 7V3+RrfhPM5mCMs3uYgRwBsy0/tF1Wsh8r7Jun1BesOngVyUjQAUV0X+kJXcd5WBDb+s pDPjdKMMbCE9aFJAOBWoLDZ5zHmFSR9gBXzUeidVn+ZUhbep46xE09MmmrC8JDHHNfAZ r2BlNM2XvLWq3CQA88jn8vtE/CzHfEV9wTqA/274KeeI+bFMcRZMVCciw3G20aawrabn NO+3jqHgWbDK9MgCHNbyar4YEWEK2NMg2hQaSQuvn1VH5Lenp2qRuq28fvXyMtPWrPtd 6s6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689798424; x=1692390424; 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=Hyh5Pyti/0nkO+5v1kH0qWrNJavkuVSGm+KH+gsizAU=; b=HhcZWRXptrsyLn2U+CoO5/Ydb4dUfH3Da/Oo3Qt7HeBLhlBelgTcqr0an2iUleofeO b+ztgaLY7i3erp5f397HIxuTOL/su5Lof23jlHZETNLEUvT/eUk1uPVUTtcTI87Mr0N7 RsMynRx7G14EJ84545mVlvZAOZYgqTzRrMVLr0Ucm6S56XjfuQOCS+qHmfP71Y8/F3Ik TKw/pmzFUPjQCZ+ZR6cXAvrGaCK5J146BjW2eVJuJOzzftzO8mhoqBeptbsdcrpNzPw6 FIHrtflIE6pFelg77wscau2fHSOMxKt+F9Pm0iB2F8kTzH4+2vEz2RTNn+pHIQeTKZyD hggw== X-Gm-Message-State: ABy/qLbvkAkjtjvhyIhnS12SkeQNBbVk0YXBrZj4VQoWiQncjprPfAu/ YdWAM9bwbT3uzkEtWaz9GayPoNUbevuN/rWqY2g= X-Received: by 2002:a05:600c:5128:b0:3fa:8c8b:716 with SMTP id o40-20020a05600c512800b003fa8c8b0716mr2633359wms.1.1689798424269; Wed, 19 Jul 2023 13:27:04 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id 3-20020a05600c234300b003fc04d13242sm2432319wmq.0.2023.07.19.13.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 13:27:03 -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 , Salam Noureddine , "Tetreault, Francois" , netdev@vger.kernel.org Subject: [PATCH v8 15/23] net/tcp: Add tcp_hash_fail() ratelimited logs Date: Wed, 19 Jul 2023 21:26:20 +0100 Message-ID: <20230719202631.472019-16-dima@arista.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202631.472019-1-dima@arista.com> References: <20230719202631.472019-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=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 Add a helper for logging connection-detailed messages for failed TCP hash verification (both MD5 and AO). 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/net/tcp.h | 14 ++++++++++++-- include/net/tcp_ao.h | 29 +++++++++++++++++++++++++++++ net/ipv4/tcp.c | 23 +++++++++++++---------- net/ipv4/tcp_ao.c | 7 +++++++ 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 646aebc682f8..61dd9a8afaf1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2610,12 +2610,18 @@ tcp_inbound_hash(struct sock *sk, const struct request_sock *req, int l3index; /* Invalid option or two times meet any of auth options */ - if (tcp_parse_auth_options(th, &md5_location, &aoh)) + if (tcp_parse_auth_options(th, &md5_location, &aoh)) { + tcp_hash_fail("TCP segment has incorrect auth options set", + family, skb, ""); return SKB_DROP_REASON_TCP_AUTH_HDR; + } if (req) { if (tcp_rsk_used_ao(req) != !!aoh) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD); + tcp_hash_fail("TCP connection can't start/end using TCP-AO", + family, skb, "%s", + !aoh ? "missing AO" : "AO signed"); return SKB_DROP_REASON_TCP_AOFAILURE; } } @@ -2632,10 +2638,14 @@ tcp_inbound_hash(struct sock *sk, const struct request_sock *req, * the last key is impossible to remove, so there's * always at least one current_key. */ - if (tcp_ao_required(sk, saddr, family, true)) + if (tcp_ao_required(sk, saddr, family, true)) { + tcp_hash_fail("AO hash is required, but not found", + family, skb, "L3 index %d", l3index); return SKB_DROP_REASON_TCP_AONOTFOUND; + } if (unlikely(tcp_md5_do_lookup(sk, l3index, saddr, family))) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); + tcp_hash_fail("MD5 Hash not found", family, skb, ""); return SKB_DROP_REASON_TCP_MD5NOTFOUND; } return SKB_NOT_DROPPED_YET; diff --git a/include/net/tcp_ao.h b/include/net/tcp_ao.h index fc5674763730..801dca405df7 100644 --- a/include/net/tcp_ao.h +++ b/include/net/tcp_ao.h @@ -119,6 +119,35 @@ struct tcp_ao_info { struct rcu_head rcu; }; +#define tcp_hash_fail(msg, family, skb, fmt, ...) \ +do { \ + const struct tcphdr *th = tcp_hdr(skb); \ + char hdr_flags[5] = {}; \ + char *f = hdr_flags; \ + \ + if (th->fin) \ + *f++ = 'F'; \ + if (th->syn) \ + *f++ = 'S'; \ + if (th->rst) \ + *f++ = 'R'; \ + if (th->ack) \ + *f++ = 'A'; \ + if (f != hdr_flags) \ + *f = ' '; \ + if (family == AF_INET) { \ + net_info_ratelimited("%s for (%pI4, %d)->(%pI4, %d) %s" fmt "\n", \ + msg, &ip_hdr(skb)->saddr, ntohs(th->source), \ + &ip_hdr(skb)->daddr, ntohs(th->dest), \ + hdr_flags, ##__VA_ARGS__); \ + } else { \ + net_info_ratelimited("%s for [%pI6c]:%u->[%pI6c]:%u %s" fmt "\n", \ + msg, &ipv6_hdr(skb)->saddr, ntohs(th->source), \ + &ipv6_hdr(skb)->daddr, ntohs(th->dest), \ + hdr_flags, ##__VA_ARGS__); \ + } \ +} while (0) + #ifdef CONFIG_TCP_AO /* TCP-AO structures and functions */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index fcedec0ae08e..096c2f0949d3 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4376,7 +4376,6 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, * o MD5 hash and we're not expecting one. * o MD5 hash and its wrong. */ - const struct tcphdr *th = tcp_hdr(skb); const struct tcp_sock *tp = tcp_sk(sk); struct tcp_md5sig_key *key; int genhash; @@ -4386,6 +4385,7 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, if (!key && hash_location) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); + tcp_hash_fail("Unexpected MD5 Hash found", family, skb, ""); return SKB_DROP_REASON_TCP_MD5UNEXPECTED; } @@ -4401,16 +4401,19 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, if (genhash || memcmp(hash_location, newhash, 16) != 0) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); if (family == AF_INET) { - net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n", - saddr, ntohs(th->source), - daddr, ntohs(th->dest), - genhash ? " tcp_v4_calc_md5_hash failed" - : "", l3index); + tcp_hash_fail("MD5 Hash failed", AF_INET, skb, "%s L3 index %d", + genhash ? "tcp_v4_calc_md5_hash failed" + : "", l3index); } else { - net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u L3 index %d\n", - genhash ? "failed" : "mismatch", - saddr, ntohs(th->source), - daddr, ntohs(th->dest), l3index); + if (genhash) { + tcp_hash_fail("MD5 Hash failed", + AF_INET6, skb, "L3 index %d", + l3index); + } else { + tcp_hash_fail("MD5 Hash mismatch", + AF_INET6, skb, "L3 index %d", + l3index); + } } return SKB_DROP_REASON_TCP_MD5FAILURE; } diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c index 5ebbfadfbfd0..9ee7fc9f6a76 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -772,6 +772,8 @@ tcp_ao_verify_hash(const struct sock *sk, const struct sk_buff *skb, NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD); atomic64_inc(&info->counters.pkt_bad); atomic64_inc(&key->pkt_bad); + tcp_hash_fail("AO hash wrong length", family, skb, + "%u != %d", maclen, tcp_ao_maclen(key)); return SKB_DROP_REASON_TCP_AOFAILURE; } @@ -786,6 +788,7 @@ tcp_ao_verify_hash(const struct sock *sk, const struct sk_buff *skb, NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD); atomic64_inc(&info->counters.pkt_bad); atomic64_inc(&key->pkt_bad); + tcp_hash_fail("AO hash mismatch", family, skb, ""); kfree(hash_buf); return SKB_DROP_REASON_TCP_AOFAILURE; } @@ -813,6 +816,8 @@ tcp_inbound_ao_hash(struct sock *sk, const struct sk_buff *skb, info = rcu_dereference(tcp_sk(sk)->ao_info); if (!info) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOKEYNOTFOUND); + tcp_hash_fail("AO key not found", family, skb, + "keyid: %u", aoh->keyid); return SKB_DROP_REASON_TCP_AOUNEXPECTED; } @@ -915,6 +920,8 @@ tcp_inbound_ao_hash(struct sock *sk, const struct sk_buff *skb, key_not_found: NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOKEYNOTFOUND); atomic64_inc(&info->counters.key_not_found); + tcp_hash_fail("Requested by the peer AO key id not found", + family, skb, ""); return SKB_DROP_REASON_TCP_AOKEYNOTFOUND; } -- 2.41.0