Skip to contentSkip to conversation

htif: reject invalid signature ranges (end <= begin)

PATCH Superseded heropd 1 participant 1 message Nov 27, 2025 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

heropd

author
#0 lore raw

PATCH 1/1 htif: reject invalid signature ranges (end <= begin)

From: Munkhbaatar Enkhbaatar <[email protected]>

Prevents huge allocations and crashes caused by malformed HTIF signature addresses.
Fixes: link to issue #3205

---
 hw/char/riscv_htif.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/char/riscv_htif.c +5 -0
index a78ea9b01c..aa205c84c0 100644
@@ -170,6 +170,11 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)
                  * begin/end_signature symbols exist.
                  */
                 if (sig_file && begin_sig_addr && end_sig_addr) {
+                    if (end_sig_addr <= begin_sig_addr) {
+                        error_report("Invalid HTIF signature range: begin=0x%llx end=0x%llx",
+                                    begin_sig_addr, end_sig_addr);
+                        return;
+                    }
                     uint64_t sig_len = end_sig_addr - begin_sig_addr;
                     char *sig_data = g_malloc(sig_len);
                     dma_memory_read(&address_space_memory, begin_sig_addr,
Signature · 1 line
2.50.1 (Apple Git-155)