* [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
@ 2017-12-22 15:55 Paolo Bonzini
2017-12-22 16:12 ` Roman Kagan
2018-01-04 17:42 ` Eric Blake
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2017-12-22 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: rkagan
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 <rkagan@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scsi/utils.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scsi/utils.c b/scsi/utils.c
index ddae650a99..8738522955 100644
--- a/scsi/utils.c
+++ b/scsi/utils.c
@@ -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)
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
2017-12-22 15:55 [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0 Paolo Bonzini
@ 2017-12-22 16:12 ` Roman Kagan
2018-01-04 17:42 ` Eric Blake
1 sibling, 0 replies; 3+ messages in thread
From: Roman Kagan @ 2017-12-22 16:12 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On Fri, Dec 22, 2017 at 04:55:22PM +0100, Paolo Bonzini wrote:
> 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 <rkagan@virtuozzo.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> scsi/utils.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
Tested-by: Roman Kagan <rkagan@virtuozzo.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
2017-12-22 15:55 [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0 Paolo Bonzini
2017-12-22 16:12 ` Roman Kagan
@ 2018-01-04 17:42 ` Eric Blake
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2018-01-04 17:42 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: rkagan
[-- Attachment #1: Type: text/plain, Size: 672 bytes --]
On 12/22/2017 09:55 AM, Paolo Bonzini wrote:
> 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 <rkagan@virtuozzo.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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 ?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-04 17:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-22 15:55 [Qemu-devel] [PATCH] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0 Paolo Bonzini
2017-12-22 16:12 ` Roman Kagan
2018-01-04 17:42 ` Eric Blake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).