linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: mpt3sas: Fix a possible divide-by-zero bug in base_mod64()
@ 2021-08-11 13:24 Tuo Li
  0 siblings, 0 replies; only message in thread
From: Tuo Li @ 2021-08-11 13:24 UTC (permalink / raw)
  To: sathya.prakash, sreekanth.reddy, suganath-prabu.subramani, jejb,
	martin.petersen
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, baijiaju1990,
	Tuo Li, TOTE Robot

The variable divisor is checked in:
  if (!divisor)

This indicates that divisor can be NULL.
If so, a divide-by-zero bug will occur:
  remainder = do_div(dividend, divisor);

To fix the possible bug, the function returns 0 when divisor is zero.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 19b1c0cf5f2a..3550998ea38b 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -1594,8 +1594,10 @@ static u32 base_mod64(u64 dividend, u32 divisor)
 {
 	u32 remainder;
 
-	if (!divisor)
+	if (!divisor) {
 		pr_err("mpt3sas: DIVISOR is zero, in div fn\n");
+		return 0;
+	}
 	remainder = do_div(dividend, divisor);
 	return remainder;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-11 13:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 13:24 [PATCH] scsi: mpt3sas: Fix a possible divide-by-zero bug in base_mod64() Tuo Li

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).