Skip to contentSkip to conversation

arm64: change to use memmove in efi-stub

PATCH In review yalin wang 2 participants 3 messages Oct 16, 2015 – Oct 19, 2015 arm64

lore
Share & tools
lore

yalin wang

author
#0 lore raw

PATCH 1/1 arm64: change to use memmove in efi-stub

Change to use memmove(), in case the dest address overlap with the source address.

---
 arch/arm64/kernel/efi-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/efi-stub.c +1 -1
index 816120e..b6dc44b 100644
@@ -59,7 +59,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
 			}
 			*image_addr = *reserve_addr + TEXT_OFFSET;
 		}
-		memcpy((void *)*image_addr, old_image_addr, kernel_size);
+		memmove((void *)*image_addr, old_image_addr, kernel_size);
 		*reserve_size = kernel_memsize;
 	}
 
Signature · 1 line
1.9.1
reviewer
#1 lore raw

Hi,

Quoted 2 lines · yalin wang

Change to use memmove(), in case the dest address overlap with the source address.

This cannot happen, and memove would not be sufficient if it did.

The destination is a region returned by EFI_BOOT_SERVICES.AllocatePages, which can only allocate pages which were free to begin with. Therefore the new region cannot overlap with the stub (whose pages are not free).

Were the new region to overlap with the stub, the memmove could corrupt the code/data in use by the stub, and things would explode shortly thereafter.

Thanks,
Mark.

Quoted 22 lines
---
 arch/arm64/kernel/efi-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/efi-stub.c +1 -1
index 816120e..b6dc44b 100644
@@ -59,7 +59,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
 			}
 			*image_addr = *reserve_addr + TEXT_OFFSET;
 		}
-		memcpy((void *)*image_addr, old_image_addr, kernel_size);
+		memmove((void *)*image_addr, old_image_addr, kernel_size);
 		*reserve_size = kernel_memsize;
 	}
 
Signature · 1 line
1.9.1
author
#2 lore raw

Got it ,

Thanks for your explanation .

Quoted 43 lines · Mark Rutland

Hi,

Quoted 2 lines · yalin wang

Change to use memmove(), in case the dest address overlap with the source address.

This cannot happen, and memove would not be sufficient if it did.

The destination is a region returned by EFI_BOOT_SERVICES.AllocatePages, which can only allocate pages which were free to begin with. Therefore the new region cannot overlap with the stub (whose pages are not free).

Were the new region to overlap with the stub, the memmove could corrupt the code/data in use by the stub, and things would explode shortly thereafter.

Thanks,
Mark.

Quoted 22 lines

---
arch/arm64/kernel/efi-stub.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/efi-stub.c +1 -1
index 816120e..b6dc44b 100644
@@ -59,7 +59,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
 			}
 			*image_addr = *reserve_addr + TEXT_OFFSET;
 		}
-		memcpy((void *)*image_addr, old_image_addr, kernel_size);
+		memmove((void *)*image_addr, old_image_addr, kernel_size);
 		*reserve_size = kernel_memsize;
 	}
 
Signature · 1 line
1.9.1