From patchwork Fri Sep 15 19:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 140628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1263430vqi; Fri, 15 Sep 2023 12:10:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKQ1NbZ9CFAU3ccBeDxv4x9w0ytc5NYu6jhftUpjPeoGmdW29JNA/BcgHG851fK7K4aQ6r X-Received: by 2002:a17:90a:c917:b0:273:4672:98b5 with SMTP id v23-20020a17090ac91700b00273467298b5mr2262757pjt.42.1694805042101; Fri, 15 Sep 2023 12:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694805042; cv=none; d=google.com; s=arc-20160816; b=vfBNdN+PVqAiSqNaV8Cy3yeNUJH9ieQbS3HqK1x5HKqcLhQTlNFd2CuwuW1cT2LzKj dyoQLDbq7+sS4UJXz7e+0wS17qbQgKlAYSllBdGbkHBbVwOfTgDRZ1ohMJYdnesA4Qql sQDq9GQifvtq4XjHvB4Jg7ny03idI8BiJ5U6fKxDQr+dycNDeeoqDkIAWsyIvdky1BI6 psXWxF1hwkcsBZIHACj7eHJpgyji0mmNJWoCX8qnKFo/6IUVHfXW3vJAj8pwQggzDyHN QOj06xkJVGI4Wg4bOY7qlEbtxcrrozfKhHx+GYFJeqXZcc9+BZe51gpJAENbeqzv8UtM 4KEQ== 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 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id k26-20020a6568da000000b0057744d09d22si3714904pgt.85.2023.09.15.12.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; 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 2620:137:e000::3:3 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 21A048293C45; Fri, 15 Sep 2023 12:01:25 -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 S236932AbjIOTAw (ORCPT + 30 others); Fri, 15 Sep 2023 15:00:52 -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-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:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777131891801952218 X-GMAIL-MSGID: 1777131891801952218 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 Reviewed-by: Kees Cook Reviewed-by: Ido Schimmel --- 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);