mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-28 23:23:30 +08:00
remoteproc: elf_loader: Always check the validity of the image before loading
rproc_elf32_load_image() rely on user to send a valid address for elf loading. Instead do a sanity check on the address passed by user. This will help all rproc elf users to not call sanity_check explicitly before calling elf_loading. Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> Reviewed-by: Fabien Dessenne <fabien.dessenne@st.com>
This commit is contained in:
parent
c08eb93626
commit
14d963d1b5
@ -64,13 +64,18 @@ int rproc_elf32_sanity_check(ulong addr, ulong size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A very simple elf loader, assumes the image is valid */
|
||||
int rproc_elf32_load_image(struct udevice *dev, unsigned long addr)
|
||||
int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
|
||||
{
|
||||
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
|
||||
Elf32_Phdr *phdr; /* Program header structure pointer */
|
||||
const struct dm_rproc_ops *ops;
|
||||
unsigned int i;
|
||||
unsigned int i, ret;
|
||||
|
||||
ret = rproc_elf32_sanity_check(addr, size);
|
||||
if (ret) {
|
||||
dev_err(dev, "Invalid ELF32 Image %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ehdr = (Elf32_Ehdr *)addr;
|
||||
phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
|
||||
|
@ -155,14 +155,7 @@ static int stm32_copro_load(struct udevice *dev, ulong addr, ulong size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Support only ELF32 image */
|
||||
ret = rproc_elf32_sanity_check(addr, size);
|
||||
if (ret) {
|
||||
dev_err(dev, "Invalid ELF32 image (%d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return rproc_elf32_load_image(dev, addr);
|
||||
return rproc_elf32_load_image(dev, addr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,9 +218,10 @@ int rproc_elf32_sanity_check(ulong addr, ulong size);
|
||||
* rproc_elf32_load_image() - load an ELF32 image
|
||||
* @dev: device loading the ELF32 image
|
||||
* @addr: valid ELF32 image address
|
||||
* @size: size of the image
|
||||
* @return 0 if the image is successfully loaded, else appropriate error value.
|
||||
*/
|
||||
int rproc_elf32_load_image(struct udevice *dev, unsigned long addr);
|
||||
int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
|
||||
#else
|
||||
static inline int rproc_init(void) { return -ENOSYS; }
|
||||
static inline int rproc_dev_init(int id) { return -ENOSYS; }
|
||||
@ -234,7 +235,8 @@ static inline int rproc_is_running(int id) { return -ENOSYS; }
|
||||
static inline int rproc_elf32_sanity_check(ulong addr,
|
||||
ulong size) { return -ENOSYS; }
|
||||
static inline int rproc_elf32_load_image(struct udevice *dev,
|
||||
unsigned long addr) { return -ENOSYS; }
|
||||
unsigned long addr, ulong size)
|
||||
{ return -ENOSYS; }
|
||||
#endif
|
||||
|
||||
#endif /* _RPROC_H_ */
|
||||
|
@ -171,11 +171,8 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts)
|
||||
ut_assertnonnull(loaded_firmware);
|
||||
memset(loaded_firmware, 0, loaded_firmware_size);
|
||||
|
||||
/* Verify valid ELF format */
|
||||
ut_assertok(rproc_elf32_sanity_check((ulong)valid_elf32, size));
|
||||
|
||||
/* Load firmware in loaded_firmware, and verify it */
|
||||
ut_assertok(rproc_elf32_load_image(dev, (unsigned long)valid_elf32));
|
||||
ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size));
|
||||
ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size));
|
||||
unmap_physmem(loaded_firmware, MAP_NOCACHE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user