From patchwork Tue Feb 7 16:57:29 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: 53996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2961785wrn; Tue, 7 Feb 2023 09:02:32 -0800 (PST) X-Google-Smtp-Source: AK7set9DsRwwFN8R1vDJYCSGQGngXUQ8mLc2xdW8+EREJ07W30vuP4Xi2Lv36+KMZipTM8jABqqe X-Received: by 2002:a17:907:3e0a:b0:88d:ba89:1842 with SMTP id hp10-20020a1709073e0a00b0088dba891842mr23055831ejc.19.1675789351864; Tue, 07 Feb 2023 09:02:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675789351; cv=none; d=google.com; s=arc-20160816; b=PWDkPI2tEqXBAGlege9qWgr24imZEgJWZ2yA4yYvDt2hqKiTnh9VMvxbelH24dOqjM Xs7ktSxKblrjhMNhKTf+Omle0s5K+M7+nHeASPlIl8Sh5l1a1rt6z8yB3tN95u22EqCJ FMOvE9f9UlfcMYF7DgIFohlUmVYObGvu5cH9oRtwLHjvMeccdM3wn90STCmqDubxsAGG N8uv5ad7gqx6pd4RO7MFqMwckpdg0Dk613TP4IRKWT028PqHZaoi5/Fdo5hlmW1k8oH6 uc8SYecKF2Yk3eHCdTBfZtAdh/Xncy5zs+Dy3vedncm0C3M2oWdd6B43she89h/tb52F VAFQ== 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=wDLcpuM95TqhHWnDFI6MhIzJZRGd+aLgwxUq4ew4pdo=; b=t2yj6F4e2tC9iTnrpSbYYLmdZhJhulkbcXKbD1jZWZHy7zHBPJpdf+/ZTVLnLtEVAB /8j/MXpdn39afNKh6Awj7eZKbHfXlFPwSjsIb8Ak5gs0iyDrmrJ08ZrFXvvUNDxz0fmU 3dviPJmcJfwP6mgLI1RZAjwi+C0LWd5o6ah1fjnofJ6P/hse9A/lTEZNwDzxKy770me6 3mDutoDm5JHuPyyVrmz8kpuON/PWnM5yZdupUUkNOmt6mvwaI9VjbZpdofDzsNLksWSj RbVri0LJNHATp1PVnTGVnVFS4HezAoujizk1CqDD/A7m/ifPhN1CkAEylm4eoHgu3aTv PN9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ffwz5mg+; 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 fd2-20020a1709072a0200b008845c668412si14149365ejc.189.2023.02.07.09.02.06; Tue, 07 Feb 2023 09:02:31 -0800 (PST) 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=Ffwz5mg+; 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 S232003AbjBGQ5V (ORCPT + 99 others); Tue, 7 Feb 2023 11:57:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjBGQ5U (ORCPT ); Tue, 7 Feb 2023 11:57:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034793A594; Tue, 7 Feb 2023 08:57:19 -0800 (PST) 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 B44F7B81A01; Tue, 7 Feb 2023 16:57:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03C78C433EF; Tue, 7 Feb 2023 16:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675789036; bh=MNtjrR3i9zJVMbXrA2OM0kVsyK6vBzmxrxtfk069rf4=; h=Date:From:To:Cc:Subject:From; b=Ffwz5mg+uOZwkbqk3CdPXkwZ9FrLo9uSsNsNsQw5kweSC29zByMBR7kj4y9ueasMc jRK5le8mzpZz7Edq+RS1FjPxmELIf+LJrw6uQueXrTWqcChbuB3lwdBxirpX3xuPwt 8a6E8Ogxb1IIkG2nkAF3mLxbNg3cb0eM6HmSn32YmeUTnjyrY7OI4Xs77BXyfZYSGX MX7uuhhUpgKNFStumGa+0gZQ95FRrhOGdj76UJxXEMw+XtLu+EjcWv4LJK2AcKXoJa 1X/eBUoosJnhIHkk5u7N4HRU4LRO618snZyFBz26qfYuBlTezr1rEoD07bspuuhlfJ oXqEH0duQFRdw== Date: Tue, 7 Feb 2023 10:57:29 -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, Kees Cook Subject: [PATCH v2][next] scsi: smartpqi: Replace one-element array with flexible-array member 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 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?1757192495215240855?= X-GMAIL-MSGID: =?utf-8?q?1757192495215240855?= 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 report_log_lun_list. 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/204 Signed-off-by: Gustavo A. R. Silva --- Changes in v2: In v1 we thought that the original code was allocating one too-many entries for the list. However, Don Brance commented that the allocation was actually intentional[1]. So, I added a code comment with his feedback. Link: https://lore.kernel.org/linux-hardening/16e6c434-44af-2efb-d4bc-a253e93e5590@embeddedor.com/ [1] v1: Link: https://lore.kernel.org/linux-hardening/c80c0979933e0c05e80d95792ef167a28640a14b.1663816572.git.gustavoars@kernel.org/ drivers/scsi/smartpqi/smartpqi.h | 2 +- drivers/scsi/smartpqi/smartpqi_init.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h index af27bb0f3133..228838eb3686 100644 --- a/drivers/scsi/smartpqi/smartpqi.h +++ b/drivers/scsi/smartpqi/smartpqi.h @@ -954,7 +954,7 @@ struct report_log_lun { struct report_log_lun_list { struct report_lun_header header; - struct report_log_lun lun_entries[1]; + struct report_log_lun lun_entries[]; }; struct report_phys_lun_8byte_wwid { diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index d0446d4d4465..af8f1a8e9f8f 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -1277,6 +1277,10 @@ static int pqi_get_device_lists(struct pqi_ctrl_info *ctrl_info, logdev_data_length = sizeof(struct report_lun_header) + logdev_list_length; + /* + * Notice that we take on an extra list entry (struct report_log_lun) + * that is all zeros for the controller itself. + */ internal_logdev_list = kmalloc(logdev_data_length + sizeof(struct report_log_lun), GFP_KERNEL); if (!internal_logdev_list) {