From: Jia-Ju Bai <baijiaju@tsinghua.edu.cn>
To: linuxdrivers@attotech.com, jejb@linux.ibm.com,
martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Jia-Ju Bai <baijiaju@tsinghua.edu.cn>
Subject: [PATCH] scsi: esas2r: fix possible buffer overflow caused by bad DMA value in esas2r_process_fs_ioctl()
Date: Sun, 2 Aug 2020 23:21:45 +0800 [thread overview]
Message-ID: <20200802152145.4387-1-baijiaju@tsinghua.edu.cn> (raw)
In esas2r_read_fs():
struct esas2r_ioctl_fs *fs =
(struct esas2r_ioctl_fs *)a->fs_api_buffer;
Because "a->fs_api_buffer" is mapped to coherent DMA (allocated in
esas2r_write_fs()), "fs" is also mapped to DMA.
Then esas2r_read_fs() calls esas2r_process_fs_ioctl() with "fs".
In esas2r_process_fs_ioctl():
fsc = &fs->command;
...
if (fsc->command >= cmdcnt) {
fs->status = ATTO_STS_INV_FUNC;
return false;
}
func = cmd_to_fls_func[fsc->command];
if (func == 0xFF) {
fs->status = ATTO_STS_INV_FUNC;
return false;
}
Because "fs" is mapped to DMA, its data can be modified at anytime by
malicious or malfunctioning hardware. In this case, the check
"if (fsc->command >= cmdcnt)" can be passed, and then "fsc->command"
can be modified by hardware to cause buffer overflow.
To fix this problem, "fsc->command" is assigned to a local variable, and
then this local variable is used to replace "fsc->command".
Signed-off-by: Jia-Ju Bai <baijiaju@tsinghua.edu.cn>
---
drivers/scsi/esas2r/esas2r_flash.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/esas2r/esas2r_flash.c b/drivers/scsi/esas2r/esas2r_flash.c
index b02ac389e6c6..ca5ff0d4c7d0 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -851,6 +851,7 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
struct esas2r_ioctlfs_command *fsc = &fs->command;
u8 func = 0;
u32 datalen;
+ u8 command = fsc->command;
fs->status = ATTO_STS_FAILED;
fs->driver_error = RS_PENDING;
@@ -860,18 +861,18 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
return false;
}
- if (fsc->command >= cmdcnt) {
+ if (command >= cmdcnt) {
fs->status = ATTO_STS_INV_FUNC;
return false;
}
- func = cmd_to_fls_func[fsc->command];
+ func = cmd_to_fls_func[command];
if (func == 0xFF) {
fs->status = ATTO_STS_INV_FUNC;
return false;
}
- if (fsc->command != ESAS2R_FS_CMD_CANCEL) {
+ if (command != ESAS2R_FS_CMD_CANCEL) {
if ((a->pcid->device != ATTO_DID_MV_88RC9580
|| fs->adap_type != ESAS2R_FS_AT_ESASRAID2)
&& (a->pcid->device != ATTO_DID_MV_88RC9580TS
--
2.17.1
next reply other threads:[~2020-08-02 15:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-02 15:21 Jia-Ju Bai [this message]
2020-08-02 15:47 ` [PATCH] scsi: esas2r: fix possible buffer overflow caused by bad DMA value in esas2r_process_fs_ioctl() James Bottomley
2020-08-03 3:07 ` Jia-Ju Bai
2020-08-03 5:51 ` 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=20200802152145.4387-1-baijiaju@tsinghua.edu.cn \
--to=baijiaju@tsinghua.edu.cn \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linuxdrivers@attotech.com \
--cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).