From patchwork Wed Jun 21 20:27:20 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: 111307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4641816vqr; Wed, 21 Jun 2023 13:57:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6I349zLKVucV7peAf1otqLLExwjaAsn39TX/PTIZ776+mXFgwdt0oDvF8f/0S9gV504XBu X-Received: by 2002:a17:902:e807:b0:1b3:d33f:917 with SMTP id u7-20020a170902e80700b001b3d33f0917mr14567738plg.49.1687381075308; Wed, 21 Jun 2023 13:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687381075; cv=none; d=google.com; s=arc-20160816; b=zdqYJWZr75nPsfJXw7f5oiFEJv/B1z2VXlYxnSmUFQjHkE5uMctRwyTFSscRHE0vku CHMteDTZAzWxaoVmGDww7OCr4BkGcm7KMdPH38k2w8xh0fw9RUkpbb6AHRpXXl4jBPGY 5WIT56+HvnvvRQ2e7yUhVvmAUSnX3rOrPYjkyu5yTSwa2H7fsUWrKUSyAwtbZHF0RLnd pSux05xXTna5i5c0kGCiS70UgTYsIJeD66OR1ZYudn9LwF+yYyZ+d9tJxXhj49roEYof zzj5h42fqXqFq9to7VrBLM3OLGY16P/Mdi5uJWniRUySLsYO8ylF8AmWSPsuleJa7jAu IC0A== 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=nC+d2NQkXP/bCT8RkhhgtDJQ2Yn7M4hU1mMHamxX1VM=; b=ZPyj49cltBZtHB1H7gWOHvOvAaV7ie/blP4kA7b/Tm5QhviUtsdOu/H5xglWMjT0zM 6hNWgN0Ny746NN8bVS6VvC0o57Lb3W3f+QfCmw+dkqlkw3O+9vjg6CGasRMz/FaV5aiI ph0wdIBimMODo1q5iL61x2hxixJZIQz8Aqu0ZnbBFd8wr95An7itBZOBr1b/IR32OayM nPLVsBFC6LE8flPeA7SsspGvd+b7+rCp0IDNLNgFVFoby82WQDA2nZorUsiD2qBSNXlU gvwmMEleoXK8+fzHofmjNFiaDNdRt8GSxMbPa6Zyx81GDcT2f+PIto441O5n3BsBVN/+ BbNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y2yqS/Y4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a170902d54700b001b5afd23447si5075051plf.244.2023.06.21.13.57.42; Wed, 21 Jun 2023 13:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y2yqS/Y4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230190AbjFUU0k (ORCPT + 99 others); Wed, 21 Jun 2023 16:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbjFUU02 (ORCPT ); Wed, 21 Jun 2023 16:26:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E2011BFC; Wed, 21 Jun 2023 13:26:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B207E616A1; Wed, 21 Jun 2023 20:26:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37288C433C0; Wed, 21 Jun 2023 20:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687379185; bh=IldafOrMYKZpxWjdW8Dzn1OfaBUtuI1eV2ylNsc6e4U=; h=Date:From:To:Cc:Subject:From; b=Y2yqS/Y4fgeMMrBp4GVpPiqQbkfNRrlEDKuueTlTQcPCkJMvcZl93ZvoNBGz2WDfd prh5aeFF+odgcGV6AHJovFc1nEKh5cxfzd3S8h2m07GFMUckTezMG4N7GGzAN8fHY4 d7JdCsfUVoBNmj2AlNadrUd87AzKOuZrRDvoL7MP1Vq9vBRZUd95XDNOMPjmUqQUKx JMS2PKX5AmaDfvzGLvKQ6Fu1YquE0AdOgntp9F8JvZUElb/mbC3KGDpstXFzmfDT7D xBHLVodDHNUxpMCFx2G+bfNhum2wBPFITdhqY5+waVCPStH3gMdb50Jy2z/dIh2biy 84S6CUf4NnFcQ== Date: Wed, 21 Jun 2023 14:27:20 -0600 From: "Gustavo A. R. Silva" To: Don Brace , "James E.J. Bottomley" , "Martin K. Petersen" Cc: storagedev@microchip.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] scsi: smartpqi: Replace one-element arrays with flexible-array members Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769347298387441604?= X-GMAIL-MSGID: =?utf-8?q?1769347298387441604?= One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(). This results in no differences in binary output. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/204 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/smartpqi/smartpqi.h | 4 ++-- drivers/scsi/smartpqi/smartpqi_init.c | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h index f960b5095d09..e392eaf5b2bf 100644 --- a/drivers/scsi/smartpqi/smartpqi.h +++ b/drivers/scsi/smartpqi/smartpqi.h @@ -982,12 +982,12 @@ struct report_phys_lun_16byte_wwid { struct report_phys_lun_8byte_wwid_list { struct report_lun_header header; - struct report_phys_lun_8byte_wwid lun_entries[1]; + struct report_phys_lun_8byte_wwid lun_entries[]; }; struct report_phys_lun_16byte_wwid_list { struct report_lun_header header; - struct report_phys_lun_16byte_wwid lun_entries[1]; + struct report_phys_lun_16byte_wwid lun_entries[]; }; struct raid_map_disk_data { diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index 19af36e9a16d..6aaaa7ebca37 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -1203,7 +1203,6 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b unsigned int i; u8 rpl_response_format; u32 num_physicals; - size_t rpl_16byte_wwid_list_length; void *rpl_list; struct report_lun_header *rpl_header; struct report_phys_lun_8byte_wwid_list *rpl_8byte_wwid_list; @@ -1232,9 +1231,9 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b rpl_8byte_wwid_list = rpl_list; num_physicals = get_unaligned_be32(&rpl_8byte_wwid_list->header.list_length) / sizeof(rpl_8byte_wwid_list->lun_entries[0]); - rpl_16byte_wwid_list_length = sizeof(struct report_lun_header) + (num_physicals * sizeof(struct report_phys_lun_16byte_wwid)); - rpl_16byte_wwid_list = kmalloc(rpl_16byte_wwid_list_length, GFP_KERNEL); + rpl_16byte_wwid_list = kmalloc(struct_size(rpl_16byte_wwid_list, lun_entries, + num_physicals), GFP_KERNEL); if (!rpl_16byte_wwid_list) return -ENOMEM;