]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
accel/tcg: Fix uninitialized hostp in get_page_addr_code_hostp
authorRichard Henderson <richard.henderson@linaro.org>
Wed, 28 Jan 2026 01:04:30 +0000 (12:04 +1100)
committerRichard Henderson <richard.henderson@linaro.org>
Fri, 6 Feb 2026 06:51:09 +0000 (16:51 +1000)
This uninitialized value violates the contract in the
documentation comment, and may lead to a SEGV during
translaton with -d in_asm.

Change the documentation to disallow hostp NULL.
Pass hostp to probe_access_internal directly.

Reported-by: Panda Jiang <3160104094@zju.edu.cn>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
accel/tcg/cputlb.c
accel/tcg/internal-common.h
accel/tcg/user-exec.c

index 76546c66515177d481e7692738e0740ab6e8fe4e..3d75abbe689496a2434cf65ace1f791a100dc572 100644 (file)
@@ -1545,18 +1545,18 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr,
 
     (void)probe_access_internal(env_cpu(env), addr, 1, MMU_INST_FETCH,
                                 cpu_mmu_index(env_cpu(env), true), false,
-                                &p, &full, 0, false);
+                                hostp, &full, 0, false);
+
+    p = *hostp;
     if (p == NULL) {
         return -1;
     }
 
     if (full->lg_page_size < TARGET_PAGE_BITS) {
+        *hostp = NULL;
         return -1;
     }
 
-    if (hostp) {
-        *hostp = p;
-    }
     return qemu_ram_addr_from_host_nofail(p);
 }
 
index 0ca13750f98df82d41c3e14949368c583d15c64d..9e7be2d78dfd6739e01d81bccd03664b4ae0001a 100644 (file)
@@ -82,7 +82,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr);
  * See get_page_addr_code() (full-system version) for documentation on the
  * return value.
  *
- * Sets *@hostp (when @hostp is non-NULL) as follows.
+ * Sets *@hostp as follows.
  * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp
  * to the host address where @addr's content is kept.
  *
index ddbdc0432d7bc6f0e676169142c428a24d01f7ae..f8b4a2671112c1553ff5cec59503873c8b36f309 100644 (file)
@@ -822,9 +822,7 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr,
     flags = probe_access_internal(env, addr, 1, MMU_INST_FETCH, false, 0);
     g_assert(flags == 0);
 
-    if (hostp) {
-        *hostp = g2h_untagged(addr);
-    }
+    *hostp = g2h_untagged(addr);
     return addr;
 }