From 62b4701646a46f8edda4697f52cfdc48c820ce40 Mon Sep 17 00:00:00 2001 From: Nicola Vetrini Date: Wed, 9 Jul 2025 17:20:49 -0700 Subject: [PATCH] xen/arm: address violations of Rule 11.3 Use {get,put}_unaligned_t to ensure that reads and writes are safe to perform even on potentially misaligned pointers. Signed-off-by: Nicola Vetrini Signed-off-by: Victor Lira Acked-by: Bertrand Marquis --- xen/arch/arm/efi/efi-boot.h | 9 +++++---- xen/common/device-tree/bootfdt.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index faabe5a6a8..7dd2528a17 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -85,7 +86,7 @@ static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells) *addr_cells = 2; } else - *addr_cells = fdt32_to_cpu(*((uint32_t *)prop->data)); + *addr_cells = fdt32_to_cpu(get_unaligned_t(uint32_t, prop->data)); prop = fdt_get_property(fdt, node, "#size-cells", &len); if ( !prop ) @@ -96,7 +97,7 @@ static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells) *size_cells = 2; } else - *size_cells = fdt32_to_cpu(*((uint32_t *)prop->data)); + *size_cells = fdt32_to_cpu(get_unaligned_t(uint32_t, prop->data)); /* * Make sure ranges is empty if it exists, otherwise create empty ranges @@ -824,7 +825,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima return ERROR_MISSING_DT_PROPERTY; } - addr_cells = fdt32_to_cpu(*((uint32_t *)prop->data)); + addr_cells = fdt32_to_cpu(get_unaligned_t(uint32_t, prop->data)); prop = fdt_get_property(fdt_efi, domain_node, "#size-cells", &len); if ( !prop ) @@ -833,7 +834,7 @@ static int __init handle_dom0less_domain_node(const EFI_LOADED_IMAGE *loaded_ima return ERROR_MISSING_DT_PROPERTY; } - size_cells = fdt32_to_cpu(*((uint32_t *)prop->data)); + size_cells = fdt32_to_cpu(get_unaligned_t(uint32_t, prop->data)); /* Check for nodes compatible with multiboot,module inside this node */ for ( module_node = fdt_first_subnode(fdt_efi, domain_node); diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/bootfdt.c index 39334d6205..08d919aba6 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -211,7 +212,7 @@ u32 __init device_tree_get_u32(const void *fdt, int node, if ( !prop || prop->len < sizeof(u32) ) return dflt; - return fdt32_to_cpu(*(uint32_t*)prop->data); + return fdt32_to_cpu(get_unaligned_t(uint32_t, prop->data)); } /**