Skip to contentSkip to conversation

kho: Fix NULL pointer dereference in kho_update_memory_map()

PATCH New Zhan Xusheng 1 participant 1 message Mar 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kho: Fix NULL pointer dereference in kho_update_memory_map()

The function kho_update_memory_map currently does not check if the pointer returned by fdt_getprop_w is NULL. If the pointer is NULL, subsequent operations such as dereferencing the pointer or using it in unaligned access functions could cause undefined behavior or crashes. Prevent that.

---
 kernel/liveupdate/kexec_handover.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/liveupdate/kexec_handover.c +2 -0
index cc68a3692905..f6ad87930003 100644
@@ -397,6 +397,8 @@ static void kho_update_memory_map(struct khoser_mem_chunk *first_chunk)
 	u64 phys;
 
 	ptr = fdt_getprop_w(kho_out.fdt, 0, KHO_FDT_MEMORY_MAP_PROP_NAME, NULL);
+	if (!ptr)
+		return;
 
 	/* Check and discard previous memory map */
 	phys = get_unaligned((u64 *)ptr);
Signature · 1 line
2.43.0