Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1346115rwb; Thu, 10 Nov 2022 15:01:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM6aKExw1TEJtZ18CkELLSFT+bXDQsGnLWsVFLtgtMWbBr3Ojjnimy18trJ6ED2J1bn6sRuH X-Received: by 2002:a17:906:9f20:b0:78d:e26f:bfd8 with SMTP id fy32-20020a1709069f2000b0078de26fbfd8mr4123509ejc.482.1668121284643; Thu, 10 Nov 2022 15:01:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668121284; cv=none; d=google.com; s=arc-20160816; b=MnW+Gq7A9xoUA9jBG5t/vXg+Ncp6CDeRq7GDfT0tDADh/ldAshsV2rnU19B6cUX1eK rPAp2rFkTubu3HkHUsTba5ionE/h0xCols/yVTN4HvTpFFMxPqRcit5W9Zq0vUWBZk4J viJigu9Md2uo14ujLouFVMSfpjQMMcyq+ly5JapaKszc6xJrseobrhuw24Msg7vdl9/V IyeUxuGtMcMqS0jIEQvNpZFO8YYzQ17lFtF1mJbmqXKqmz/PZc1ZvUZSXXKGyT7n8Txd xQkHoksD5uG37Lz0svUiXGfkg3kNZC7J9Rk4YOUbgwKetv0OJ5PMyQp5ogXsj14ZV6N9 o0QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ckYAbxaJX0FE8Tra3HuW7LsP7t9ODhY0IvtR+ncmsgw=; b=X1Bgy22YwkuGASYHG8xioETt5RdYlzBBsH9q8mR9x0DkTeiFUJvsWonGuikREhmOjY P1KPQCHQrqj5D23SfJHUGD8sfbyNaREsAocg4cN+hdqDkRSSHDFg7kwM9L1OU9p7D/oO 06jTzm4slrFNmxU6n5/Q91jDoRwxD5CZ6Vnf2sZfb5REPTBtIBJPo6FScX9TOf5RrlWT Q0Ln9eqG9TekSaBOVRfZod4KFDKItCODqlxx89LFJ144YYi6motyJiky5/tFmU00ztTW v7WeBi4JwAsHvy9Q1HU50DAYd96qFZMvK8STC1Y4Pbibz694qiIZARIKKE9c75eXtWyL 47Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=ovhF5zrW; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a50fb87000000b0046272b487cesi689673edq.331.2022.11.10.15.01.00; Thu, 10 Nov 2022 15:01:24 -0800 (PST) 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=@lunn.ch header.s=20171124 header.b=ovhF5zrW; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbiKJWbP (ORCPT + 93 others); Thu, 10 Nov 2022 17:31:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiKJWbN (ORCPT ); Thu, 10 Nov 2022 17:31:13 -0500 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E20F56554; Thu, 10 Nov 2022 14:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=ckYAbxaJX0FE8Tra3HuW7LsP7t9ODhY0IvtR+ncmsgw=; b=ovhF5zrWCtYwRWd0map5L3rP9S ULuwT6k3vz7XX9YcVnv00raZit9RjhuDzHvp8RtGfApuIYgsm968LEldgM7IbE4U4seuynQcE0rox 633dO+HcsRyvID8hubiuWBcJDQWu7ZQVNOlWRY/1SSBTV+f7jVZU+IVRwdOkPxQMPCUA=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1otG4A-0024Zo-7g; Thu, 10 Nov 2022 23:30:34 +0100 Date: Thu, 10 Nov 2022 23:30:34 +0100 From: Andrew Lunn To: Jamie Bainbridge Cc: Eric Dumazet , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tcp: Add listening address to SYN flood message Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS 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 On Fri, Nov 11, 2022 at 08:20:18AM +1100, Jamie Bainbridge wrote: > On Fri, 11 Nov 2022 at 00:51, Andrew Lunn wrote: > > > > On Thu, Nov 10, 2022 at 09:21:06PM +1100, Jamie Bainbridge wrote: > > > The SYN flood message prints the listening port number, but on a system > > > with many processes bound to the same port on different IPs, it's > > > impossible to tell which socket is the problem. > > > > > > Add the listen IP address to the SYN flood message. It might have been > > > nicer to print the address first, but decades of monitoring tools are > > > watching for the string "SYN flooding on port" so don't break that. > > > > > > Tested with each protcol's "any" address and a host address: > > > > > > Possible SYN flooding on port 9001. IP 0.0.0.0. > > > Possible SYN flooding on port 9001. IP 127.0.0.1. > > > Possible SYN flooding on port 9001. IP ::. > > > Possible SYN flooding on port 9001. IP fc00::1. > > > > > > Signed-off-by: Jamie Bainbridge > > > --- > > > net/ipv4/tcp_input.c | 16 +++++++++++++--- > > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > > > index 0640453fce54b6daae0861d948f3db075830daf6..fb86056732266fedc8ad574bbf799dbdd7a425a3 100644 > > > --- a/net/ipv4/tcp_input.c > > > +++ b/net/ipv4/tcp_input.c > > > @@ -6831,9 +6831,19 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) > > > __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPREQQFULLDROP); > > > > > > if (!queue->synflood_warned && syncookies != 2 && > > > - xchg(&queue->synflood_warned, 1) == 0) > > > - net_info_ratelimited("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n", > > > - proto, sk->sk_num, msg); > > > + xchg(&queue->synflood_warned, 1) == 0) { > > > +#if IS_ENABLED(CONFIG_IPV6) > > > + if (sk->sk_family == AF_INET6) { > > > > Can the IS_ENABLED() go inside the if? You get better build testing > > that way. > > > > Andrew > > Are you sure? Why would the IS_ENABLED() be inside of a condition > which isn't compiled in? If IPv6 isn't compiled in then the condition > would never evaluate as true, so seems pointless a pointless > comparison to make? People not compiling in IPv6 have explicitly asked > *not* to have their kernel filled with a bunch of "if (family == > AF_INET6)" haven't they? > > There are many other examples of this pattern of "IS_ENABLED()" first > and "if (family == AF_INET6)" inside it, but I can't see any of the > inverse which I think you're suggesting, see: > > grep -C1 -ERHn "IS_ENABLED\(CONFIG_IPV6\)" net | grep -C1 "family == AF_INET6" > > Please let me know if I've misunderstood? So what i'm suggesting is if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { net_info_ratelimited("%s: Possible SYN flooding on port %d. IP %pI6c. %s. Check SNMP counters.\n", proto, sk->sk_num, &sk->sk_v6_rcv_saddr, msg); } The IS_ENABLED(CONFIG_IPV6) will evaluate to 0 at compile time, and the optimiser will throw away the whole lot since it can never be true. However, before the code gets to the optimiser, it first needs to compile. It will check you have the correct number of parameters for the string format, do the types match, do the structure members exist, etc. Anybody doing compile testing of a change, and they have IPV6 turned off, has a chance off getting errors reported when they have actually broken IPV6, but don't know it, because they are not compiling it. Now, IPV6 is one of those big options which i expect 0-day tests quite regularly. Using IF_ENABLED() like this brings more benefit from less used options which gets very little build testing, and so are often broke until somebody like Arnd runs builds with lots of random configs. Andrew