Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4786352rdb; Fri, 15 Sep 2023 12:10:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpoR55zgD6rXcuIMeupd1Aj/TBiFgUqBtxdXCOyE7LdhVHc6ItAQaEOZ5T/ZYH8iXbjycr X-Received: by 2002:a05:6a20:a127:b0:13f:b028:7892 with SMTP id q39-20020a056a20a12700b0013fb0287892mr3355591pzk.2.1694805040530; Fri, 15 Sep 2023 12:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694805040; cv=none; d=google.com; s=arc-20160816; b=l9qlZX9bD74fKjjugr/6lWM+teL4eQ2XK9irMTv9o0QYBWj7rmMCk69nwje0peSWoq 70Ijp3pOQchaBvrf8iasSwSwhhWigukIHZuJkQkTSAsq+OABrss2fySf6oViJV9txQrP 0MrCfj4eh9wPKD2jFKqIE9iAzjvfTz8RhaDt9HXpTYeLtTYFvBS1SM17dmz99gUf7ROd dSgDI1DEhY/h8gHgBxXpcf6x9lxPCmH4Z0ODIkr22w1v3nQghDgQPtUNlsDTpUj/abz8 tu8kUcY3FNI/NhYlcQrBA83b5kVjISidtwiqZ57yLvc0LuPep7aKyuhb3jsyQL/LSFCY ZkZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=KVbzJRGcPIX3Hgv1j9XcXlc9qe8rtEL0QXWefF1ivYA=; fh=o2oofC3V0hbua+fCdFxJGwVxMzy/N3Q9DFRI35oWZ9E=; b=kLgMTey5/+wYcm2M2005skGG7tNIfEI+e4ZSlaP4mjTxJtloU+tDYtd8Kvqqf1spZ8 h8Dx/7n0tPJjxoCToWuilxCUNObcRHaTQtLfyftpDsR23Db2xqCsXKNtrHL/YroiVSwe Mlymg2Y0HHoUHCjNr0ZdFHVUw8vV1uCEud8H42UPMapeRJM5yoSXLxqIuaxOe7PS2Xhm oVf3q0Yl+cfJd2BfY7+PCE6d+SPZezxrQoacURDXOR6WP6qn1F1nHJsIPWfPff5d7SKn Woiow6rbo+f5pNMfCe34QTVCFdXVw2ejO2yF+tuSvbaHJFkgcpG515J3WCGX6a5dq6SG KEDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dc8ehB5S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j190-20020a638bc7000000b0057795a17f4asi3770596pge.177.2023.09.15.12.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dc8ehB5S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EF9C9829325E; Fri, 15 Sep 2023 12:01:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236910AbjIOTAv (ORCPT + 99 others); Fri, 15 Sep 2023 15:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237067AbjIOTAo (ORCPT ); Fri, 15 Sep 2023 15:00:44 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930BA270A; Fri, 15 Sep 2023 12:00:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF916C4339A; Fri, 15 Sep 2023 19:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694804429; bh=MwYH2ME9s5GR5J22JIc9pHMsg8/BLoZqEWB3h/MNKug=; h=Date:From:To:Cc:Subject:From; b=dc8ehB5SmqvG+DNp8dNDSxMhG6TsX6M2Tx1knthy1ka7AXh1nnnTV+JKs/Ham9X1W 3md8hC7WO1cITCN5OrswcKVsh5Fy1W7DIf5Ax8oN5FfaBJ5yZWyR3k9tEURxkhX9ZF qNGNd+NHhuu+6+i4FytLLtQYvu8N7xtCcLFQFfIWMbuR28NGsHHVMMqeU7Z5M+OjOw 7HgYmICKCdR35+1RWyxVxRCMOFdSPFz+StmTuRGIBMd2E0SKfLvdGwAL+AtAPECYAo kTi27M/ImM9c0gDUg/Q8A+JdhRNsC1gbUNUaw0o3YyuJkPjVDCUotXiTehzBM32kWj FeCGvVBwtoKhg== Date: Fri, 15 Sep 2023 13:01:23 -0600 From: "Gustavo A. R. Silva" To: Ido Schimmel , Petr Machata , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] mlxsw: Use size_mul() in call to struct_size() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:01:22 -0700 (PDT) If, for any reason, the open-coded arithmetic causes a wraparound, the protection that `struct_size()` adds against potential integer overflows is defeated. Fix this by hardening call to `struct_size()` with `size_mul()`. Fixes: 2285ec872d9d ("mlxsw: spectrum_acl_bloom_filter: use struct_size() in kzalloc()") Signed-off-by: Gustavo A. R. Silva --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c index e2aced7ab454..95f63fcf4ba1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c @@ -496,7 +496,7 @@ mlxsw_sp_acl_bf_init(struct mlxsw_sp *mlxsw_sp, unsigned int num_erp_banks) * is 2^ACL_MAX_BF_LOG */ bf_bank_size = 1 << MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_BF_LOG); - bf = kzalloc(struct_size(bf, refcnt, bf_bank_size * num_erp_banks), + bf = kzalloc(struct_size(bf, refcnt, size_mul(bf_bank_size, num_erp_banks)), GFP_KERNEL); if (!bf) return ERR_PTR(-ENOMEM); -- 2.34.1