Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp673198rwb; Thu, 18 Aug 2022 10:07:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7bxlMhiL0il+LcWXCAYkv8D4CEomNgSxIYL91VXm+iOBdKFLTMK39lY9WLrHuFIzvSM2mK X-Received: by 2002:a63:e901:0:b0:422:4d27:5814 with SMTP id i1-20020a63e901000000b004224d275814mr3117482pgh.317.1660842463753; Thu, 18 Aug 2022 10:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660842463; cv=none; d=google.com; s=arc-20160816; b=jouNtrpqcgGlsPHpC5t6+euuDHIHNlxL/o2vaSFn5p9R0rDPNC2x1P6zlWsHozRIx4 ss5nydow2iTcUWNmbfAcjg62ZyFzl94B6FcWpO66zutAgnNA+NkeOKg0y3/w7i+cLVxY 0ChltHBBWqQu4uxWhW6saw3Qh/uPj7kYtHJoE9oDN75mSm3P8GduQ4e+2Ly9qI5h0pjG d4o1jwED5ezO3wtE81C/CBMKveOrXEKbpi7QNahEH8kO0x36c0lUS3ZKwmWZ7bQ64Bft l8lS+f3tWEHUkSAhVWTdoyDH8H7CmbqhemPrwZHkaEtWQMNQlO4FLPiCNJfOsrzaziPw cmlg== 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=eLy87IRVh4b6Em0nmlrAVYIKhrkSltNj2ViSGS4UTfA=; b=r1q1pnN1tL2PjyOX4sP0nirD6jfKqaST9Yl574unvFASBuyAAMVfbyLdBDtHUTY/q/ 7NpX4ZRlHq0dwk7SFAKObetYfZkRxf4N6bo9nW/NC70V7QAixhBRL0esP8HfeARR5N+6 Z1ocxcRxKwOvUhsBo4Mz/cElo2y54tt5g0BEfPjRu3ib7O0w9/u7RkBhS5hBoX/z3f5m iS1h8mfnViRNWZi+5JUv0gNxrurPrSEsgnfMfb1jRTOFhBtB+AwJFKQAA+cvB/Bxaow2 UgIHvOLOCR16dcmq+J6HTg5Sh6bx0wVli5rPIu+UBeeH551YTe4iNsZ31Hbdkr8KFMGu AgfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=XeSwAr9n; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 4-20020a631144000000b004226298dfa2si1632662pgr.312.2022.08.18.10.07.26; Thu, 18 Aug 2022 10:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=XeSwAr9n; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S1344764AbiHRRDL (ORCPT + 99 others); Thu, 18 Aug 2022 13:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344574AbiHRRAy (ORCPT ); Thu, 18 Aug 2022 13:00:54 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 929A6C9EB8 for ; Thu, 18 Aug 2022 10:00:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id r16so2424441wrm.6 for ; Thu, 18 Aug 2022 10:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=eLy87IRVh4b6Em0nmlrAVYIKhrkSltNj2ViSGS4UTfA=; b=XeSwAr9n/Pw5Fm5O7zSRaI6sLWfJJvFQzX9m5oz3ag1QJcf6ZYTV2ZvwG+utKZUWiH 0Ip4YOxZs6/cR6joQTCf4XbSlbnIdDIr0lyYowO6/cQLJVSzjKw8351B6vQFRELXcT6j 0Ln3/LwasJ/0jH96ZTUWY3vyu2LfwmREYmS+v++7BHaC2m3EtWRnX10RFm7KfP+sFuBS O1bbaAlfSJWb02jRZvhXPAwdYGrmVYCNyW8sEeSbXvte9cUsFepUsfRrMUsDQb55C4SY sCHmBpoHgKuQ699QNzWfZfspdizqugGaxKA9sBPOZEv2QTEvkr0VBRqLcIerGSTIOpYD Zi6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=eLy87IRVh4b6Em0nmlrAVYIKhrkSltNj2ViSGS4UTfA=; b=2nAY0pvdiP4T/CPD18VXnE8EMh99DlFI+K0TB5Dom43O2QxVOwBHGclvHQ0UyxwkxL jg6EICJAC15PzYZ2iSwSPvfj7aY4Ck9iWeL0Qz+KZ1x2WV9/2p6WLdkAaDwyYzquKbfy E3iptPiRDUEweDGQLDdOwnq7v4Dcwh+UekgYwn4ssfHBjKV4M+G9oPnc66YbeouQ95Nu O17d8BVs3kCLE7hr6Y3zBvVs7cHpUW9KRDCQ89tuPrjQDBIPkAxgIBapXPieJviPiIlc agAA4wMMgMN187OjWgdbzvKaW3STf/cPSB5Gz1DJDlJirbIKYT762sC2/AO9DCZIGhHh y33w== X-Gm-Message-State: ACgBeo0aTwo1/5huTbSIZVHXzswQ2Lo88smspDEzyV9IlfZR8BZJp+si f5y/7ESBsbhp8cbXJmCb1/6DLw== X-Received: by 2002:a05:6000:1704:b0:220:69a7:ec2b with SMTP id n4-20020a056000170400b0022069a7ec2bmr2234469wrc.436.1660842043096; Thu, 18 Aug 2022 10:00:43 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id be13-20020a05600c1e8d00b003a511e92abcsm2662169wmb.34.2022.08.18.10.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 10:00:42 -0700 (PDT) From: Dmitry Safonov To: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org Cc: Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , David Ahern , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Biggers , Francesco Ruggeri , Herbert Xu , Hideaki YOSHIFUJI , Ivan Delalande , Jakub Kicinski , Leonard Crestez , Paolo Abeni , Salam Noureddine , Shuah Khan , netdev@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH 20/31] net/tcp: Add tcp_hash_fail() ratelimited logs Date: Thu, 18 Aug 2022 17:59:54 +0100 Message-Id: <20220818170005.747015-21-dima@arista.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220818170005.747015-1-dima@arista.com> References: <20220818170005.747015-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-crypto@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 | 27 +++++++++++++++++++++++++++ net/ipv4/tcp.c | 23 +++++++++++++---------- net/ipv4/tcp_ao.c | 7 +++++++ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 94573219f58d..896db7ba0670 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2517,12 +2517,19 @@ 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) + if (tcp_rsk_used_ao(req) != !!aoh) { + 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; + } } /* sdif set, means packet ingressed via a device @@ -2545,11 +2552,14 @@ tcp_inbound_hash(struct sock *sk, const struct request_sock *req, lockdep_sock_is_held(sk)); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOREQUIRED); atomic64_inc(&ao_info->counters.ao_required); + tcp_hash_fail("AO hash is required, but not found", + family, skb, ""); return SKB_DROP_REASON_TCP_AONOTFOUND; } #endif 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 dbeaa7d4e212..e99c8f300a5a 100644 --- a/include/net/tcp_ao.h +++ b/include/net/tcp_ao.h @@ -101,6 +101,33 @@ struct tcp_ao_info { int tcp_do_parse_auth_options(const struct tcphdr *th, const u8 **md5_hash, const u8 **ao_hash); +#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 (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 8df03d456ebb..3ef9d69fa561 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4511,7 +4511,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); struct tcp_sock *tp = tcp_sk(sk); struct tcp_md5sig_key *key; int genhash; @@ -4521,6 +4520,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; } @@ -4536,16 +4536,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 3a33733a714d..4283e0193e2a 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -662,6 +662,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; } @@ -672,6 +674,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, ""); return SKB_DROP_REASON_TCP_AOFAILURE; } NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOGOOD); @@ -698,6 +701,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; } @@ -780,6 +785,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.37.2