Linux-SCSI Archive on lore.kernel.org
 help / color / Atom feed
From: "zhengbin (A)" <zhengbin13@huawei.com>
To: Finn Thain <fthain@telegraphics.com.au>
Cc: <bvanassche@acm.org>, <jejb@linux.ibm.com>,
	<martin.petersen@oracle.com>, <linux-scsi@vger.kernel.org>,
	<yi.zhang@huawei.com>
Subject: Re: [PATCH v3] scsi: core: fix uninit-value access of variable sshdr
Date: Thu, 17 Oct 2019 09:16:24 +0800
Message-ID: <7353d3a6-f763-d52c-c405-ef5f32c4c259@huawei.com> (raw)
In-Reply-To: <alpine.LNX.2.21.1910171101460.32@nippy.intranet>


On 2019/10/17 8:05, Finn Thain wrote:
> On Sat, 12 Oct 2019, zhengbin wrote:
>
>> kmsan report a warning in 5.1-rc4:
>>
>> BUG: KMSAN: uninit-value in sr_get_events drivers/scsi/sr.c:207 [inline]
>> BUG: KMSAN: uninit-value in sr_check_events+0x2cf/0x1090 drivers/scsi/sr.c:243
>> CPU: 1 PID: 13858 Comm: syz-executor.0 Tainted: G    B             5.1.0-rc4+ #8
>> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014
>> Call Trace:
>>  __dump_stack lib/dump_stack.c:77 [inline]
>>  dump_stack+0x173/0x1d0 lib/dump_stack.c:113
>>  kmsan_report+0x131/0x2a0 mm/kmsan/kmsan.c:619
>>  __msan_warning+0x7a/0xf0 mm/kmsan/kmsan_instr.c:310
>>  sr_get_events drivers/scsi/sr.c:207 [inline]
>>  sr_check_events+0x2cf/0x1090 drivers/scsi/sr.c:243
>>
>> The reason is as follows:
>> sr_get_events
>>   struct scsi_sense_hdr sshdr;  -->uninit
>>   scsi_execute_req              -->If fail, will not set sshdr
>>   scsi_sense_valid(&sshdr)      -->access sshdr
>>
>> We can init sshdr in sr_get_events, but there have many callers of
>> scsi_execute, scsi_execute_req, we have to troubleshoot all callers,
>> the simpler way is init sshdr in __scsi_execute.
>>
>> BTW: sr_do_ioctl should check whether sshdr is valid, fix this
>>
>> Signed-off-by: zhengbin <zhengbin13@huawei.com>
>> ---
>> v1->v2: modify the comments suggested by Bart
>> v2->v3: fix bug in sr_do_ioctl
>>  drivers/scsi/scsi_lib.c | 7 +++++++
>>  drivers/scsi/sr_ioctl.c | 5 +++++
>>  2 files changed, 12 insertions(+)
>>
>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
>> index 5447738..d5e29c5 100644
>> --- a/drivers/scsi/scsi_lib.c
>> +++ b/drivers/scsi/scsi_lib.c
>> @@ -255,6 +255,13 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
>>  	struct scsi_request *rq;
>>  	int ret = DRIVER_ERROR << 24;
>>
>> +	/*
>> +	 * Zero-initialize sshdr for those callers that check the *sshdr
>> +	 * contents even if no sense data is available.
>> +	 */
>> +	if (sshdr)
>> +		memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
>> +
>>  	req = blk_get_request(sdev->request_queue,
>>  			data_direction == DMA_TO_DEVICE ?
>>  			REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT);
> Does this have any effect? It appears __scsi_execute() calls 
> scsi_normalize_sense(), which already does
> memset(sshdr, 0, sizeof(struct scsi_sense_hdr)).

__scsi_execute

  if (IS_ERR(req))  -->not init

    return ret;


  if (bufflen && ...) -->not init

    goto out;


scsi_normalize_sense

>


  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-12  3:25 zhengbin
2019-10-17  0:05 ` Finn Thain
2019-10-17  1:16   ` zhengbin (A) [this message]
2019-10-17  2:45 ` Bart Van Assche
2019-10-17  3:26   ` zhengbin (A)

Reply instructions:

You may reply publically 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=7353d3a6-f763-d52c-c405-ef5f32c4c259@huawei.com \
    --to=zhengbin13@huawei.com \
    --cc=bvanassche@acm.org \
    --cc=fthain@telegraphics.com.au \
    --cc=jejb@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yi.zhang@huawei.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

Linux-SCSI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-scsi/0 linux-scsi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-scsi linux-scsi/ https://lore.kernel.org/linux-scsi \
		linux-scsi@vger.kernel.org
	public-inbox-index linux-scsi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-scsi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git