All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yiyuan GUO <yguoaz@gmail.com>
To: shivasharan.srikanteshwara@broadcom.com
Cc: linux-scsi@vger.kernel.org, megaraidlinux.pdl@broadcom.com,
	sumit.saxena@broadcom.com, kashyap.desai@broadcom.com,
	yguoaz@gmail.com, Yiyuan GUO <yguoaz@cse.ust.hk>
Subject: [PATCH] scsi: megaraid: check the value of quad->diff before using it in division
Date: Mon, 17 May 2021 16:24:36 +0800	[thread overview]
Message-ID: <20210517082436.73551-1-yguoaz@cse.ust.hk> (raw)

The function get_strip_from_row and mr_update_span_set uses the
variable quad->diff as a divisor withou checking (by passing it
to the function mega_mod64 and mega_div64_32 respectively). The
variable quad->diff may equal to zero, leading to potential divide
by zero problems. Similar checks on quad->diff are already enforced
in the function mr_spanset_get_span_block.

Signed-off-by: Yiyuan GUO <yguoaz@cse.ust.hk>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index b6c08d620..0e242632e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -562,6 +562,7 @@ static u64 get_strip_from_row(struct megasas_instance *instance,
 					spanBlock[span].block_span_info.quad[info];
 				if (le64_to_cpu(quad->logStart) <= row  &&
 					row <= le64_to_cpu(quad->logEnd)  &&
+					le32_to_cpu(quad->diff) &&
 					mega_mod64((row - le64_to_cpu(quad->logStart)),
 					le32_to_cpu(quad->diff)) == 0) {
 					strip = mega_div64_32
@@ -1242,6 +1243,8 @@ void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL *map,
 					spanBlock[span].block_span_info.
 					quad[element];
 
+				if (!le32_to_cpu(quad->diff))
+					continue;
 				span_set->diff = le32_to_cpu(quad->diff);
 
 				for (count = 0, span_row_width = 0;
-- 
2.25.1


                 reply	other threads:[~2021-05-17  8:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210517082436.73551-1-yguoaz@cse.ust.hk \
    --to=yguoaz@gmail.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=megaraidlinux.pdl@broadcom.com \
    --cc=shivasharan.srikanteshwara@broadcom.com \
    --cc=sumit.saxena@broadcom.com \
    --cc=yguoaz@cse.ust.hk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.