Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3033585pxb; Tue, 12 Oct 2021 19:35:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt1Ffg0+eK+xWJG2AubVfzUhCV94REtt6e2PVrVZ4nAlm2NVRIPNR7+JAG6XvIE6LYN/S/ X-Received: by 2002:a05:6402:5187:: with SMTP id q7mr5331366edd.374.1634092535006; Tue, 12 Oct 2021 19:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634092535; cv=none; d=google.com; s=arc-20160816; b=f3kvPvqrw36f2AeMhdf3G36SfuBh8IR/Ny8Bpj0Vb2e3D1dqVmaImUOmWOQbwGWI4/ 1LlB29E7QrIG/To5DRtMMU4iQFwXph6waShfVzCDepdY+z9VdkfNxDCkNYfsKBfnPJB9 Z68PKdTq4aY6qwkJWuXboyKVNrhn867t1+GJSY1HJvJARDoFrcRl85q/adVPuQhbV5jD 69HPfNU6up34oa5JxQ2kuHCXgMvNCcnrKkRObVDGKCT4gk8osMWi+mU5uSvvloTmfxuz lB4AcuRrabuHwu7Y7YeWrIZM1sagIWVXiqR/Kq8rlTQB8q4aLHRiMs7pbbUN0pT7FgTa zXBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=bcEsa+sI2EXkheHsoe75kuAxpaLmz4nDKnJI4rcst5U=; b=zufFARgF1K7CiqBsojSM7V+YR9LMjFzZ1Sy5JrB8XLkT7zgPk0+hUQS1gTVVv/QNzM RRQLsAZNDytVidzDyITISkC0RvH7aSvmjpfYloNd3VIFFYkvKoq6sugAaJ+E5j6hBv3b p1FkZEn6Duboz/bAhKFOq2H7nCrcXycT0fWB1mUm96IZk0ix1YmHL2hGdnFHU29DBrY0 oMQd1UCw25Uh2+gWw8ACC3h+MCS+7VYPo/Qo9OVkVlwXcLxbe6ju8nDlqLiw8AqIFgNx uDSxbtJcGo4Aozw3iWTAkBWoFFSQ7ppfKvba04bGSAAPrUjrFuNJbhqrSHWxuatrE105 yoPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bi99xq2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si17926864edi.437.2021.10.12.19.35.10; Tue, 12 Oct 2021 19:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bi99xq2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236586AbhJMCfZ (ORCPT + 99 others); Tue, 12 Oct 2021 22:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbhJMCfY (ORCPT ); Tue, 12 Oct 2021 22:35:24 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66B21C061570; Tue, 12 Oct 2021 19:33:22 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id k2-20020a056830168200b0054e523d242aso1763933otr.6; Tue, 12 Oct 2021 19:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=bcEsa+sI2EXkheHsoe75kuAxpaLmz4nDKnJI4rcst5U=; b=bi99xq2xlfmX8gHx/JDCUhkBmUC7GwIBxwapVKoXIq1tsXuj6FwYqddmY7+khfnwAI sVnOdrMGanHB/SULSC2lJ2lL4KxknKtWxqg9uLetI3mUNBvodbLRxANPvyvzE5nY8pKI 7ZlbxU87HKtpmd1oWXFfQ2EUEkCVKThLExmt6yGrkLA+tTZqHvRemZjtx0nb+uOknGcA Ub7Kaidho8bZtQz5jlNwgsKhwnluGS3T18vnScvbWe0f1JGjUTy/GBdZLhhXSgOV0kFe i4WT2qtbutQo1nUf5MxthMfryTL/Gq8xNwkL8MXZkujLIcRms1S/vyGNaS64ZPHxB4hK wk/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bcEsa+sI2EXkheHsoe75kuAxpaLmz4nDKnJI4rcst5U=; b=K7M1mjOky6TjD9ktZJT27GX6TaMf5UdzO9eG5TPHy+mmOyeBe22NM62GHeEYhPodpk wQSX3xOlLe6pqDHZuC/yJvQziF+/6FfoO/jNN+vRsiPct64MNsScuuQh7QTZGK34RY3I fdZeN8Pw0xrHMKSTnCrSBXOp0g907rldCdakHLAjiW2ncyK7ow2Xz+guRxuLWDX9HGw5 J6h1ErJMMZxonU3YVEXyVD94t0IVzBVP0qQfChHL6UDFkHvY37snPYV+NWU0ZEpjAdek EmmG1Ext7TafRNJ/pgTrBPS7UaWVcZqqt4wJ6GzKjs+pMfQpVzD4QEkurcl7xrcxvZCq xLdg== X-Gm-Message-State: AOAM533b64bkPju08+9VxeVnyDHuYr0/0OboCjD9RZziBYsNuEDPcU9A xewPfcOk+lNmyUQLdmsd9rzqW6TQklu6bg== X-Received: by 2002:a05:6830:2486:: with SMTP id u6mr27916709ots.353.1634092401617; Tue, 12 Oct 2021 19:33:21 -0700 (PDT) Received: from Davids-MacBook-Pro.local ([8.48.134.30]) by smtp.googlemail.com with ESMTPSA id k6sm2705768otf.80.2021.10.12.19.33.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Oct 2021 19:33:21 -0700 (PDT) Subject: Re: [PATCH] ipv4: only allow increasing fib_info_hash_size To: =?UTF-8?B?5byg5Yev?= Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20211012110658.10166-1-zhangkaiheb@126.com> <23911752-3971-0230-cfd2-f8e30e8805db@gmail.com> <3bd88b51.6c7.17c77339c10.Coremail.zhangkaiheb@126.com> From: David Ahern Message-ID: <9404e2d8-0976-1726-5f08-c277cdc14945@gmail.com> Date: Tue, 12 Oct 2021 20:33:19 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <3bd88b51.6c7.17c77339c10.Coremail.zhangkaiheb@126.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/12/21 7:10 PM, 张凯 wrote: > > 1) Below shift operation will set fib_info_hash_size to zero if there > are so many routes:  >   unsigned int new_size = fib_info_hash_size << 1; > >     This will wrap value of fib_info_hash_size, and a lot of fib_info > will insert to a small hash bucket. > so this patch disables above wrap. > 2) Check whether fib_info_hash_size is zero only needed after allocation > failed: > if (!new_info_hash || !new_laddrhash) { > > why not something simpler like this: diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 3364cb9c67e0..5c4bd1cebe0a 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1401,6 +1401,10 @@ struct fib_info *fib_create_info(struct fib_config *cfg, if (!new_size) new_size = 16; + + if (new_size < fib_info_hash_size) + goto failure; + bytes = new_size * sizeof(struct hlist_head *); new_info_hash = fib_info_hash_alloc(bytes); new_laddrhash = fib_info_hash_alloc(bytes);