Skip to content

Commit a48e2c3

Browse files
GustavoARSilvamartinkpetersen
authored andcommitted
scsi: lpfc: Avoid -Wstringop-overflow warning
Prevent any potential integer wrapping issue, and avoid a -Wstringop-overflow warning by using the check_mul_overflow() helper. drivers/scsi/lpfc/lpfc.h: 837:#define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024) drivers/scsi/lpfc/lpfc_debugfs.c: 2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize; this can wrap to negative if cfg_ras_fwlog_buffsize is large enough. And even when in practice this is not possible (due to phba->cfg_ras_fwlog_buffsize never being larger than 4[1]), the compiler is legitimately warning us about potentially buggy code. Fix the following warning seen under GCC-13: In function ‘lpfc_debugfs_ras_log_data’, inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15: drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 2210 | memcpy(buffer + copied, dmabuf->virt, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2211 | size - copied - 1); | ~~~~~~~~~~~~~~~~~~ Link: KSPP#305 Link: https://lore.kernel.org/linux-hardening/CABPRKS8zyzrbsWt4B5fp7kMowAZFiMLKg5kW26uELpg1cDKY3A@mail.gmail.com/ [1] Co-developed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/ZHkseX6TiFahvxJA@work Reviewed-by: Justin Tee <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent bb26224 commit a48e2c3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/scsi/lpfc/lpfc_debugfs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,11 +2259,15 @@ lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
22592259
goto out;
22602260
}
22612261
spin_unlock_irq(&phba->hbalock);
2262-
debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2262+
2263+
if (check_mul_overflow(LPFC_RAS_MIN_BUFF_POST_SIZE,
2264+
phba->cfg_ras_fwlog_buffsize, &size))
2265+
goto out;
2266+
2267+
debug = kzalloc(sizeof(*debug), GFP_KERNEL);
22632268
if (!debug)
22642269
goto out;
22652270

2266-
size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
22672271
debug->buffer = vmalloc(size);
22682272
if (!debug->buffer)
22692273
goto free_debug;

0 commit comments

Comments
 (0)