Skip to contentSkip to conversation

scsi: mptconfig: fix format string

PATCH In review P J P 2 participants 3 messages Aug 31, 2016 – Sep 1, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/2 scsi: mptconfig: fix format string

From: Prasad J Pandit <[email protected]>

When LSI SAS1068 Host Bus emulator builds configuration page headers, the format string used in 'mptsas_config_manufacturing_1' was wrong. It could lead to an invalid memory access.

---
 hw/scsi/mptconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/mptconfig.c +1 -1
index 7071854..1ec895b 100644
@@ -203,7 +203,7 @@ size_t mptsas_config_manufacturing_1(MPTSASState *s, uint8_t **data, int address
 {
     /* VPD - all zeros */
     return MPTSAS_CONFIG_PACK(1, MPI_CONFIG_PAGETYPE_MANUFACTURING, 0x00,
-                              "s256");
+                              "*s256");
 }
 
 static
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH 2/2 scsi: mptconfig: fix an assert expression

From: Prasad J Pandit <[email protected]>

When LSI SAS1068 Host Bus emulator builds configuration page headers, mptsas_config_pack() asserts to check returned size value is within limit of 256 bytes. Fix that assert expression.

---
 hw/scsi/mptconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/mptconfig.c +1 -1
index 1ec895b..531947f 100644
@@ -158,7 +158,7 @@ static size_t mptsas_config_pack(uint8_t **data, const char *fmt, ...)
     va_end(ap);
 
     if (data) {
-        assert(ret < 256 && (ret % 4) == 0);
+        assert(ret / 4 < 256);
         stb_p(*data + 1, ret / 4);
     }
     return ret;
Signature · 1 line
2.5.5
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] scsi: mptconfig: fix an assert expression

Quoted 6 lines · P J P
hw/scsi/mptconfig.c +0 -0
index 1ec895b..531947f 100644

hw/scsi/mptconfig.c static size_t mptsas_config_pack(uint8_t **data, const char *fmt, ...) · line 164

Quoted 8 lines
hw/scsi/mptconfig.c +1 -1
@@ -158,7 +158,7 @@ static size_t mptsas_config_pack(uint8_t **data, const char *fmt, ...)
     va_end(ap);
 
     if (data) {
-        assert(ret < 256 && (ret % 4) == 0);
+        assert(ret / 4 < 256);
         stb_p(*data + 1, ret / 4);
     }
     return ret;

The (ret % 4) == 0 part is still useful. Here is the patch I'm committing with a commit message that explains the change:

commit f7a080e249008fdb90b070dff15d45690b6a06b8

Author: Prasad J Pandit <[email protected]>
Date:   Wed Aug 31 17:36:07 2016 +0530

scsi: mptconfig: fix an assert expression

When LSI SAS1068 Host Bus emulator builds configuration page headers, mptsas_config_pack() should assert that the size fits in a byte. However, the size is expressed in 32-bit units, so up to 1020 bytes fit. The assertion was only allowing replies up to 252 bytes, so fix it.

Message-Id: <[email protected]>

hw/scsi/mptconfig.c +1 -1
index 7071854..3e4f400 100644
@@ -158,7 +158,7 @@ static size_t mptsas_config_pack(uint8_t **data, const char *fmt, ...)
     va_end(ap);
 
     if (data) {
-        assert(ret < 256 && (ret % 4) == 0);
+        assert(ret / 4 < 256 && (ret % 4) == 0);
         stb_p(*data + 1, ret / 4);
     }
     return ret;