From: Tuo Li <islituo@gmail.com>
To: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com,
shivasharan.srikanteshwara@broadcom.com, jejb@linux.ibm.com,
martin.petersen@oracle.com
Cc: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
Tuo Li <islituo@gmail.com>, TOTE Robot <oslab@tsinghua.edu.cn>
Subject: [PATCH] [SCSI] megaraid_sas: Fix possible divide-by-zero bugs in megaraid_sas_fp.c
Date: Wed, 11 Aug 2021 06:16:47 -0700 [thread overview]
Message-ID: <20210811131647.9300-1-islituo@gmail.com> (raw)
In the function mega_mod64(). the variable is checked in:
if (!divisor)
This indicates that divisor can be zero.
If so, a divide-by-zero bug will occur:
remainder = do_div(d, divisor);
Also, in the function mega_div64_32(), a divide-by-zero bug can also occur
if divisor is NULL.
To fix these divide-by-zero bugs, the functions return 0 if divisor is
zero.
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/scsi/megaraid/megaraid_sas_fp.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 83f69c33b01a..05eb0d201aed 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -72,8 +72,10 @@ u32 mega_mod64(u64 dividend, u32 divisor)
u64 d;
u32 remainder;
- if (!divisor)
+ if (!divisor) {
printk(KERN_ERR "megasas : DIVISOR is zero, in div fn\n");
+ return 0;
+ }
d = dividend;
remainder = do_div(d, divisor);
return remainder;
@@ -90,8 +92,10 @@ static u64 mega_div64_32(uint64_t dividend, uint32_t divisor)
{
u64 d = dividend;
- if (!divisor)
+ if (!divisor) {
printk(KERN_ERR "megasas : DIVISOR is zero in mod fn\n");
+ return 0;
+ }
do_div(d, divisor);
--
2.25.1
next reply other threads:[~2021-08-11 13:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 13:16 Tuo Li [this message]
2021-08-11 13:58 ` [PATCH] [SCSI] megaraid_sas: Fix possible divide-by-zero bugs in megaraid_sas_fp.c James Bottomley
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=20210811131647.9300-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=kashyap.desai@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=megaraidlinux.pdl@broadcom.com \
--cc=oslab@tsinghua.edu.cn \
--cc=shivasharan.srikanteshwara@broadcom.com \
--cc=sumit.saxena@broadcom.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