From patchwork Mon Aug 15 21:40:35 2022 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: 597773 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 786D2C25B0D for ; Tue, 16 Aug 2022 01:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233545AbiHPBtT (ORCPT ); Mon, 15 Aug 2022 21:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233512AbiHPBs6 (ORCPT ); Mon, 15 Aug 2022 21:48:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD992036B9; Mon, 15 Aug 2022 14:40:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 22186B811FE; Mon, 15 Aug 2022 21:40:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBA9DC433D7; Mon, 15 Aug 2022 21:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660599644; bh=s1ysBUarhjxYEJL4ryDgOKJSJUjnZCoo74clBKJ7yNs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W9PFrRzkfJnI6SrnWoCVG5SqJNhu1B5NEPoyhp8D91e3ogQKqwHXEqkt90ffhnXlf qJMqJ+FDHdOWOYTENMc3DRbWLuMOa2ngAdL1NIss/wvQvBG8G6ua1oWpSM+/vq7tj2 81JiienoY6xTd5A2JSjUpSu4Zn1YPyP94sam4qHJ7H98nGEu0iYXhRfFuN0pAYq/Vd 42j2Q5hlQ6I0r9jpzaXgaETDQ1riXTBdlNKl/oO2wSa+CXNNcLiPnpe/V4oyVF8HpQ 1NfBSGb2nz1mGZ7hiVdDiZBB32PIYjax4U3xXdATGhdHbN7FdEc4PWHO4Gwq1ZmhJu rMCdU5/i2ZUNA== Date: Mon, 15 Aug 2022 16:40:35 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 1/6] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_FW_RAID_MAP Message-ID: <4495ce170c8ef088a10f1abe0e7c227368f43242.1660592640.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org One-element arrays are deprecated, and we are replacing them with flexible array members, instead. So, replace one-element array with flexible-array member in struct MR_DRV_RAID_MAP and refactor the the rest of the code accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(). Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/109 Enhanced-by: Kees Cook # Change in struct MR_FW_RAID_MAP_ALL Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - Modify MR_FW_RAID_MAP_ALL structures. - Revert use of struct_size() helper. Changes in v2: - Update Subject line and changelog text. drivers/scsi/megaraid/megaraid_sas_base.c | 2 +- drivers/scsi/megaraid/megaraid_sas_fp.c | 2 +- drivers/scsi/megaraid/megaraid_sas_fusion.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index a3e117a4b8e7..c06a346a3eaf 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -5159,7 +5159,7 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance) } else { fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + (sizeof(struct MR_LD_SPAN_MAP) * - (instance->fw_supported_vd_count - 1)); + instance->fw_supported_vd_count); fusion->new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT); fusion->max_map_sz = diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c index 83f69c33b01a..b2ec7a3f7650 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fp.c +++ b/drivers/scsi/megaraid/megaraid_sas_fp.c @@ -327,7 +327,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id) expected_size = sizeof(struct MR_FW_RAID_MAP_EXT); else expected_size = - (sizeof(struct MR_FW_RAID_MAP) - sizeof(struct MR_LD_SPAN_MAP) + + (sizeof(struct MR_FW_RAID_MAP) + (sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount))); if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) { diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h index ce84f811e5e1..5530c233fccb 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.h +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h @@ -942,7 +942,7 @@ struct MR_FW_RAID_MAP { u8 reserved2[7]; struct MR_ARRAY_INFO arMapInfo[MAX_RAIDMAP_ARRAYS]; struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES]; - struct MR_LD_SPAN_MAP ldSpanMap[1]; + struct MR_LD_SPAN_MAP ldSpanMap[]; }; struct IO_REQUEST_INFO { @@ -1148,7 +1148,7 @@ typedef struct LOG_BLOCK_SPAN_INFO { struct MR_FW_RAID_MAP_ALL { struct MR_FW_RAID_MAP raidMap; - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES - 1]; + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]; } __attribute__ ((packed)); struct MR_DRV_RAID_MAP { From patchwork Mon Aug 15 21:42:21 2022 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: 598062 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ABEBC25B0F for ; Tue, 16 Aug 2022 05:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233226AbiHPFTe (ORCPT ); Tue, 16 Aug 2022 01:19:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233204AbiHPFTM (ORCPT ); Tue, 16 Aug 2022 01:19:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DEB1C21DD; Mon, 15 Aug 2022 14:42:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE500B811BF; Mon, 15 Aug 2022 21:42:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5988DC433D6; Mon, 15 Aug 2022 21:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660599763; bh=J5sILHxjfHL2mngdVIkP+62Tsl5BM29kcszjyaZgtTM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ULAZ4sTT/Mfp7G7ebqcnzGlna8miB9S2AwB9BgcbB/JuXmMpPr7cfPCQnwDw7PMuA ZMxWtTbU5TDApU6vqxIgSdapoRSZRIcgecgILwrVPGCAkSP9N1toRhWTlCYFgKOPkS PXHu0z/Dva+XPvwEZn1vPXAtSVwNwqblnfTnwMaxxARol7mpnKEVU47iU8tOvLWCkd YqzYylwjgZXD1z+VyG9KUSYPZm0S5hfvUo4UszZr+v5l+NbvwC5r/Qp9nQHAnMk4CL 0JH4Jg6wuLFmPKnCphPsmLgXfp2n65rxQKEpr55wPUOPBWba5aFw+eTXMDjR88IElx ykiTveYvARyrQ== Date: Mon, 15 Aug 2022 16:42:21 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 2/6] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_FW_RAID_MAP_DYNAMIC Message-ID: <896476f8fe43cf83b491c6c13f59c9ace780d82c.1660592640.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org One-element arrays are deprecated, and we are replacing them with flexible array members, instead. So, replace one-element array with flexible-array member in struct MR_FW_RAID_MAP_DYNAMIC. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(). Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/109 Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - None. Changes in v2: - None. drivers/scsi/megaraid/megaraid_sas_fusion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h index 5530c233fccb..66e13b74fcdc 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.h +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h @@ -1053,7 +1053,7 @@ struct MR_FW_RAID_MAP_DYNAMIC { struct MR_RAID_MAP_DESC_TABLE raid_map_desc_table[RAID_MAP_DESC_TYPE_COUNT]; /* Variable Size buffer containing all data */ - u32 raid_map_desc_data[1]; + u32 raid_map_desc_data[]; }; /* Dynamicaly sized RAID MAp structure */ #define IEEE_SGE_FLAGS_ADDR_MASK (0x03) From patchwork Mon Aug 15 21:46:13 2022 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: 598064 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CBB3C25B0D for ; Tue, 16 Aug 2022 01:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243185AbiHPBzA (ORCPT ); Mon, 15 Aug 2022 21:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232617AbiHPByl (ORCPT ); Mon, 15 Aug 2022 21:54:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1641C21146F; Mon, 15 Aug 2022 14:46:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 95823B811FE; Mon, 15 Aug 2022 21:46:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D58E7C433D6; Mon, 15 Aug 2022 21:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660599980; bh=9P1wiCHMqEfEMRjp5RWcePkGLroiFvT2II+AyFuabVQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pN/UAeEWR9Cl72HCG6eavcTQAflelQE+1zXehSk9ZT47IZIlHVgTjYoi04Up2QF/g Q4VTLIjzsH7OR05f3XRTB6psxqkFDSccQgH3gPRAGePI3eXmMT4ScH5lu/+TT32oW6 9AsxpEFF9s+rehxFo+mJTLNtXomhXoinL6+OfE15YhQtbzhrcMaAsQALOiF1xlvDxZ 2i7CnO3wiIKmfI6nsGTjtChMBUo7UqfqbmqTRLqH0l8dSpcfVxcPPVHotXtQwLd/je iOrE6ljiNHJqe1TE3qkYgzwPTG0ku4RN3+Ey+vk60EkemJUynjYa+gjrcKIStJq9HB XeRnjA1BlqQeQ== Date: Mon, 15 Aug 2022 16:46:13 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 3/6] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_DRV_RAID_MAP Message-ID: <1448f387821833726b99f0ce13069ada89164eb5.1660592640.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org One-element arrays are deprecated, and we are replacing them with flexible array members, instead. So, replace one-element array with flexible-array member in struct MR_DRV_RAID_MAP and refactor the code accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(). Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/109 Enhanced-by: Kees Cook # Change in struct MR_DRV_RAID_MAP_ALL Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - Revert use of flex_array_size() helper. - Modify MR_DRV_RAID_MAP_ALL structure. Changes in v2: - None. drivers/scsi/megaraid/megaraid_sas_fusion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h index 66e13b74fcdc..df92d4369e04 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.h +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h @@ -1182,7 +1182,7 @@ struct MR_DRV_RAID_MAP { devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES_DYN]; u16 ldTgtIdToLd[MAX_LOGICAL_DRIVES_DYN]; struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_DYN]; - struct MR_LD_SPAN_MAP ldSpanMap[1]; + struct MR_LD_SPAN_MAP ldSpanMap[]; }; @@ -1193,7 +1193,7 @@ struct MR_DRV_RAID_MAP { struct MR_DRV_RAID_MAP_ALL { struct MR_DRV_RAID_MAP raidMap; - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN - 1]; + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]; } __packed; From patchwork Mon Aug 15 21:49:38 2022 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: 597772 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DACEC3F6B0 for ; Tue, 16 Aug 2022 01:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234315AbiHPB5K (ORCPT ); Mon, 15 Aug 2022 21:57:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234005AbiHPB4y (ORCPT ); Mon, 15 Aug 2022 21:56:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6301215F25; Mon, 15 Aug 2022 14:49:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E9E4FB811FF; Mon, 15 Aug 2022 21:49:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65C45C433D6; Mon, 15 Aug 2022 21:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660600184; bh=iy8yfgUtW5RIairW73K6gX9n22ly4FXl8t5qBi7ddOo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rFt1IIJhqPlHgnpNOeIr+MPhNFfGhte0Zuu8KuNySaxxuMZltDyq7TnXBKkM6Qood MCGefbwkTKeOfwL0+2Z8YHP5dzn06G/XmOGS2Kh6/QqIcuFx8PBeewhSLMpZPxq2pq QJCKnDFAL/5bsBQUZlrQz9GiP5YfwxUuILPhpLuhQs6EfHcPjhdql23ZWms6KGsOmO vHI01dtZmtoeUqaKwdnAtNlricdh5evSZiUMRmuQSuHvB9ZvB8kgKzkYTCLFMJ6dMH M0rcFYT4/ukCe/W5wx7Oy7CreXU5NgaEIKQuC2lnNfC+CCpuucWx9rxDn3gduat6Qe 26fwhOCEuFbMA== Date: Mon, 15 Aug 2022 16:49:38 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 4/6] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_PD_CFG_SEQ_NUM_SYNC Message-ID: <78e9261591db072b67fcf49f0216d7046a67ca6d.1660592640.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org One-element arrays are deprecated, and we are replacing them with flexible array members, instead. So, replace one-element array with flexible-array member in struct MR_PD_CFG_SEQ_NUM_SYNC and refactor the rest of the code accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays [0]. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/109 Link: Link: https://reviews.llvm.org/D126864 [0] Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - Revert use of struct_size() helper. Changes in v2: - None. drivers/scsi/megaraid/megaraid_sas_base.c | 4 ++-- drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +- drivers/scsi/megaraid/megaraid_sas_fusion.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index c06a346a3eaf..2dabe0b4823e 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -5795,7 +5795,7 @@ megasas_setup_jbod_map(struct megasas_instance *instance) u32 pd_seq_map_sz; pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + - (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); + (sizeof(struct MR_PD_CFG_SEQ) * MAX_PHYSICAL_DEVICES); instance->use_seqnum_jbod_fp = instance->support_seqnum_jbod_fp; @@ -8048,7 +8048,7 @@ static void megasas_detach_one(struct pci_dev *pdev) megasas_release_fusion(instance); pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + (sizeof(struct MR_PD_CFG_SEQ) * - (MAX_PHYSICAL_DEVICES - 1)); + MAX_PHYSICAL_DEVICES); for (i = 0; i < 2 ; i++) { if (fusion->ld_map[i]) dma_free_coherent(&instance->pdev->dev, diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index e48d4261d0bc..f17ec83f7c98 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -1310,7 +1310,7 @@ megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)]; pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)]; - pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1); + pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES); cmd = megasas_get_cmd(instance); if (!cmd) { diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h index df92d4369e04..49e9a9048ee7 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.h +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h @@ -1249,7 +1249,7 @@ struct MR_PD_CFG_SEQ { struct MR_PD_CFG_SEQ_NUM_SYNC { __le32 size; __le32 count; - struct MR_PD_CFG_SEQ seq[1]; + struct MR_PD_CFG_SEQ seq[]; } __packed; /* stream detection */ From patchwork Mon Aug 15 21:51:36 2022 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: 597770 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A6E9C25B0F for ; Tue, 16 Aug 2022 05:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbiHPFXz (ORCPT ); Tue, 16 Aug 2022 01:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231585AbiHPFXk (ORCPT ); Tue, 16 Aug 2022 01:23:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 342EBC13; Mon, 15 Aug 2022 14:51:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C61F0B811C1; Mon, 15 Aug 2022 21:51:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18BC8C433C1; Mon, 15 Aug 2022 21:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660600302; bh=ort1VpN7VBYM3KDJV+dEWBj27en+cZk8wTHPLkd0HQ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=V6MMkkaJ4eu1Xty7dVN4Dk3/poYM21tH0ERMKZ1HEZ3rCVFQ34+mKM/z5TNNjqVNP SM3BvLgiKvUSI/D0tqaXAbvFnLbQRXsW92v02sJP4BYFkAVkeSCr4cyGQrhkGDed4k Aea+grLX2CwBcgAM76z9JUgJUbiEbk91+5BSqUoYevGqeOMUTJo+2pKtcko+/Qcl9p leqrt7ct/k3/zjATZ3JeqTXHqpLVvcd4GngjNDMDPpl7YdyBTsZsOBvH2CCFHDai5n WgxpqBJ8mq8tHgXhyZU2n0zj7TxZMyRo2PKWp3zYgzKUYwOM+wfsYlqWe5GAHy2Rv2 5icoHVkKXRNQQ== Date: Mon, 15 Aug 2022 16:51:36 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 5/6] scsi: megaraid_sas: Use struct_size() in code related to struct MR_FW_RAID_MAP Message-ID: <1211398fb8f7ab332a93f4f8f1a63e8168dbd002.1660592640.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prefer struct_size() over open-coded versions of idiom: sizeof(struct-with-flex-array) + sizeof(type-of-flex-array) * count where count is the max number of items the flexible array is supposed to have. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - This patch is new in the series. drivers/scsi/megaraid/megaraid_sas_base.c | 6 +++--- drivers/scsi/megaraid/megaraid_sas_fp.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 2dabe0b4823e..09eef1bef430 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -5157,9 +5157,9 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance) fusion->current_map_sz = ventura_map_sz; fusion->max_map_sz = ventura_map_sz; } else { - fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + - (sizeof(struct MR_LD_SPAN_MAP) * - instance->fw_supported_vd_count); + fusion->old_map_sz = + struct_size((struct MR_FW_RAID_MAP *)0, ldSpanMap, + instance->fw_supported_vd_count); fusion->new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT); fusion->max_map_sz = diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c index b2ec7a3f7650..da1cad1ee123 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fp.c +++ b/drivers/scsi/megaraid/megaraid_sas_fp.c @@ -326,9 +326,9 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id) else if (instance->supportmax256vd) expected_size = sizeof(struct MR_FW_RAID_MAP_EXT); else - expected_size = - (sizeof(struct MR_FW_RAID_MAP) + - (sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount))); + expected_size = struct_size((struct MR_FW_RAID_MAP *)0, + ldSpanMap, + le16_to_cpu(pDrvRaidMap->ldCount)); if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) { dev_dbg(&instance->pdev->dev, "megasas: map info structure size 0x%x", From patchwork Mon Aug 15 21:52:33 2022 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: 598063 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA83C25B0D for ; Tue, 16 Aug 2022 01:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233478AbiHPB7g (ORCPT ); Mon, 15 Aug 2022 21:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233379AbiHPB7R (ORCPT ); Mon, 15 Aug 2022 21:59:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B7610777F; Mon, 15 Aug 2022 14:53:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9558361035; Mon, 15 Aug 2022 21:52:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6D74C433C1; Mon, 15 Aug 2022 21:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660600360; bh=v73qbvSX6GJicRQwVqQQUy2yDqvcefvj35hzxha3Ko8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CwddLgwnQwPWoZWTgO8y6rBBleH3lFDakZmISIh2bidn8E4Ny/XWI1/bDLMrJ/WMS +8a554SFqvUvUtpFJgB/83fpwbH3mxzJe2ZUq5ftR+lo+awqDKgHKvgayEbki4M47U ntJ6FslzTlKfJzlGVfj72kcKwQCysBJiEssyIMKPoM2c79YNMMQbL/meXlADO+QvFn 0SJK8EKesa+bxvnOTXj1zQDm7bzB8CubK/5YhzaWABzIV9x84KkZUBuHelPvBAyxDE pjnxwBmU3FFcUB0ZJja0vV72vrCrTWSZVFg6PkcjkhHITZ2UsQGtLQnF3fR/Gw7W0h DVBH/lkRsfBjg== Date: Mon, 15 Aug 2022 16:52:33 -0500 From: "Gustavo A. R. Silva" To: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH v3 6/6] scsi: megaraid_sas: Use struct_size() in code related to struct MR_PD_CFG_SEQ_NUM_SYNC Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prefer struct_size() over open-coded versions of idiom: sizeof(struct-with-flex-array) + sizeof(type-of-flex-array) * count where count is the max number of items the flexible array is supposed to have. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - This patch is new in the series. drivers/scsi/megaraid/megaraid_sas_base.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 09eef1bef430..d57cb787db0b 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -5792,10 +5792,10 @@ megasas_setup_jbod_map(struct megasas_instance *instance) { int i; struct fusion_context *fusion = instance->ctrl_context; - u32 pd_seq_map_sz; + size_t pd_seq_map_sz; - pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + - (sizeof(struct MR_PD_CFG_SEQ) * MAX_PHYSICAL_DEVICES); + pd_seq_map_sz = struct_size((struct MR_PD_CFG_SEQ_NUM_SYNC *)0, seq, + MAX_PHYSICAL_DEVICES); instance->use_seqnum_jbod_fp = instance->support_seqnum_jbod_fp; @@ -7974,7 +7974,7 @@ static void megasas_detach_one(struct pci_dev *pdev) struct Scsi_Host *host; struct megasas_instance *instance; struct fusion_context *fusion; - u32 pd_seq_map_sz; + size_t pd_seq_map_sz; instance = pci_get_drvdata(pdev); @@ -8046,9 +8046,9 @@ static void megasas_detach_one(struct pci_dev *pdev) if (instance->adapter_type != MFI_SERIES) { megasas_release_fusion(instance); - pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + - (sizeof(struct MR_PD_CFG_SEQ) * - MAX_PHYSICAL_DEVICES); + pd_seq_map_sz = + struct_size((struct MR_PD_CFG_SEQ_NUM_SYNC *)0, + seq, MAX_PHYSICAL_DEVICES); for (i = 0; i < 2 ; i++) { if (fusion->ld_map[i]) dma_free_coherent(&instance->pdev->dev,