scsi-generic: Check sense key before request snooping and patching
commit1849f297f5952ea60ddfd39fe02ce21cba6aa4d8
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 18 Jul 2019 09:42:36 +0000 (18 11:42 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 19 Jul 2019 17:04:49 +0000 (19 19:04 +0200)
tree8835126239cf372dca342517a81359c3af4f7a26
parent68fa7ca015dc8afb86e3aa51b31362f63048bd5c
scsi-generic: Check sense key before request snooping and patching

When READ CAPACITY command completes, scsi_read_complete() function
snoops the command result and updates SCSIDevice members blocksize and
max_lba . However, this update is executed even when READ CAPACITY
command indicates an error in sense data. This causes unexpected
blocksize update with zero value for SCSI devices without
READ CAPACITY(10) command support and eventually results in a divide
by zero. An emulated device by TCMU-runner is an example of a device
that doesn't support READ CAPACITY(10) command.

To avoid the unexpected update, add sense key check in
scsi_read_complete() function. The function already checks the sense key
for VPD Block Limits emulation. Do the scsi_parse_sense_buf() call for
all requests rather than just for VPD Block Limits emulation, so that
blocksize and max_lba are only updated if READ CAPACITY returns zero
sense key.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
[Extend the check to all requests, not just READ CAPACITY]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/scsi-generic.c