lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 9 Dec 2020 17:38:05 +0000
From:   John Garry <john.garry@...wei.com>
To:     Xiaohui Zhang <ruc_zhangxiaohui@....com>,
        "James E.J. Bottomley" <jejb@...ux.ibm.com>,
        "Martin K. Petersen" <martin.petersen@...cle.com>,
        <linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/1] hisi_sas: Fix possible buffer overflows in
 prep_ssp_v3_hw

On 09/12/2020 12:48, Xiaohui Zhang wrote:
> From: Zhang Xiaohui <ruc_zhangxiaohui@....com>
> 
> prep_ssp_v3_hw() calls memcpy() without checking the destination
> size may trigger a buffer overflower.
> 
> buf_cmd should be a ssp_tmf_iu struct through the analysis of

hmmm... but you change the !tmf path.

> the command below:
> buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
>          sizeof(struct ssp_frame_hdr);
> 
> Then buf_cmd + 12 should point to tag, so the length parameter
> of memcpy() should not exceed sizeof(__be16)+sizeof(u8)*14):
> struct ssp_tmf_iu {
>      u8     lun[8];
>      u16    _r_a;
>      u8     tmf;
>      u8     _r_b;
>      __be16 tag;
>      u8     _r_c[14];
> } __attribute__ ((packed));
> 
> Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@....com>
> ---
>   drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 4 +++-
>   1 file changed, 3 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..d02831c17 100644
> --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> @@ -1267,7 +1267,9 @@ 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,
> +			     sizeof(__be16) + sizeof(u8) * 14));

Again, this is not the right thing to do, and I don't think that this 
code needs fixing at all.

There should be a contract already that the driver is not sent cdb len > 
16, and this is sizeof(ssp_command_iu.cdb).

And, if we were sent too much data, then we would/should error.

Thanks,
John

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ