scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
PATCH 1/1 scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
scsi_disk_emulate_command passes in_buf == NULL when sent a REQUEST SENSE command. Check for in_len == 0 before dereferencing in_buf.
Fixes f68d98b21fa74155dc7c1fd212474379ac3c7531
Reported-by Roman Kagan <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
--- scsi/utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
scsi/utils.c +6 -6
@@ -322,18 +322,18 @@ int scsi_convert_sense(uint8_t *in_buf, int in_len,SCSISense sense;bool fixed_in; +if (in_len ==0 ) { +return scsi_build_sense_buf (buf, len,SENSE_CODE (NO_SENSE ), fixed); + } + fixed_in = (in_buf[0 ] &2 ) ==0 ; -if (in_len && fixed == fixed_in) { +if (fixed == fixed_in) {memcpy (buf, in_buf,MIN (len, in_len));return MIN (len, in_len); - } - -if (in_len ==0 ) { - sense =SENSE_CODE (NO_SENSE ); }else { sense =scsi_parse_sense_buf (in_buf, in_len); +return scsi_build_sense_buf (buf, len, sense, fixed); } -return scsi_build_sense_buf (buf, len, sense, fixed); }int scsi_sense_to_errno (int key,int asc,int ascq)
Signature · 1 line
2.14.3
Quoted 9 lines · Paolo Bonzini
scsi_disk_emulate_commandpassesin_buf== NULL when sent a REQUEST SENSE command. Check forin_len== 0 before dereferencingin_buf.Fixes f68d98b21fa74155dc7c1fd212474379ac3c7531Reported-by Roman Kagan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- scsi/utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Tested-by Roman Kagan <[email protected]>
Quoted 9 lines · Paolo Bonzini
scsi_disk_emulate_commandpassesin_buf== NULL when sent a REQUEST SENSE command. Check forin_len== 0 before dereferencingin_buf.Fixes f68d98b21fa74155dc7c1fd212474379ac3c7531Reported-by Roman Kagan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- scsi/utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
How does this compare to
https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg00582.html ?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org