Skip to contentSkip to conversation

xilinx_spips: Correct usage of an uninitialized local variable

PATCH Superseded Francisco Iglesias 2 participants 3 messages Jan 14, 2018 – Jan 16, 2018 Arm/Zynq architecture

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xilinx_spips: Correct usage of an uninitialized local variable

Coverity found that the variable tx_rx in the function xilinx_spips_flush_txfifo was being used uninitialized (CID 1383841). This patch corrects this by always initializing tx_rx to zeros.

---
 hw/ssi/xilinx_spips.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ssi/xilinx_spips.c +3 -1
index d8187fa..77e1bbe 100644
@@ -210,6 +210,8 @@
 #define SNOOP_NONE 0xEE
 #define SNOOP_STRIPING 0
 
+#define MAX_NUM_EFFECTIVE_BUSSES 2
+
 static inline int num_effective_busses(XilinxSPIPS *s)
 {
     return (s->regs[R_LQSPI_CFG] & LQSPI_CFG_SEP_BUS &&
@@ -573,7 +575,7 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s)
     for (;;) {
         int i;
         uint8_t tx = 0;
-        uint8_t tx_rx[num_effective_busses(s)];
+        uint8_t tx_rx[MAX_NUM_EFFECTIVE_BUSSES] = { 0 };
         uint8_t dummy_cycles = 0;
         uint8_t addr_length;
 
Signature · 1 line
2.9.3
#1 lore raw
Quoted 23 lines · Francisco Iglesias

Coverity found that the variable tx_rx in the function xilinx_spips_flush_txfifo was being used uninitialized (CID 1383841). This patch corrects this by always initializing tx_rx to zeros.

---
 hw/ssi/xilinx_spips.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ssi/xilinx_spips.c +2 -0
index d8187fa..77e1bbe 100644
@@ -210,6 +210,8 @@
 #define SNOOP_NONE 0xEE
 #define SNOOP_STRIPING 0
 
+#define MAX_NUM_EFFECTIVE_BUSSES 2
+
 static inline int num_effective_busses(XilinxSPIPS *s)
 {
     return (s->regs[R_LQSPI_CFG] & LQSPI_CFG_SEP_BUS &&

hw/ssi/xilinx_spips.c static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) · line 580

Quoted 7 lines
hw/ssi/xilinx_spips.c +1 -1
@@ -573,7 +575,7 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s)
     for (;;) {
         int i;
         uint8_t tx = 0;
-        uint8_t tx_rx[num_effective_busses(s)];
+        uint8_t tx_rx[MAX_NUM_EFFECTIVE_BUSSES] = { 0 };
         uint8_t dummy_cycles = 0;
         uint8_t addr_length;

It doesn't look like your device's realize method is sanity checking the num_busses property, so this change means that the user can make the device model segfault by passing it a num_busses property value larger than 2...

thanks
-- PMM

#2 lore raw
Quoted 35 lines · Peter Maydell
Quoted 2 lines · Francisco Iglesias

Coverity found that the variable tx_rx in the function xilinx_spips_flush_txfifo was being used uninitialized (CID 1383841).

This

hw/ssi/xilinx_spips.c static void xilinx_spips_flush_txfifo(XilinxSPIPS

Quoted 21 lines

patch corrects this by always initializing tx_rx to zeros.

---
 hw/ssi/xilinx_spips.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ssi/xilinx_spips.c +2 -0
index d8187fa..77e1bbe 100644
@@ -210,6 +210,8 @@
 #define SNOOP_NONE 0xEE
 #define SNOOP_STRIPING 0
 
+#define MAX_NUM_EFFECTIVE_BUSSES 2
+
 static inline int num_effective_busses(XilinxSPIPS *s)
 {
     return (s->regs[R_LQSPI_CFG] & LQSPI_CFG_SEP_BUS &&
@@ -573,7 +575,7 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS

*s)

hw/ssi/xilinx_spips.c static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) · line 580

Quoted 7 lines
hw/ssi/xilinx_spips.c +1 -1
     for (;;) {
         int i;
         uint8_t tx = 0;
-        uint8_t tx_rx[num_effective_busses(s)];
+        uint8_t tx_rx[MAX_NUM_EFFECTIVE_BUSSES] = { 0 };
         uint8_t dummy_cycles = 0;
         uint8_t addr_length;
Quoted 8 lines

It doesn't look like your device's realize method is sanity checking the num_busses property, so this change means that the user can make the device model segfault by passing it a num_busses property value larger than 2...

thanks
-- PMM

Hi Peter,

Thank you very much for reviewing the patch and I apologize for missing out on above. I'll look into a correction and create a new version of the patch.

Best regards,
Francisco Iglesias