From patchwork Fri Dec 6 10:27:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13896974 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 005CFE77173 for ; Fri, 6 Dec 2024 10:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=hthJtxRUGovk5V1RqI0hmfgY1tiYoYoWmAR9jCX9OyI=; b=I3Kqzej4uHV+nypL5Qv77RHtQ4 ERCqkF+3CNqu9Lg/jHngT+StlGa0s4wFAj4p5OkVb5O6qJBXEUH84dqrxmJ/Dr5Iu0Cv/9rJb6+t7 0Q0x9y89S/gL1iEBvAHJqhoQXK/Mcy+61+bCzmUonUajRTXOeInlDdUIuczMkYtLqkPegRMzBgNUK R83EXBXNLn2p69cXsQsEHiCT5hMGW4GBe1w3J9Ganb71KsQGQp5jQBixmMzPnH/EZ/zuYkmhLQLNJ K6VtGaFJazCx/Q947/YsxXh2SDrCtFc9h4K7/zWpmuy9kCdXGk8Xae0CSkVK0YbyzjC7gC1ARkM8J KGuNtG9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJVrU-00000001LrG-3C04; Fri, 06 Dec 2024 10:47:04 +0000 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJVZF-00000001Hq1-4B7L for linux-arm-kernel@lists.infradead.org; Fri, 06 Dec 2024 10:28:15 +0000 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-126-71H4KnOWMoK8Apry69ITrA-1; Fri, 06 Dec 2024 10:28:08 +0000 X-MC-Unique: 71H4KnOWMoK8Apry69ITrA-1 X-Mimecast-MFC-AGG-ID: 71H4KnOWMoK8Apry69ITrA Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 6 Dec 2024 10:27:23 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 6 Dec 2024 10:27:23 +0000 From: David Laight To: "netdev@vger.kernel.org" , 'Naresh Kamboju' , 'Dan Carpenter' , Julian Anastasov , "'pablo@netfilter.org'" CC: 'open list' , "'lkft-triage@lists.linaro.org'" , "'Linux Regressions'" , 'Linux ARM' , "'netfilter-devel@vger.kernel.org'" , 'Arnd Bergmann' , "'Anders Roxell'" , 'Johannes Berg' , "'toke@kernel.org'" , 'Al Viro' , "'kernel@jfarr.cc'" , "'kees@kernel.org'" Subject: [PATCH net] Fix clamp() of ip_vs_conn_tab on small memory systems. Thread-Topic: [PATCH net] Fix clamp() of ip_vs_conn_tab on small memory systems. Thread-Index: AdtHyTlbE/fm67s0Ria1gsbgnJ6Kcg== Date: Fri, 6 Dec 2024 10:27:23 +0000 Message-ID: <33893212b1cc4a418cec09aeeed0a9fc@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Q8gpgp9rNV1zfEOR5hYxE6irASarYfE0DkxJNQ-GI2U_1733480887 X-Mimecast-Originator: aculab.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241206_022814_299737_D9DECCF8 X-CRM114-Status: GOOD ( 11.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The intention of the code seems to be that the minimum table size should be 256 (1 << min). However the code uses max = clamp(20, 5, max_avail) which implies the author thought max_avail could be less than 5. But clamp(val, min, max) is only well defined for max >= min. If max < min whether is returns min or max depends on the order of the comparisons. Change to clamp(max_avail, 5, 20) which has the expected behaviour. Replace the clamp_val() on the line below with clamp(). clamp_val() is just 'an accident waiting to happen' and not needed here. Fixes: 4f325e26277b6 (Although I actually doubt the code is used on small memory systems.) Detected by compile time checks added to clamp(), specifically: minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp() Signed-off-by: David Laight --- net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 98d7dbe3d787..c0289f83f96d 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1495,8 +1495,8 @@ int __init ip_vs_conn_init(void) max_avail -= 2; /* ~4 in hash row */ max_avail -= 1; /* IPVS up to 1/2 of mem */ max_avail -= order_base_2(sizeof(struct ip_vs_conn)); - max = clamp(max, min, max_avail); - ip_vs_conn_tab_bits = clamp_val(ip_vs_conn_tab_bits, min, max); + max = clamp(max_avail, min, max); + ip_vs_conn_tab_bits = clamp(ip_vs_conn_tab_bits, min, max); ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits; ip_vs_conn_tab_mask = ip_vs_conn_tab_size - 1;