Skip to contentSkip to conversation

hw/scsi/lsi53c895a: add missing decrement of reentrancy counter

PATCH In review Sven Schnelle 4 participants 5 messages Jan 28, 2024 – Jan 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/scsi/lsi53c895a: add missing decrement of reentrancy counter

When the maximum count of SCRIPTS instructions is reached, the code stops execution and returns, but fails to decrement the reentrancy counter. This effectively renders the SCSI controller unusable because on next entry the reentrancy counter is still above the limit.

This bug was seen on HP-UX 10.20 which seems to trigger SCRIPTS loops.

Fixes b987718bbb ("hw/scsi/lsi53c895a: Fix reentrancy issues in the LSI controller (CVE-2023-0330)")
---
 hw/scsi/lsi53c895a.c | 1 +
 1 file changed, 1 insertion(+)
hw/scsi/lsi53c895a.c +1 -0
index 34e3b89287..d607a5f9fb 100644
@@ -1159,6 +1159,7 @@ again:
         lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
         lsi_disconnect(s);
         trace_lsi_execute_script_stop();
+        reentrancy_level--;
         return;
     }
     insn = read_dword(s, s->dsp);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Sven Schnelle

When the maximum count of SCRIPTS instructions is reached, the code stops execution and returns, but fails to decrement the reentrancy counter. This effectively renders the SCSI controller unusable because on next entry the reentrancy counter is still above the limit.

This bug was seen on HP-UX 10.20 which seems to trigger SCRIPTS loops.

Out of curiosity: What happened there before we introduced the reentrancy_level fix? Did it end up in an endless loop, or was it finishing at one point? In the latter case, we might need to adjust the "reentrancy_level > 8" to allow deeper nesting.

Quoted 11 lines
Fixes b987718bbb ("hw/scsi/lsi53c895a: Fix reentrancy issues in the LSI controller (CVE-2023-0330)")
---
  hw/scsi/lsi53c895a.c | 1 +
  1 file changed, 1 insertion(+)
hw/scsi/lsi53c895a.c +0 -0
index 34e3b89287..d607a5f9fb 100644

hw/scsi/lsi53c895a.c again: · line 1165

Quoted 7 lines
hw/scsi/lsi53c895a.c +1 -0
@@ -1159,6 +1159,7 @@ again:
          lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
          lsi_disconnect(s);
          trace_lsi_execute_script_stop();
+        reentrancy_level--;
          return;
      }
      insn = read_dword(s, s->dsp);
#2 lore raw
Quoted 8 lines · Thomas Huth
Quoted 6 lines · Sven Schnelle

When the maximum count of SCRIPTS instructions is reached, the code stops execution and returns, but fails to decrement the reentrancy counter. This effectively renders the SCSI controller unusable because on next entry the reentrancy counter is still above the limit. This bug was seen on HP-UX 10.20 which seems to trigger SCRIPTS loops.

Quoted 4 lines

Out of curiosity: What happened there before we introduced the reentrancy_level fix? Did it end up in an endless loop, or was it finishing at one point? In the latter case, we might need to adjust the "reentrancy_level > 8" to allow deeper nesting.

Without the reentrancy counter it was triggering the insn_processed limit. The HP-UX scsi driver seems to spin on some memory value during some SCSI writes (CDB with command 0x2a). So it is spinning in an endless loop until the insn_processed counter will trigger the exit. In HP-UX you will see a SCSI command timeout error in the kernel log
- at least i'm assuming that's related, but can't say for sure as there's no kernel source available.

#3 lore raw
In reply to Sven Schnelle

28.01.2024 23:22, Sven Schnelle :

Quoted 7 lines

When the maximum count of SCRIPTS instructions is reached, the code stops execution and returns, but fails to decrement the reentrancy counter. This effectively renders the SCSI controller unusable because on next entry the reentrancy counter is still above the limit.

This bug was seen on HP-UX 10.20 which seems to trigger SCRIPTS loops.

Cc qemu-stable@

/mjt

Tested-by on v1 1/1
#4 lore raw
In reply to Sven Schnelle
Quoted 10 lines · Sven Schnelle

When the maximum count of SCRIPTS instructions is reached, the code stops execution and returns, but fails to decrement the reentrancy counter. This effectively renders the SCSI controller unusable because on next entry the reentrancy counter is still above the limit.

This bug was seen on HP-UX 10.20 which seems to trigger SCRIPTS loops.

Fixes b987718bbb ("hw/scsi/lsi53c895a: Fix reentrancy issues in the LSI controller (CVE-2023-0330)")

Thanks!
Helge

Quoted 16 lines
---
  hw/scsi/lsi53c895a.c | 1 +
  1 file changed, 1 insertion(+)
hw/scsi/lsi53c895a.c +1 -0
index 34e3b89287..d607a5f9fb 100644
@@ -1159,6 +1159,7 @@ again:
          lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
          lsi_disconnect(s);
          trace_lsi_execute_script_stop();
+        reentrancy_level--;
          return;
      }
      insn = read_dword(s, s->dsp);