linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Adaptec OEM Raid Solutions <aacraid@microsemi.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-hardening@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: [PATCH 1/8][next] scsi: aacraid: Replace one-element array with flexible-array member
Date: Tue, 22 Feb 2022 01:28:54 -0600	[thread overview]
Message-ID: <1fb4b0263611e3a28d94c5aba4b7c3d7c7791675.1645513670.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1645513670.git.gustavoars@kernel.org>

Replace one-element array with flexible-array member in struct
aac_ciss_phys_luns_resp.

Also, use the struct_size() helper to properly calculate the total size
for allocation.

This issue was found with the help of Coccinelle and audited and fixed,
manually.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/scsi/aacraid/aachba.c  | 5 ++---
 drivers/scsi/aacraid/aacraid.h | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index b04d039da276..98100e28e95e 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -1823,13 +1823,12 @@ static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
 static int aac_get_safw_ciss_luns(struct aac_dev *dev)
 {
 	int rcode = -ENOMEM;
-	int datasize;
+	size_t datasize;
 	struct aac_srb *srbcmd;
 	struct aac_srb_unit srbu;
 	struct aac_ciss_phys_luns_resp *phys_luns;
 
-	datasize = sizeof(struct aac_ciss_phys_luns_resp) +
-		(AAC_MAX_TARGETS - 1) * 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;
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 3733df77bc65..704440a96daa 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -321,7 +321,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 */
 };
 
 /*
-- 
2.27.0


  reply	other threads:[~2022-02-22  7:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22  7:28 [PATCH 0/8] scsi: aacraid: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2022-02-22  7:28 ` Gustavo A. R. Silva [this message]
2022-02-22  7:29 ` [PATCH 2/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmap Gustavo A. R. Silva
2022-02-22  7:29 ` [PATCH 3/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmap Gustavo A. R. Silva
2022-02-22  7:30 ` [PATCH 4/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmap64 Gustavo A. R. Silva
2022-02-22  7:30 ` [PATCH 5/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmap64 Gustavo A. R. Silva
2022-02-22  7:30 ` [PATCH 6/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct sgmapraw Gustavo A. R. Silva
2022-02-22  7:30 ` [PATCH 7/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct user_sgmapraw Gustavo A. R. Silva
2022-02-22  7:31 ` [PATCH 8/8][next] scsi: aacraid: Replace one-element array with flexible-array member in struct aac_aifcmd Gustavo A. R. Silva
2022-06-23 16:29   ` Kees Cook
2022-03-10  4:03 ` [PATCH 0/8] scsi: aacraid: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2022-03-15  4:02   ` Martin K. Petersen
2022-03-15  4:22     ` Gustavo A. R. Silva
2022-06-23 16:26       ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1fb4b0263611e3a28d94c5aba4b7c3d7c7791675.1645513670.git.gustavoars@kernel.org \
    --to=gustavoars@kernel.org \
    --cc=aacraid@microsemi.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).