lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Tue, 25 Jan 2022 17:10:33 -0600
From:   "Gustavo A. R. Silva" <>
To:     "James E.J. Bottomley" <>,
        "Martin K. Petersen" <>
        "Gustavo A. R. Silva" <>,
Subject: [PATCH][next] scsi: core: Use struct_size() helper in kmalloc()

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/scsi/scsi.c:390:27: warning: using sizeof on a flexible structure

Signed-off-by: Gustavo A. R. Silva <>
 drivers/scsi/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 211aace69c22..949cb530e360 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -387,7 +387,7 @@ static struct scsi_vpd *scsi_get_vpd_buf(struct scsi_device *sdev, u8 page)
 	int vpd_len = SCSI_VPD_PG_LEN, result;
-	vpd_buf = kmalloc(sizeof(*vpd_buf) + vpd_len, GFP_KERNEL);
+	vpd_buf = kmalloc(struct_size(vpd_buf, data, vpd_len), GFP_KERNEL);
 	if (!vpd_buf)
 		return NULL;

Powered by blists - more mailing lists