From patchwork Thu May 11 06:06:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=MwzeauAO; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1cj672wz20fn for ; Thu, 11 May 2023 16:06:44 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRn-0005gJ-Il; Thu, 11 May 2023 06:06:39 +0000 Received: from mail-pf1-f177.google.com ([209.85.210.177]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRj-0005f8-L9 for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:35 +0000 Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6438d95f447so5717687b3a.3 for ; Wed, 10 May 2023 23:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785194; x=1686377194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=D/VPjLzRgnO8mXZxO2EimGAITjfuK8Mc6wFGhcyK4cQ=; b=MwzeauAOCf91aJNrIddFTwOcy8HM8enxp0h/WeeIDJ4BVaF/Bt9umLlfu4gNUhHmqk F5AQV2PtUVqVgNB6x1hthFiM17d0aNEcpWTVGgjo6JsctpToduWsCp5h2c4O3PTSGNPY fvKDpljYh2siPdx0VZ/PceqSKxOQWEuyAOq2fVvY87UMTMGa6laTjmhCPZ6C1yS6+PaD Ags+jMKizSjELkT5XczgUR97JVxeviR9zBKroXgX3+sJKQd7hfr9LadONJApQ+otXsd5 PQF/9iRN90dVl4renhb3k5MO7H9urKBo3KZUqULTAFX5mB4a9nV8UHPSQCvsfqPBNJvw lDRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785194; x=1686377194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=D/VPjLzRgnO8mXZxO2EimGAITjfuK8Mc6wFGhcyK4cQ=; b=g+xR05OllgTaIhGj+4R6bWQA+e8uQyZgYaigjwBspQNNAbu0BfIEvbuFLNX+tChsd8 T9cEunb0N+rSnyRKr+ZKAtqjExvIvf6jWy8TL0U3suw915zZuzlnaCViPQNTU9UE35cY 2XbYl9xvbA2C1DlMO994Xg63/jJH9wgxgdFlurfdH4mbVSNiX64YzbfIjgGz4JMFDlZ4 BBUyK724IRdNxANDZC6RavXwhFLhGZxihk+AK2VWnJol8RVS/y+qF5NQJpPk007a7Nqu c8In9QLwSChs6i8iQ1l3/R3FJ3UxjRzsNskDLox3lC/8anaNUff0w3nK76bmBc7Hzdjm 3z0w== X-Gm-Message-State: AC+VfDxQpqXknUoOeuVJtFLQxlXZcAhWJneeBrCn2yKPV4bmbIw+Ej4r dD9xChOxvYTuZhEVPRqGcy8PTzdtBTFOjw== X-Google-Smtp-Source: ACHHUZ6i7sXfxCWb17Os/MwHNJJfkeQ5yJuoJdISlSF4aAkwY/iIxoIUZ2F/XNaWzD/OlYwNZYAUEw== X-Received: by 2002:a05:6a00:1787:b0:627:6328:79f1 with SMTP id s7-20020a056a00178700b00627632879f1mr30041210pfg.34.1683785193592; Wed, 10 May 2023 23:06:33 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id i4-20020aa787c4000000b0063d2d9990ecsm4496183pfo.87.2023.05.10.23.06.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:33 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/6][SRU][K] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_FW_RAID_MAP Date: Thu, 11 May 2023 14:06:23 +0800 Message-Id: <20230511060628.48935-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.210.177; envelope-from=acelan@gmail.com; helo=mail-pf1-f177.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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 Link: https://lore.kernel.org/r/4495ce170c8ef088a10f1abe0e7c227368f43242.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen Enhanced-by: Kees Cook # Change in struct MR_FW_RAID_MAP_ALL (cherry picked from commit ac23b92b27e32f1ff331350342ce9f2ee9d0ab0f) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 0917b05059b4..da3647682dfa 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 Thu May 11 06:06:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=QFT3PHP1; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1cm5J4Gz20fn for ; Thu, 11 May 2023 16:06:48 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRq-0005iD-PV; Thu, 11 May 2023 06:06:42 +0000 Received: from mail-pj1-f41.google.com ([209.85.216.41]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRl-0005fU-J1 for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:37 +0000 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-24dea6d5ce8so7729562a91.2 for ; Wed, 10 May 2023 23:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785195; x=1686377195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Kq8fIxWZ73xzoP4JxdvgImV7R8HDIy4bF1x9XLL2mNc=; b=QFT3PHP1evfSK8VXdjxWaBR4oJ9fL59nR3Z0xyRwQEZDf+Gx9JN+DNTFVJcVV7njkK nISvAMkDlxIqMm7BWcysPVNDAvTptMV5Pm0E9ehUp2g61wr60PmL/cstOqbzM6Durx5y vAziUs4JO3Vksj5nVyNnd/pUExE5ACNQjTjT6rIhtrE+BfcjWIsjJqIwKqV2WX1zGAc5 bCrXnDcuXDm8OIPo1bPHIF8GaGzxgvE/K8Oitw6ybrm5kWyEEsCXBq2T5S01Zy85fEnN tccRQjv6t0WhStJw2yzG2SdKdI/96LJPzfLLdjxCF6LEFXVqmtfVsGeW5/ENInK4g5HL yc/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785195; x=1686377195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Kq8fIxWZ73xzoP4JxdvgImV7R8HDIy4bF1x9XLL2mNc=; b=j8zvQNxc92YRV5/hFM5Gt+E1YBiEiXdLQqsPZD6lmiq1CRT+1/GPXr2HdILfy2G9pq FxQJwI9spXeHS2jx7afSp89jHDB8zHQox30fzsF6qbJCSbY+zecJlx9VQftEebS8OJAL /f7BtUc73du4PGKeXqpmaikP6YslcFGeao8mWb06eipQQi/wWjanYeW6Jw+70utDmbCr dQeERlR4bU4eLAo9BefuHqXuGZLlVIgOndNqT34SwGEajF0hWPynoz0MsZyX+DNCNwRJ zCrhMMsIo6z4uEiD8LRuTzCWUlrHC0o5YJz/DhlyrmmfSTPG/ggb5OgP7vfGyxCGKom2 YUww== X-Gm-Message-State: AC+VfDwXXFHnAHyQF4e5iUtJZO9ZvDRE+5TMSEvW5NmdT82OaQc0m3R5 aPsP0oFGte8g2uoY/Y4dazLd+iyIepxquw== X-Google-Smtp-Source: ACHHUZ4hAjSHEPWyW73CgCY7qoQOMg7TGVRvrj26xYvN5ujB0Lz/VNFw1Xbdr/EjCtc/t9lcRhm3og== X-Received: by 2002:a17:90b:1d87:b0:24d:fb82:71ab with SMTP id pf7-20020a17090b1d8700b0024dfb8271abmr20503723pjb.26.1683785195515; Wed, 10 May 2023 23:06:35 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id j9-20020a654289000000b00520b677c645sm4007544pgp.41.2023.05.10.23.06.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:35 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/6][SRU][K] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_FW_RAID_MAP_DYNAMIC Date: Thu, 11 May 2023 14:06:24 +0800 Message-Id: <20230511060628.48935-3-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.41; envelope-from=acelan@gmail.com; helo=mail-pj1-f41.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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 Link: https://lore.kernel.org/r/896476f8fe43cf83b491c6c13f59c9ace780d82c.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen (cherry picked from commit 204a29a169f4c80aa3b7feb41c45cbd6833aba21) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 Thu May 11 06:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=B7Bz+MBX; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1cp5Tyvz20fn for ; Thu, 11 May 2023 16:06:50 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRs-0005jK-1o; Thu, 11 May 2023 06:06:44 +0000 Received: from mail-pl1-f179.google.com ([209.85.214.179]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRo-0005g9-3s for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:40 +0000 Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1aad55244b7so62757205ad.2 for ; Wed, 10 May 2023 23:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785198; x=1686377198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=VzBxr+7D0MtTLEkY+ShKotkDN7J3Jb9hQ9PcvT64Hnk=; b=B7Bz+MBXx0kyIWDSClKjwgclta+dx6EiKRSHAZ2doinPX9zzp6igBwZ96Md5trvUbp H3XO1bP8YIL+YZAwm2M8jkYGbZyS6YPVLTF1pWTs8DLJ1/EqvMFSZ/57w6j7WwuJWS54 M5lXDZXZDmhY0GgjqVuQcDLZR1UKUQmjN7Tw4eAFlcoo8lSFTGPODactPw+bHEYdUnFh qXSu+ALAQFzyG8QzLMonj4jQb2+XebdVz6EpGKdzTC6BQs7V+twpXEvFXDRC+9nfN7ca z0NCYyzMSyuO+AV0BQF/ddYf6EKA6mENnUIdvX/Zo/xLlMXqZ9J5aHzNjD+dUuZu+rZo jyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785198; x=1686377198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VzBxr+7D0MtTLEkY+ShKotkDN7J3Jb9hQ9PcvT64Hnk=; b=koz2xDwySb29jmpkmTl3Ub36VzO0IB+uz377P/OVT88YSoDFghjoHoDxSEIYZdur4U 9UbYdWC+Zg7g8rh9E8nPFJgP0vfQigj5S8fARSeE+lIEyIk9N/wPuIPfc6xdu+zSTjgi SrheDKsRkMADGkmv8VsfzuXlYg4kKCz7tVhIGmrbfsHWAaG/8xzvczQKVCOfiN7v+CZZ LBhIyIWie7rCiwcl4jrBcR5zomVNIwZ5OJWEZFzv33ME9V3Q3PTIn+X32i1oIxxmN0W1 RZ84IqRibliDYL1w+/xvau2hCMn4uXThsg0xRnZ9vRJWU6qR5FBMq4OFun0LJwYqUnUB 56wg== X-Gm-Message-State: AC+VfDziMOzplCshRoqNy9OiK9J3NgNWfEJMcv8c16nBELyXLHSuMODR ZCzQiKYPTXkRFJiTh4auvG006XgIp5XHCg== X-Google-Smtp-Source: ACHHUZ44OysIeFObPMkcPJdWypFTEHz0HPJwkA9RoOc+RS/fvDbqHN8uDcxAAcWvcFSCGG2UrZQT6A== X-Received: by 2002:a17:902:f683:b0:1ac:8148:8c40 with SMTP id l3-20020a170902f68300b001ac81488c40mr16013885plg.53.1683785197892; Wed, 10 May 2023 23:06:37 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id i6-20020a170902c28600b001a52c38350fsm4888624pld.169.2023.05.10.23.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:37 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/6][SRU][K] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_DRV_RAID_MAP Date: Thu, 11 May 2023 14:06:25 +0800 Message-Id: <20230511060628.48935-4-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.179; envelope-from=acelan@gmail.com; helo=mail-pl1-f179.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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 Link: https://lore.kernel.org/r/1448f387821833726b99f0ce13069ada89164eb5.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen Enhanced-by: Kees Cook # Change in struct MR_DRV_RAID_MAP_ALL (cherry picked from commit eeb3bab77244b8d91e4e9b611177cd1196900163) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 Thu May 11 06:06:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=gOjtF2bs; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1cs5Wgkz20fn for ; Thu, 11 May 2023 16:06:53 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRu-0005mE-I8; Thu, 11 May 2023 06:06:46 +0000 Received: from mail-pl1-f170.google.com ([209.85.214.170]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRp-0005hD-Nf for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:41 +0000 Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1aaed87d8bdso58510255ad.3 for ; Wed, 10 May 2023 23:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785200; x=1686377200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=QbEb12rBJqSSsG57RTP5Cwu4uEaDyDUHjTPVrZcDfYc=; b=gOjtF2bsOe0R9srPoYyUFSjHJtdAQMp3mbCwvMGNXrdcJFv43Q/rkagnlC2NHXQ5QH aVwjnM2CsmocawoAEFQ1ZmUFOuQ53NaG8WigVE/sFBL6zj7eAsDA/dIZjF/0UoAeUkIp h5QIkVk9FGpnpWEOXHprKcZtrkSvnVLGBjrplDbo2ol+1aCYzUBrbsv2g3daTlj/66Ul b5iPYCK9WQvyLOYodyIQPvve6T0ZdFECBjfa153/tY41OOgw+lxFXjEg3hgjK9dd1wp9 Ja0gP2dLp550fKXP5O5p720SZZfvplP3tVmIsyZqGvqb0vJjHiT7Ca/nUMod5WhI8hDD hh3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785200; x=1686377200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=QbEb12rBJqSSsG57RTP5Cwu4uEaDyDUHjTPVrZcDfYc=; b=CUpsyQME2RPF3v/FSqDgyNm21Uca+zmAgdEg3Iz+iW7qUsjPNQj3E6bolN71Kk/ETw jSg5ttG1iH/aNTAbYqkPOt624CNOL8N1tRNb5O4df+UIwmrCYxdqC5vzSAZ+piQ1N5I0 UOeIhj6zsc08LaXTVlwTU1w+I0HZs94u/KBtulGiQmNa/XA0bUcRoMf5KO9FyG5FPItl LW3Um/tr6UR+uZQpQoRYTF/e35NmCC+dpR3CmNk7Df3JJR9qtND6onMlcyqt4bQFJdu5 y7gLF1gEYREuPCHY1fFFaVN0b4ZPoa4+wJIe1alwu99N/GbJbSq+cXM87IlDXvTNSX4L Ascg== X-Gm-Message-State: AC+VfDwRgU15pat0MgdZnjEFyFsuPPlMJDiv0cHKf9LoGeL+/nwPakM1 9MvJks6oRtmMUr1+zNW4ei2R+RnGXMEFZw== X-Google-Smtp-Source: ACHHUZ6V6Y6VbPNu69RBaKKUKhMJJF/mQw9lYcWkwYtuesRPgtbsB7cGDQAbiCCTsJTy6KH6cLVbcA== X-Received: by 2002:a17:903:41c3:b0:1a9:6b57:f400 with SMTP id u3-20020a17090341c300b001a96b57f400mr25863930ple.16.1683785199734; Wed, 10 May 2023 23:06:39 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id d23-20020a170902729700b001a216d44440sm4892354pll.200.2023.05.10.23.06.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:39 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/6][SRU][K] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_PD_CFG_SEQ_NUM_SYNC Date: Thu, 11 May 2023 14:06:26 +0800 Message-Id: <20230511060628.48935-5-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.170; envelope-from=acelan@gmail.com; helo=mail-pl1-f170.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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] Link: https://lore.kernel.org/r/78e9261591db072b67fcf49f0216d7046a67ca6d.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen (cherry picked from commit ee92366a8439856136368a106e6e08ffa8306a1e) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 da3647682dfa..cbd5e54de25b 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 3e9b2b0099c7..b7ab4ecdaaa5 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 Thu May 11 06:06:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=jL21Fytv; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1ct31mrz214l for ; Thu, 11 May 2023 16:06:54 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRv-0005no-LB; Thu, 11 May 2023 06:06:47 +0000 Received: from mail-pf1-f174.google.com ([209.85.210.174]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRs-0005hy-2Y for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:44 +0000 Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-643912bca6fso6537700b3a.0 for ; Wed, 10 May 2023 23:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785201; x=1686377201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=iMNhI3sa8xXu48yyV5+py/N5Hepng+AD9/1OoZP91qM=; b=jL21FytvfQwGOMR/w5puDhP4MObCmVei3fces9QYi7rtgpIK5e5QQQRFD0fJgZ4w1k H4bCNP/jnTn5mvGlPJgYjklduqA2SzSNy9O4FNK73DysLfVbNeiV/Yi68mHGcOBXBOhJ TLK3SMXWbKGIK0V7BAhWFQwpCcC6wNKQiqjtfwyi4Kb4Q5yByrCBOGznAslVcfU18aiB q2ckwenFeohhvy9mpen7MyIN4EgBeRR6pb9/afR95RbKs2p8nv+Fu9Kd4LpTxAM27M1R 2F5cx8hxQA6HNTTuMI5zOQE5xUSw/DiW1Tg6zUa6o6srf46Hs9rSh6Jqs1rC88OdgsVz nuSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785201; x=1686377201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=iMNhI3sa8xXu48yyV5+py/N5Hepng+AD9/1OoZP91qM=; b=e2bqkifsmAUTf6OVLhe5wpsnhxPEuXOC6DXOCboJDAoZqLVg31wNmzBuhNilHo+9o1 ayYEtSx+qv4nXxtD0qz3ZXVi6myg8lmdvOTMQpXQztTjBZuZE8r2T/Q2BC5qn+JmsmIK 3kQw26CyKXdjIf56kjejVMNG7W2pQmsOE9sX4RKHH9YhxbpnUkcEtmcMDxhZAAcPo1fR qWHlmx1sAUcPCIMaSASg97XWfsJBL7j6EOb9wr2nvHnH9mDim2hTXAb/lOEzZts7eKBb 7Pl6KDB+TjCsCZ/f2zE+EuYZKLm40QcUWKD0m9Cc7KmspQtft1FBLiXuZHSa706ZoTgM XBbA== X-Gm-Message-State: AC+VfDyBVNufbPnHkR+cx1XzDvcI5AO+p8FNC7UF2Dz0SVC01TL7Bnwx LdSSrOZnQoZnQ+5uwCj/ZBiRvbSj3MtVYQ== X-Google-Smtp-Source: ACHHUZ5B0p9cK+22/qyZ8Tqo5zHgczSECPPHX0DjMCZiIEqK1Xiw6uKdLPrlEPVaj+0NPATimJYEWw== X-Received: by 2002:a17:902:cece:b0:1a8:626:6d9d with SMTP id d14-20020a170902cece00b001a806266d9dmr26842607plg.62.1683785201470; Wed, 10 May 2023 23:06:41 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id x1-20020a170902820100b0019e60c645b1sm4905356pln.305.2023.05.10.23.06.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:41 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/6][SRU][K] scsi: megaraid_sas: Use struct_size() in code related to struct MR_FW_RAID_MAP Date: Thu, 11 May 2023 14:06:27 +0800 Message-Id: <20230511060628.48935-6-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.210.174; envelope-from=acelan@gmail.com; helo=mail-pf1-f174.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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 Link: https://lore.kernel.org/r/1211398fb8f7ab332a93f4f8f1a63e8168dbd002.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen (cherry picked from commit 41e830269d68a07b3e9214449b9ff0be7a3cfda5) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 cbd5e54de25b..861a77eec908 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 Thu May 11 06:06:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1779787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ZamIR4fr; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH1cw3PCYz20fn for ; Thu, 11 May 2023 16:06:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pwzRy-0005sA-4M; Thu, 11 May 2023 06:06:50 +0000 Received: from mail-pf1-f174.google.com ([209.85.210.174]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pwzRu-0005jN-Rg for kernel-team@lists.ubuntu.com; Thu, 11 May 2023 06:06:47 +0000 Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-643ac91c51fso4940917b3a.1 for ; Wed, 10 May 2023 23:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785203; x=1686377203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=IikuzzIl34QbbSFZOMShSI2RlSdxeQJvu21XBkCGsHU=; b=ZamIR4frbWrxkDyzJYqdql53ygSXiW3NaDd20qfaEoZD9lvFu5cZDOimkyBKdLz29s KPbe2+oEioghiInTRrfJo6BwNEtDoE0EKAF0Y1c8lG1lNHI4FgPL+antZooxUzAR16Zp 638QwVFA00Q2A1QYtgx0fG4WLiLUfkNWaU4VUZOjTgkKE7tzWFTIGVoRFzatrzwAHGQ/ OkTg6B23kr1rmh00QHgIqgPHuUBFXUPoMOteBznn9UKjIbzVBZWCVO5n8bekI/sQKxKV Mfa96t3LF2VWe/x6fHLqGfA4tg32qTNuOY+OR6ONYpXrOTyoCByDoI1XJpkb36jLbwvt FLgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785203; x=1686377203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IikuzzIl34QbbSFZOMShSI2RlSdxeQJvu21XBkCGsHU=; b=cTNXjhXLWWwmw1KU/jXMumTiYkZWTTl1EAU7BMdghyFOSmQsu1sQWYrbyc56QWL1zU ttcskrfu7+J1I4kdZs70sutMNZu6lqSBR39/1CinSQtHcnEWRrrQvOzWUHsbhv4X3pc2 u3JY2m0THt/Hk1uHKZJgpNFTHFFdQA37irbHWhYVu7DWs1KlUPpHBK3JSD2Jj5U7jMwO amLfXvyvfl2CBzeZKnIANTCe8kbB1d3kYtjsEVtyA0nDkC555Nm1mTE6K27ftrWGGW/M Fbn9rvUcbHvf55/miVXmqxSoYzatx5RQcsC0k+kxG9GnKCOJ2pxlQS6sYP4DeZhc82x1 85Hg== X-Gm-Message-State: AC+VfDx2fJI3N3GV0+0vAC1oczwfjhQhBdudoPvcJ04Xc/tovS/0PgLf hudatS/C1Br5Xm+31P5VsoxaQjwcYCGUeA== X-Google-Smtp-Source: ACHHUZ7b4hfBQchzcVyqYUX2WvIYQDfEvbN7sRX4Sy2kQ20PntpuXcYWlMcnjH6lqmWLjQ5iaIz8cQ== X-Received: by 2002:a05:6a20:9191:b0:f5:e534:3e52 with SMTP id v17-20020a056a20919100b000f5e5343e52mr27768663pzd.37.1683785203246; Wed, 10 May 2023 23:06:43 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id x12-20020a62fb0c000000b006436ffa3dc4sm4511094pfm.24.2023.05.10.23.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 23:06:42 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 6/6][SRU][K] scsi: megaraid_sas: Use struct_size() in code related to struct MR_PD_CFG_SEQ_NUM_SYNC Date: Thu, 11 May 2023 14:06:28 +0800 Message-Id: <20230511060628.48935-7-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511060628.48935-1-acelan.kao@canonical.com> References: <20230511060628.48935-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.210.174; envelope-from=acelan@gmail.com; helo=mail-pf1-f174.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Gustavo A. R. Silva" BugLink: https://launchpad.net/bugs/2008157 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 Link: https://lore.kernel.org/r/b215f4760f0e8fbe5fc35be20f2487e89924424d.1660592640.git.gustavoars@kernel.org Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Martin K. Petersen (cherry picked from commit 48658213202c4f48ef34b43b9b6f60af8b67fb8a) Signed-off-by: Chia-Lin Kao (AceLan) --- 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 861a77eec908..dc20e669337c 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,