Skip to contentSkip to conversation

scsi-disk: handle invalid cdb length

PATCH Superseded Bruce Rogers 3 participants 4 messages Apr 29, 2019 – May 1, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi-disk: handle invalid cdb length

While investigating link-time-optimization, the compiler flagged this case of not handling the error return from scsi_cdb_length(). Handle this error case with a trace report.

---
 hw/scsi/scsi-disk.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/scsi/scsi-disk.c +4 -0
index e7e865ab3b..dc13c892ef 100644
@@ -2520,6 +2520,10 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)
     int len = scsi_cdb_length(buf);
     char *line_buffer, *p;
 
+    if (len < 0) {
+        trace_scsi_disk_new_request(lun, tag, "bad cdb length!");
+        return;
+    }
     line_buffer = g_malloc(len * 5 + 1);
 
     for (i = 0, p = line_buffer; i < len; i++) {
Signature · 1 line
2.21.0
#1 lore raw
Quoted 14 lines · Bruce Rogers

While investigating link-time-optimization, the compiler flagged this case of not handling the error return from scsi_cdb_length(). Handle this error case with a trace report.

---
 hw/scsi/scsi-disk.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/scsi/scsi-disk.c +0 -0
index e7e865ab3b..dc13c892ef 100644

hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2524

Quoted 5 lines
hw/scsi/scsi-disk.c +2 -0
@@ -2520,6 +2520,10 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf)
     int len = scsi_cdb_length(buf);
     char *line_buffer, *p;
 
+    if (len < 0) {
+        trace_scsi_disk_new_request(lun, tag, "bad cdb length!");

I'd drop the !. We aren't shouting at the trace clients, after all :)

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Eric Blake

hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun,

Quoted 14 lines · Bruce Rogers

While investigating link-time-optimization, the compiler flagged this case of not handling the error return from scsi_cdb_length(). Handle this error case with a trace report.

---
 hw/scsi/scsi-disk.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/scsi/scsi-disk.c +0 -0
index e7e865ab3b..dc13c892ef 100644
@@ -2520,6 +2520,10 @@ static void scsi_disk_new_request_dump(uint32_t lun, 

uint32_t tag, uint8_t *buf)

Quoted 7 lines

hw/scsi/scsi-disk.c static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) · line 2524

Quoted 5 lines
hw/scsi/scsi-disk.c +2 -0
     int len = scsi_cdb_length(buf);
     char *line_buffer, *p;
 
+    if (len < 0) {
+        trace_scsi_disk_new_request(lun, tag, "bad cdb length!");

I'd drop the !. We aren't shouting at the trace clients, after all :)

Got it.

Bruce

#3 lore raw
In reply to Bruce Rogers
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===

The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]