From patchwork Wed Jun 28 17:54:27 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: 13296101 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 318F6EB64D7 for ; Wed, 28 Jun 2023 17:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231887AbjF1Rxh (ORCPT ); Wed, 28 Jun 2023 13:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbjF1Rxe (ORCPT ); Wed, 28 Jun 2023 13:53:34 -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 DEC1FD8; Wed, 28 Jun 2023 10:53:33 -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 73F4C6141D; Wed, 28 Jun 2023 17:53:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03D96C433C8; Wed, 28 Jun 2023 17:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974812; bh=RiuIgkhu77zPv+WhGnYLVNRE1+8TYz1yHFT8B0EbRN0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i2dAsDjrx2FY+7CZ6IaD3SGF1mVQ62NvOZP1ffXHdTe9MIH6sAVnOqt8muzuDFh6g +G8oPPveZdLQvXAexB57GUsz3YnFG+Jueo0lSfdNlzm9MaPHiEczuinsNkRr8QqP8t KAPxgiK9dXNI057IMDrfucA+DSq1aurAjjm1a6/sNHQW0krpZZQmd60TkYcarpZXGs 6me+kvVwZhdykmGSwYFAYgcY+Z1s23OqD9HNVJM5Rf217TawDV14bpq778VfGklorS TFWI3fVRQRFE1oBp/y65JaqYKx2TFnJbR7eBinkb+njJ+gfsnMZlYZ7jfFNz23kNn0 CiKdtBZV+Ahpw== Date: Wed, 28 Jun 2023 11:54:27 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 01/10][next] scsi: aacraid: Replace one-element array with flexible-array member Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct aac_ciss_phys_luns_resp. This results in no differences in binary output. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aachba.c | 2 +- drivers/scsi/aacraid/aacraid.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index 70e1cac1975e..bba2d4d952ca 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1833,7 +1833,7 @@ static int aac_get_safw_ciss_luns(struct aac_dev *dev) struct aac_ciss_phys_luns_resp *phys_luns; datasize = sizeof(struct aac_ciss_phys_luns_resp) + - (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun); + AAC_MAX_TARGETS * sizeof(struct _ciss_lun); phys_luns = kmalloc(datasize, GFP_KERNEL); if (phys_luns == NULL) goto out; diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 7c6efde75da6..83fa890f28be 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -322,7 +322,7 @@ struct aac_ciss_phys_luns_resp { u8 level3[2]; u8 level2[2]; u8 node_ident[16]; /* phys. node identifier */ - } lun[1]; /* List of phys. devices */ + } lun[]; /* List of phys. devices */ }; /* From patchwork Wed Jun 28 17:54:58 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: 13296102 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 C71A6EB64DA for ; Wed, 28 Jun 2023 17:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbjF1RyT (ORCPT ); Wed, 28 Jun 2023 13:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbjF1RyF (ORCPT ); Wed, 28 Jun 2023 13:54:05 -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 EF0F21FE8; Wed, 28 Jun 2023 10:54:04 -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 851366141D; Wed, 28 Jun 2023 17:54:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F162C433C8; Wed, 28 Jun 2023 17:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974844; bh=oSRPOgHpNDB64XuYcsnvS74umcBXdshhYlA/hMOAXX8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H3m7jv70ePbAmDUscA1F0AhYSYj7TOZVKgCeF01P64dnTgDXLMxvVR6PT4N6Fe5cS yi2yAQIJQVICsaInV50nOacomxIXbN/EA7ueM5VYALZZb/xMiOTGmOVr3qcutoFZaq Q4FI0gMtZo86BobjGg/qAv7HRb6PZ4MfAXFm0ceeDZE4uK2p1V4Oe1dAuJOw6N77TV 4bw2cBT5r9AbcHMwRg2rtonUVZ6Wdt9TiP4R1C8x51iSq8QVZOuchu28Uj0xN2Je1f 6THqWVmanj40ydMVnAllifZdpTzwKzJlbreJFrCwQtB42A9SpDxPSp7L90sG5JY63+ ikrYCgaxZe4Kg== Date: Wed, 28 Jun 2023 11:54:58 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 02/10][next] scsi: aacraid: Use struct_size() helper in aac_get_safw_ciss_luns() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Prefer struct_size() over open-coded versions. This results in no differences in binary output. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aachba.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index bba2d4d952ca..fff0550e02e4 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1832,8 +1832,7 @@ static int aac_get_safw_ciss_luns(struct aac_dev *dev) struct aac_srb_unit srbu; struct aac_ciss_phys_luns_resp *phys_luns; - datasize = sizeof(struct aac_ciss_phys_luns_resp) + - AAC_MAX_TARGETS * sizeof(struct _ciss_lun); + datasize = struct_size(phys_luns, lun, AAC_MAX_TARGETS); phys_luns = kmalloc(datasize, GFP_KERNEL); if (phys_luns == NULL) goto out; From patchwork Wed Jun 28 17:55:24 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: 13296103 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 126A8EB64D7 for ; Wed, 28 Jun 2023 17:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbjF1RzT (ORCPT ); Wed, 28 Jun 2023 13:55:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232013AbjF1Ryg (ORCPT ); Wed, 28 Jun 2023 13:54:36 -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 167182704; Wed, 28 Jun 2023 10:54:31 -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 9C36A61426; Wed, 28 Jun 2023 17:54:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33042C433C0; Wed, 28 Jun 2023 17:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974870; bh=Bh4L2zCmi8co6ZKpNs0mjBEZPUkU4wABH1EONUGV4ko=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=drUR6x+k+t8/2hPL0PU77jfEmFxwI/9p/nmhLCpepsUyg8imTUiIrSHEitQ39pyf5 dQ6Mi9W1I8tCpaC636iTfWsmcupTbmrxBMXarmQYnzqp1Pou3/R0SUmtsQhYJOjDvy 8Wq7mBolcr/4mLGtxrrTSVunbtlIwBRLVqZ1x4Smg/En4x9EEEvSruh+Am68sBLON+ /Tj8m6Vcrqh+0+ne5Hr1CsIP/Y9egbkv9lVUjXUKXbD353UZv4iq1F3tzSx697BjCg +HXJO39pfxtnt4re3CmOAnW0jqHkXqPVGNFR00FZgY+idT08P01GxOMFRRTNJhyzPh l6EKX6oV4xUVw== Date: Wed, 28 Jun 2023 11:55:24 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 03/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct aac_aifcmd Message-ID: <65907ee4083de62fbaadc5c2e6512e3828912d1b.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct aac_aifcmd. This results in no differences in binary output. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aacraid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 83fa890f28be..2e1623344327 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -2618,7 +2618,7 @@ struct aac_hba_info { struct aac_aifcmd { __le32 command; /* Tell host what type of notify this is */ __le32 seqnum; /* To allow ordering of reports (if necessary) */ - u8 data[1]; /* Undefined length (from kernel viewpoint) */ + u8 data[]; /* Undefined length (from kernel viewpoint) */ }; /** From patchwork Wed Jun 28 17:55:47 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: 13296104 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 C8C7BEB64DA for ; Wed, 28 Jun 2023 17:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231410AbjF1RzU (ORCPT ); Wed, 28 Jun 2023 13:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232123AbjF1Ryz (ORCPT ); Wed, 28 Jun 2023 13:54:55 -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 8C3A42681; Wed, 28 Jun 2023 10:54:54 -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 2247E6139D; Wed, 28 Jun 2023 17:54:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B536BC433C0; Wed, 28 Jun 2023 17:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974893; bh=plV4nM9kY1seEi2E6G5RifIXmBYxufGUPbUvfxDlnUI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RmuxOHe4Dp8GBzik4q7A9/cuR8XTkx2C/8mmbApEAIa5ixksWpREBzzySrOS0TJ/o C0w3iZlSmyxGeZ6dKYfAVMGNoAiDsv515TZsDLeO69ZrB0onpnXLkBBl7RcenAcuri +FuXQLbEHdWN5WqE54VrsCAz/5C7+xbFSekpCyD+2Xx8qNQE8Guc3AY6JRLwj07BW2 gy4Z5u8Az8XYuVEmSmlSwCsGQLn+ZFCpucxv0TlEF3AKvuM399EAb4TuYtGV8ZYhLE mov3A6XFmu1LUGwSsDlMzs1S1IpqXr5DFppJZjGAKEt0uAa2AYs5MIe+lk6lizC0pn tctk8Fk0j76bg== Date: Wed, 28 Jun 2023 11:55:47 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 04/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmapraw Message-ID: <4c2277b8aa3de8600c807ff8c995635f414161f9.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct user_sgmapraw. This results in no differences in binary output. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aacraid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 2e1623344327..d1fc1ce2e36d 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -532,7 +532,7 @@ struct sgmapraw { struct user_sgmapraw { u32 count; - struct user_sgentryraw sg[1]; + struct user_sgentryraw sg[]; }; struct creation_info From patchwork Wed Jun 28 17:56:12 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: 13296105 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 5A794EB64D7 for ; Wed, 28 Jun 2023 17:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbjF1Rzv (ORCPT ); Wed, 28 Jun 2023 13:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjF1RzU (ORCPT ); Wed, 28 Jun 2023 13:55:20 -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 5DABDED; Wed, 28 Jun 2023 10:55:19 -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 E7A46613F8; Wed, 28 Jun 2023 17:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83028C433C0; Wed, 28 Jun 2023 17:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974918; bh=0hu58kp2QVPpg0WUsZ39FkRVCtgHbTIBc4jqwasTzQI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jy3t3Ms+Hev97tgWKs7vJAFVzGHlfwRe716LzYvpe3e58vu247JuRAdmECUNjA7Ae s2ipJsRqzuSQjFycRI6VQPZNq5wofki/o/ibj2lS2DXkGUisJJrS8B6iqxkxjB6tE2 OEHJLpwJars1xgZA9lbL700/xoyPHeOk9cv1VRV5OVxllqZbpvobkG9GjS0eYhghRx S1Zi9rz9R7Ol3B8l6tAoECz8QSrhVc4QlTGx/uB8qsUTxX95Lzywg+AEVAHzrrHy6A qx9glc/ez3ULkJimnTS9phWFs2+mP8dXwzdzMMJKG8as+x+t/F28/eKnKIqcqeXOP8 EfN6CBtMU2vrQ== Date: Wed, 28 Jun 2023 11:56:12 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 05/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmapraw Message-ID: <9dfcdf55597a49ed7e19ba064f5be424b344e175.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct sgmapraw. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aachba.c | 4 ++-- drivers/scsi/aacraid/aacraid.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index fff0550e02e4..b3c0c2255e55 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1267,7 +1267,7 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3 return ret; command = ContainerRawIo; fibsize = sizeof(struct aac_raw_io) + - ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw)); + le32_to_cpu(readcmd->sg.count) * sizeof(struct sgentryraw); } BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); @@ -1401,7 +1401,7 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u return ret; command = ContainerRawIo; fibsize = sizeof(struct aac_raw_io) + - ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw)); + le32_to_cpu(writecmd->sg.count) * sizeof(struct sgentryraw); } BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index d1fc1ce2e36d..87015dd2abd9 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -527,7 +527,7 @@ struct user_sgmap64 { struct sgmapraw { __le32 count; - struct sgentryraw sg[1]; + struct sgentryraw sg[]; }; struct user_sgmapraw { From patchwork Wed Jun 28 17:56:31 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: 13296106 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 428CEEB64D7 for ; Wed, 28 Jun 2023 17:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjF1R4P (ORCPT ); Wed, 28 Jun 2023 13:56:15 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:37064 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232260AbjF1Rzi (ORCPT ); Wed, 28 Jun 2023 13:55:38 -0400 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 3378161447; Wed, 28 Jun 2023 17:55:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C09A2C433CB; Wed, 28 Jun 2023 17:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974937; bh=7JUyr2dX63IraG+7yBFRgMvzzEv6qsJXwBtXtsyQIRg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a+poLz5iSuMCS+/NCh2iMU0fnKSOL7K0254QTfODdY9ehKFz7PwZ0L1424dV6bpuP LazKhf9sGQAhwjY0vGc/YP9CSllExeuAk22cq1kcd5OpvjpMMYGSX22Fd2SgJsH3QM eUknnw01QGNcAYfq3Je4I1bvBkhtMWG/4P2AlqsCZzL4PsbHneJaaYYM+QYuqBPqEi 2lgDhdhdZweMvvV8udarefvKiJdLy37c42fM/6kgvqXqm6UC5pA0pGKz4Nyvoqfsnc RTvctdvyBTOVJj3Ua9ychfylMelEmD7e5rITvKO3qpvQj6FbkxPAUeXATeB8iMMnfg Dy1Hz6czDnb4A== Date: Wed, 28 Jun 2023 11:56:31 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 06/10][next] scsi: aacraid: Use struct_size() helper in code related to struct sgmapraw Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Prefer struct_size() over open-coded versions. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aachba.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index b3c0c2255e55..03ba974f6b2a 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1266,8 +1266,7 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3 if (ret < 0) return ret; command = ContainerRawIo; - fibsize = sizeof(struct aac_raw_io) + - le32_to_cpu(readcmd->sg.count) * sizeof(struct sgentryraw); + fibsize = struct_size(readcmd, sg.sg, le32_to_cpu(readcmd->sg.count)); } BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); @@ -1400,8 +1399,7 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u if (ret < 0) return ret; command = ContainerRawIo; - fibsize = sizeof(struct aac_raw_io) + - le32_to_cpu(writecmd->sg.count) * sizeof(struct sgentryraw); + fibsize = struct_size(writecmd, sg.sg, le32_to_cpu(writecmd->sg.count)); } BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); From patchwork Wed Jun 28 17:56:52 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: 13296114 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 783F7EB64D7 for ; Wed, 28 Jun 2023 17:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbjF1R4z (ORCPT ); Wed, 28 Jun 2023 13:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232429AbjF1Rz7 (ORCPT ); Wed, 28 Jun 2023 13:55:59 -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 13207ED; Wed, 28 Jun 2023 10:55:59 -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 935F16141D; Wed, 28 Jun 2023 17:55:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ABBEC433C9; Wed, 28 Jun 2023 17:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974958; bh=7gxVFglFtXDu/AnNBVBeHPlv7TElOsSUgfmrlZBHPf0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VAGQADKajLlW1y4fkCGn3p1Dl/RgpYmd4NHIx7S2mGSb25bdu9R0GYH1edCFjDrWT tXuz1a1LhxR9StVgXR8q7G8ihL/kHAHNTNvO02H6CAtQ53yaCW8SQxL91q+IcPztHO x8k9ggymNK9nKqeSCuiHLU8YFCgb/bcppPK6nN0BDcvaxUzXBhxLzrU0buDQaaxdY9 P8nN1N9Z6XKDbOIYmGbz83ZnbMmWUFe74RzFn5BkhzaXhX5Kqe3n2fZ78BKFnP/5dh A2L1fOV2uIw7mb2Vyd7sBLkGNsY3X2Vw7VjYyvnMt6jxpNh8HI9rlL4fD0cP0LurMh bK1wlm/YrdjmA== Date: Wed, 28 Jun 2023 11:56:52 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 07/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmap64 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct user_sgmap64. This results in no differences in binary output. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aacraid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 87015dd2abd9..94eb83d38be6 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -522,7 +522,7 @@ struct sgmap64 { struct user_sgmap64 { u32 count; - struct user_sgentry64 sg[1]; + struct user_sgentry64 sg[]; }; struct sgmapraw { From patchwork Wed Jun 28 17:57:13 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: 13296115 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 C7BD7EB64DD for ; Wed, 28 Jun 2023 17:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232306AbjF1R5b (ORCPT ); Wed, 28 Jun 2023 13:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232441AbjF1R4V (ORCPT ); Wed, 28 Jun 2023 13:56:21 -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 5EFD426B7; Wed, 28 Jun 2023 10:56:20 -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 E9B2261426; Wed, 28 Jun 2023 17:56:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DB67C433C0; Wed, 28 Jun 2023 17:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974979; bh=oURmBWezquiCxtgzQofhLG2vCq/AGJynRcxtSxdHtso=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kutrpgvcj50b2E0D25+J+Q1Qzv+1OZq6w/2/qYqixf1eZbltUDqp0P0utmW2fLHgI 1g+flEQ6xrEepEkkuv+wr7qu3DYNxUpD1TBOlg8xFN1TZb8b9gHuzEOEnDAiWC7EHz wAEFETeWqMRdqTqpEk2Y9G5wQBGCfRgSIEoD7+W7xaabLbj71RF4b3RJTy60j0NEQ5 gIvMhuPy1/5A6cHNbArJlNCF1EqgXT4giwrXIPOdf+FpeRhS3FXsHd4ynapG7RkWqA SgUlCifBVQTU6L1IrEORnAO8ET/RNVlYdm18rgjICXK49Hg5rVk4ICxOvKlrqeSA1H 183vSoEdJzxIQ== Date: Wed, 28 Jun 2023 11:57:13 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 08/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmap Message-ID: <0c7402fe6448186cda5a2618a35eb5f8d1cbb313.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct sgmap and refactor the rest of the code, accordingly. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva --- drivers/scsi/aacraid/aachba.c | 24 ++++++++++-------------- drivers/scsi/aacraid/aacraid.h | 2 +- drivers/scsi/aacraid/commctrl.c | 4 ++-- drivers/scsi/aacraid/comminit.c | 3 +-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index 03ba974f6b2a..b2849e5cc104 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1336,8 +1336,7 @@ static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 if (ret < 0) return ret; fibsize = sizeof(struct aac_read) + - ((le32_to_cpu(readcmd->sg.count) - 1) * - sizeof (struct sgentry)); + le32_to_cpu(readcmd->sg.count) * sizeof(struct sgentry); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); /* @@ -1471,8 +1470,7 @@ static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3 if (ret < 0) return ret; fibsize = sizeof(struct aac_write) + - ((le32_to_cpu(writecmd->sg.count) - 1) * - sizeof (struct sgentry)); + le32_to_cpu(writecmd->sg.count) * sizeof(struct sgentry); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); /* @@ -1590,9 +1588,9 @@ static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd) /* * Build Scatter/Gather list */ - fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) + - ((le32_to_cpu(srbcmd->sg.count) & 0xff) * - sizeof (struct sgentry64)); + fibsize = sizeof(struct aac_srb) + + (le32_to_cpu(srbcmd->sg.count) & 0xff) * + sizeof(struct sgentry64); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); @@ -1621,9 +1619,9 @@ static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd) /* * Build Scatter/Gather list */ - fibsize = sizeof (struct aac_srb) + - (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * - sizeof (struct sgentry)); + fibsize = sizeof(struct aac_srb) + + (le32_to_cpu(srbcmd->sg.count) & 0xff) * + sizeof(struct sgentry); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); @@ -1691,8 +1689,7 @@ static int aac_send_safw_bmic_cmd(struct aac_dev *dev, fibptr->hw_fib_va->header.XferState &= ~cpu_to_le32(FastResponseCapable); - fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) + - sizeof(struct sgentry64); + fibsize = sizeof(struct aac_srb) + sizeof(struct sgentry64); /* allocate DMA buffer for response */ addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len, @@ -2264,8 +2261,7 @@ int aac_get_adapter_info(struct aac_dev* dev) dev->a_ops.adapter_bounds = aac_bounds_32; dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - sizeof(struct aac_fibhdr) - - sizeof(struct aac_write) + sizeof(struct sgentry)) / - sizeof(struct sgentry); + sizeof(struct aac_write)) / sizeof(struct sgentry); if (dev->dac_support) { dev->a_ops.adapter_read = aac_read_block64; dev->a_ops.adapter_write = aac_write_block64; diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 94eb83d38be6..3fbc22ae72b6 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -507,7 +507,7 @@ struct sge_ieee1212 { struct sgmap { __le32 count; - struct sgentry sg[1]; + struct sgentry sg[]; }; struct user_sgmap { diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c index e7cc927ed952..df811ad4afaa 100644 --- a/drivers/scsi/aacraid/commctrl.c +++ b/drivers/scsi/aacraid/commctrl.c @@ -561,8 +561,8 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) rcode = -EINVAL; goto cleanup; } - actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) + - ((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry)); + actual_fibsize = sizeof(struct aac_srb) + + (user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry); actual_fibsize64 = actual_fibsize + (user_srbcmd->sg.count & 0xff) * (sizeof(struct sgentry64) - sizeof(struct sgentry)); /* User made a mistake - should not continue */ diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c index bd99c5492b7d..d8dd89c87b01 100644 --- a/drivers/scsi/aacraid/comminit.c +++ b/drivers/scsi/aacraid/comminit.c @@ -523,8 +523,7 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) dev->max_fib_size = sizeof(struct hw_fib); dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size - sizeof(struct aac_fibhdr) - - sizeof(struct aac_write) + sizeof(struct sgentry)) - / sizeof(struct sgentry); + - sizeof(struct aac_write)) / sizeof(struct sgentry); dev->comm_interface = AAC_COMM_PRODUCER; dev->raw_io_interface = dev->raw_io_64 = 0; From patchwork Wed Jun 28 17:57:30 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: 13296116 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 89DF8EB64D7 for ; Wed, 28 Jun 2023 17:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232315AbjF1R55 (ORCPT ); Wed, 28 Jun 2023 13:57:57 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:37780 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbjF1R4h (ORCPT ); Wed, 28 Jun 2023 13:56:37 -0400 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 B7E6E613F8; Wed, 28 Jun 2023 17:56:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58625C433C8; Wed, 28 Jun 2023 17:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687974996; bh=ps8O/vvPqe7Ml4jiez90Tc0cMsCWoN+RGXBfPOYX34A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WG4eyi+y/ciMnIh9VHVyG7YzFresIOZuA2+mhnPV1La9FwqYgE2e01/tdVZObtSG6 Zsd6nqmm2hz+BeWguL/Jgp1VzbT6qpVOiKgHGfocitCOkmJUvV0FJMWCteaCVYBZDL owdOva+i9k46ziaBdY+Y8oKnAFxdE7v62qj12oHNFZyHUTxSEGxiw3m4DpC8gZm75b ZMTc4zObcE6hLBcpVmIRKet5ElUEPIItC/LF3xPd2hSKA3VE6YhFbT5P+evMcxxIpO 5pi38cjb+wnWTyDOUO5xJHRmPSmwVRjHSBzK2BpCBX2rmX4d6P/IGqBVNcsZcXK3kx /fteion7OzC/g== Date: Wed, 28 Jun 2023 11:57:30 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 09/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmap64 Message-ID: <169a28c9e45d1f237308b1ca716122c5d0ee3488.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct sgmap64 and refactor the rest of the code, accordingly. Issue found with the help of Coccinelle and audited and fixed, manually. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aachba.c | 9 +++------ drivers/scsi/aacraid/aacraid.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index b2849e5cc104..90df697e7c5f 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1301,8 +1301,7 @@ static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u if (ret < 0) return ret; fibsize = sizeof(struct aac_read64) + - ((le32_to_cpu(readcmd->sg.count) - 1) * - sizeof (struct sgentry64)); + le32_to_cpu(readcmd->sg.count) * sizeof(struct sgentry64); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); /* @@ -1433,8 +1432,7 @@ static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, if (ret < 0) return ret; fibsize = sizeof(struct aac_write64) + - ((le32_to_cpu(writecmd->sg.count) - 1) * - sizeof (struct sgentry64)); + le32_to_cpu(writecmd->sg.count) * sizeof(struct sgentry64); BUG_ON (fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); /* @@ -2271,8 +2269,7 @@ int aac_get_adapter_info(struct aac_dev* dev) dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - sizeof(struct aac_fibhdr) - - sizeof(struct aac_write64) + - sizeof(struct sgentry64)) / + sizeof(struct aac_write64)) / sizeof(struct sgentry64); } else { dev->a_ops.adapter_read = aac_read_block; diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index 3fbc22ae72b6..fb3d93e4a99e 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -517,7 +517,7 @@ struct user_sgmap { struct sgmap64 { __le32 count; - struct sgentry64 sg[1]; + struct sgentry64 sg[]; }; struct user_sgmap64 { From patchwork Wed Jun 28 17:57:48 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: 13296117 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 6BEFBEB64DA for ; Wed, 28 Jun 2023 17:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbjF1R6O (ORCPT ); Wed, 28 Jun 2023 13:58:14 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:38110 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232016AbjF1R4z (ORCPT ); Wed, 28 Jun 2023 13:56:55 -0400 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 8435F61425; Wed, 28 Jun 2023 17:56:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20271C433C0; Wed, 28 Jun 2023 17:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687975014; bh=td4cyQQksCxGhpEodkvmN0yoaLrNPgSUoTLfY9rGDgw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fB+3roWxpteaF0aMShsipBAj4bahjfCFQctyoGq3B5zVfMEaqDe1n2TIWQmB68bxh 48BVgJYR8oLZtdVm9fFLMMr95TUufrtPx/eLi4IEMv9AXbOnvJvD4KVPQWbVt2egTH 1DINJwCnOgM2gFFjZM/r5lJ1Cd4Gu8d+9gqYl1sPHBKSNR0y74nuNdMkq+S7DHkAWx 3le0rEcZPDCBQY/VD5LtH7yfMFOgW41OqkK5b2DHNEdy92QVcRV0j/sEuFiL3hGC8p UUcqI+BTPD6vtl7oZwqtj1HSBRPa9aVbPOWeGMokq/ZMyluYqtGbomLM/sMeLxBYlD HewzNxyoc1/xA== Date: Wed, 28 Jun 2023 11:57:48 -0600 From: "Gustavo A. R. Silva" To: aacraid@microsemi.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 10/10][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmap Message-ID: <2ebb702f25c4764fb36ab29f4f40728e12b0e42b.1687974498.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace one-element array with flexible-array member in struct user_sgmap and refactor the rest of the code, accordingly. Issue found with the help of Coccinelle and audited and fixed, manually. This results in no differences in binary output. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/ClangBuiltLinux/linux/issues/1851 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/aacraid/aacraid.h | 2 +- drivers/scsi/aacraid/commctrl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index fb3d93e4a99e..7d3f2f7348ff 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h @@ -512,7 +512,7 @@ struct sgmap { struct user_sgmap { u32 count; - struct user_sgentry sg[1]; + struct user_sgentry sg[]; }; struct sgmap64 { diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c index df811ad4afaa..74eb33eb70d3 100644 --- a/drivers/scsi/aacraid/commctrl.c +++ b/drivers/scsi/aacraid/commctrl.c @@ -523,7 +523,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) goto cleanup; } - if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) || + if ((fibsize < sizeof(struct user_aac_srb)) || (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) { rcode = -EINVAL; goto cleanup;