Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues: - [High] Unconditional loading of the secure kernel overwrites VTL1 memory even if VTL1 is already active, leading to memory corruption or fatal faults. Pre-existing issues: - [High] Missing bounds check when parsing ELF program headers from firmware, leading to potential out-of-bounds read. -- commit 58f06b8de69e2f750e55a8ff7220ab38d88c0f8f Author: Thara Gopinath <[email protected]> drivers: hv: hv_vsm_boot: Enable VTL1 on the boot processor This commit introduces helpers to get VP status and enable VTL1 on the boot virtual processor. It extends hv_vsm_bootstrap_vtl() to enable VTL1 on the boot VP if it is not already enabled, and re-queries the status to confirm the transition. > diff --git a/drivers/hv/hv_vsm_boot.c b/drivers/hv/hv_vsm_boot.c > index dc20f935da5b2..abe82e03e1897 100644 > --- a/drivers/hv/hv_vsm_boot.c > +++ b/drivers/hv/hv_vsm_boot.c > @@ -216,6 +216,47 @@ static int __init hv_vsm_load_secure_kernel(Elf64_Addr > *sk_entry_pa) > return ret; > } [Severity: High] This isn't a bug introduced by this patch, but there appears to be a missing bounds check when parsing ELF program headers from the firmware in hv_vsm_load_elf() which is called by hv_vsm_load_secure_kernel(). The firmware size (fw->size) is discarded instead of being passed to hv_vsm_load_elf() for validation. Inside hv_vsm_load_elf(), the program header table offset (e_phoff) is never bounds-checked against the firmware size before being iterated over: drivers/hv/hv_vsm_boot.c:hv_vsm_load_elf() { ... Elf64_Phdr *phdr = image + ehdr->e_phoff; ... } Later, the memcpy() copies uncontrolled lengths of kernel memory based on untrusted firmware headers: drivers/hv/hv_vsm_boot.c:hv_vsm_load_elf() { ... memcpy(load_addr, image + phdr->p_offset, phdr->p_filesz); ... } Could a malformed or maliciously crafted firmware file cause an out-of-bounds read past the end of the firmware buffer, potentially leaking sensitive kernel data into the secure kernel's memory or causing a kernel panic? [ ... ] > @@ -300,7 +342,34 @@ static int __init hv_vsm_bootstrap_vtl(void) > } > } > > - return hv_vsm_load_secure_kernel(&sk_entry_pa); > + ret = hv_vsm_load_secure_kernel(&sk_entry_pa); > + if (ret) > + return ret; > + > + /* Check and enable VTL1 for the primary virtual processor */ > + ret = hv_vsm_get_vp_status(&vp_enabled_vtl_set, &active_mbec_enabled); > + if (ret) > + return ret; > + > + if (vp_enabled_vtl_set & HV_VTL1_ENABLE_BIT) { > + pr_info("VP VTL1 is already enabled\n"); [Severity: High] If VTL1 is already enabled, does calling hv_vsm_load_secure_kernel() earlier in this function overwrite the memory of the currently running VTL1 secure kernel? Since hv_vsm_load_secure_kernel() is called unconditionally before checking if VP VTL1 is active, could unconditionally loading the secure kernel ELF image cause a regression by triggering a fatal hypervisor intercept/fault in VTL0, or silently corrupting the active VTL1 (such as during a kexec reboot)? -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=9
