From nobody Wed Feb 11 19:41:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3599ACA0EC6 for ; Tue, 12 Sep 2023 03:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242084AbjILDMN (ORCPT ); Mon, 11 Sep 2023 23:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242106AbjILDL6 (ORCPT ); Mon, 11 Sep 2023 23:11:58 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450AB901D for ; Mon, 11 Sep 2023 15:22:07 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-403004a96eeso29311085e9.3 for ; Mon, 11 Sep 2023 15:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1694470840; x=1695075640; 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=0llV6UqFLHP2cV3AYJNJt8dH/ml/kwPn87cg+YveH0M=; b=MSVr0aUT5Iw5B0k2D/eERUH99CYAOG9ukOZVfVzS7BFWXoP1MnuuYBtSHoBkTqg4ZG tMMDSM6cmG+dlOM/j+i26wXZYnK1uQV0ccpM/Cu+nFqqjnq1dTwaQhJjPDHmcZzqvw34 vw35nT3WtijJlWC8ycDTPLh8O+RA/qZmi35R3dWPaXfIFIeSSI3CWyI5lEZRJ205y8by 6MErN006Wwf6n7zbPbvDTqMSH522VECg/KdalCdenojcSg3XD52TV/nohAo7S6gvn0hg pIu3/l72ypkEZ1Yp+McIZfyCsPE53CitAYrN+bsQkC0XHN8pZ7uegCAXVR0geTTLScY1 MHWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694470840; x=1695075640; 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=0llV6UqFLHP2cV3AYJNJt8dH/ml/kwPn87cg+YveH0M=; b=A4XOvPgYdGLPaK/tA87JY5vph3zQI1eGvJc+3Ho2iZe0ILfs5I9DkqecMec3lvSOGe /RV7sBx7FCrVBvy1F0Nm3S66zWEdRGBn9NvCYkuaTRX9RS3cglhM1vjq8jBukPrMISSL RRGv4LP80FnttQ35/asohSCuQTuK1te+SemV7rq8LbnyFfx9FA3B2EfNCm2K4PGIy9aq WTYUyJGlpFJX1N0TTahHTttByNApFNbrUT+hJP13P+FdEUDYCOwpYKgXSV28IHX4LLCM Oliiog2IbcrLfJvH14RoJWmv3V/E7bhEwQB/6wgLZivG65oXcbcm5GC8XGXsocWEMJm5 uqmg== X-Gm-Message-State: AOJu0YzkwpgYfuCpXd7Ll/3Jm9f/i87PB5v7Qzt5h0ewoRxSceNucf60 HGVyNvABCy0V0DtpXCKLcGRtuDUPfQJaf+ra/d4= X-Google-Smtp-Source: AGHT+IE6HB3qXlbZaXVSvSLwz1Xoel6gOTZY3UMeIzjK8dA9C1nsztH8KNeiobr8nSv/a36RQDqrHw== X-Received: by 2002:a05:600c:245:b0:401:1b58:72fa with SMTP id 5-20020a05600c024500b004011b5872famr9354440wmj.33.1694466262894; Mon, 11 Sep 2023 14:04:22 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id z20-20020a1c4c14000000b00402e942561fsm14261699wmf.38.2023.09.11.14.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 14:04:22 -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 v11 net-next 15/23] net/tcp: Add tcp_hash_fail() ratelimited logs Date: Mon, 11 Sep 2023 22:03:35 +0100 Message-ID: <20230911210346.301750-16-dima@arista.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911210346.301750-1-dima@arista.com> References: <20230911210346.301750-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: David Ahern --- 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 7003b64527d4..ac5f96f0ce19 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2641,12 +2641,18 @@ tcp_inbound_hash(struct sock *sk, const struct requ= est_sock *req, int l3index; =20 /* 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; + } =20 if (req) { if (tcp_rsk_used_ao(req) !=3D !!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; } } @@ -2663,10 +2669,14 @@ tcp_inbound_hash(struct sock *sk, const struct requ= est_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 e62452bc17d6..5c5d16b6f9f9 100644 --- a/include/net/tcp_ao.h +++ b/include/net/tcp_ao.h @@ -118,6 +118,35 @@ struct tcp_ao_info { struct rcu_head rcu; }; =20 +#define tcp_hash_fail(msg, family, skb, fmt, ...) \ +do { \ + const struct tcphdr *th =3D tcp_hdr(skb); \ + char hdr_flags[5] =3D {}; \ + char *f =3D hdr_flags; \ + \ + if (th->fin) \ + *f++ =3D 'F'; \ + if (th->syn) \ + *f++ =3D 'S'; \ + if (th->rst) \ + *f++ =3D 'R'; \ + if (th->ack) \ + *f++ =3D 'A'; \ + if (f !=3D hdr_flags) \ + *f =3D ' '; \ + if ((family) =3D=3D 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 */ =20 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 8506be193843..ab6eb3cc38e1 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4367,7 +4367,6 @@ tcp_inbound_md5_hash(const struct sock *sk, const str= uct sk_buff *skb, * o MD5 hash and we're not expecting one. * o MD5 hash and its wrong. */ - const struct tcphdr *th =3D tcp_hdr(skb); const struct tcp_sock *tp =3D tcp_sk(sk); struct tcp_md5sig_key *key; u8 newhash[16]; @@ -4377,6 +4376,7 @@ tcp_inbound_md5_hash(const struct sock *sk, const str= uct sk_buff *skb, =20 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; } =20 @@ -4392,16 +4392,19 @@ tcp_inbound_md5_hash(const struct sock *sk, const s= truct sk_buff *skb, if (genhash || memcmp(hash_location, newhash, 16) !=3D 0) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); if (family =3D=3D AF_INET) { - net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 i= ndex %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 0b5621cbc744..2283203f1ac5 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -764,6 +764,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 !=3D %d", maclen, tcp_ao_maclen(key)); return SKB_DROP_REASON_TCP_AOFAILURE; } =20 @@ -778,6 +780,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; } @@ -805,6 +808,8 @@ tcp_inbound_ao_hash(struct sock *sk, const struct sk_bu= ff *skb, info =3D 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; } =20 @@ -907,6 +912,8 @@ tcp_inbound_ao_hash(struct sock *sk, const struct sk_bu= ff *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; } =20 --=20 2.41.0