mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: sr: Fix a potential uninit-value in sr_get_events()
@ 2023-05-31 16:43 Shigeru Yoshida
  2023-05-31 22:44 ` Bart Van Assche
  0 siblings, 1 reply; 4+ messages in thread
From: Shigeru Yoshida @ 2023-05-31 16:43 UTC (permalink / raw)
  To: jejb, martin.petersen; +Cc: linux-scsi, linux-kernel, Shigeru Yoshida

KMSAN found the following issue:

 BUG: KMSAN: uninit-value in sr_check_events+0x365/0x1460
  sr_check_events+0x365/0x1460
  cdrom_check_events+0x66/0x170
  sr_block_check_events+0xf2/0x130
  disk_check_events+0xec/0x900
  bdev_check_media_change+0x2a6/0x7d0
  sr_block_open+0x154/0x320
  blkdev_get_whole+0xa8/0x6c0
  blkdev_get_by_dev+0x50f/0x1200
  blkdev_open+0x215/0x430
  do_dentry_open+0xfbd/0x19a0
  vfs_open+0x7b/0xa0
  path_openat+0x4a54/0x5b40
  do_filp_open+0x24d/0x660
  do_sys_openat2+0x1f0/0x910
  __x64_sys_openat+0x2b4/0x330
  do_syscall_64+0x41/0xc0
  entry_SYSCALL_64_after_hwframe+0x63/0xcd

 Local variable sshdr.i created at:
  sr_check_events+0x131/0x1460
  cdrom_check_events+0x66/0x170

sr_get_events() can access uninitialized local variable sshdr when
scsi_execute_cmd() returns error.  This patch fixes the issue by
checking the result before accessing sshdr.

Fixes: 93aae17af117 ("sr: implement sr_check_events()")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
---
 drivers/scsi/sr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 12869e6d4ebd..86b43c069a44 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -177,10 +177,13 @@ static unsigned int sr_get_events(struct scsi_device *sdev)
 
 	result = scsi_execute_cmd(sdev, cmd, REQ_OP_DRV_IN, buf, sizeof(buf),
 				  SR_TIMEOUT, MAX_RETRIES, &exec_args);
+	if (result)
+		return 0;
+
 	if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION)
 		return DISK_EVENT_MEDIA_CHANGE;
 
-	if (result || be16_to_cpu(eh->data_len) < sizeof(*med))
+	if (be16_to_cpu(eh->data_len) < sizeof(*med))
 		return 0;
 
 	if (eh->nea || eh->notification_class != 0x4)
-- 
2.39.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-30 15:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31 16:43 [PATCH] scsi: sr: Fix a potential uninit-value in sr_get_events() Shigeru Yoshida
2023-05-31 22:44 ` Bart Van Assche
2023-10-30  8:13   ` Shigeru Yoshida
2023-10-30 15:02     ` michael.christie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®