* [PATCH 1/1] hisi_sas: Fix possible buffer overflows in prep_ssp_v3_hw
@ 2020-12-08 16:40 Xiaohui Zhang
2020-12-08 18:10 ` John Garry
0 siblings, 1 reply; 2+ messages in thread
From: Xiaohui Zhang @ 2020-12-08 16:40 UTC (permalink / raw)
To: Xiaohui Zhang, John Garry, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
From: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
prep_ssp_v3_hw() calls memcpy() without checking the
destination size may trigger a buffer overflower, which a
local user could use to cause denial of service or the
execution of arbitrary code.
Fix it by putting the length check before calling memcpy().
Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
---
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 7133ca859..2664c36d3 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -1267,7 +1267,8 @@ static void prep_ssp_v3_hw(struct hisi_hba *hisi_hba,
memcpy(buf_cmd, &task->ssp_task.LUN, 8);
if (!tmf) {
buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3);
- memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
+ memcpy(buf_cmd + 12, scsi_cmnd->cmnd,
+ min_t(unsigned short, scsi_cmnd->cmd_len, strlen(buf_cmd)-12));
} else {
buf_cmd[10] = tmf->tmf;
switch (tmf->tmf) {
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] hisi_sas: Fix possible buffer overflows in prep_ssp_v3_hw
2020-12-08 16:40 [PATCH 1/1] hisi_sas: Fix possible buffer overflows in prep_ssp_v3_hw Xiaohui Zhang
@ 2020-12-08 18:10 ` John Garry
0 siblings, 0 replies; 2+ messages in thread
From: John Garry @ 2020-12-08 18:10 UTC (permalink / raw)
To: Xiaohui Zhang, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, linux-kernel
On 08/12/2020 16:40, Xiaohui Zhang wrote:
> From: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
>
> prep_ssp_v3_hw() calls memcpy() without checking the
> destination size may trigger a buffer overflower, which a
> local user could use to cause denial of service or the
> execution of arbitrary code.
> Fix it by putting the length check before calling memcpy().
>
> Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
> ---
> drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> index 7133ca859..2664c36d3 100644
> --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> @@ -1267,7 +1267,8 @@ static void prep_ssp_v3_hw(struct hisi_hba *hisi_hba,
> memcpy(buf_cmd, &task->ssp_task.LUN, 8);
> if (!tmf) {
> buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3);
> - memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
> + memcpy(buf_cmd + 12, scsi_cmnd->cmnd,
> + min_t(unsigned short, scsi_cmnd->cmd_len, strlen(buf_cmd)-12));
buf_cmd is not a NULL-terminated string, it's actually a pointer to a
structure.
And you can see that we set buf_cmd[9] previously (which could set as
0), so how can you possibly rely on a strlen(buf_cmd) - 12 being sane?
Thanks,
john
> } else {
> buf_cmd[10] = tmf->tmf;
> switch (tmf->tmf) {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-08 18:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 16:40 [PATCH 1/1] hisi_sas: Fix possible buffer overflows in prep_ssp_v3_hw Xiaohui Zhang
2020-12-08 18:10 ` John Garry
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).