#include <platform_def.h>
#include <smcc_helpers.h>
#include <string.h>
+#include <utils.h>
#include "bl1_private.h"
/*
return -EPERM;
}
- if ((!image_src) || (!block_size)) {
+ if ((!image_src) || (!block_size) ||
+ check_uptr_overflow(image_src, block_size - 1)) {
WARN("BL1-FWU: Copy not allowed due to invalid image source"
" or block size\n");
return -ENOMEM;
return -ENOMEM;
}
#else
- /* Find out how much free trusted ram remains after BL1 load */
+ /*
+ * Check the image will fit into the free trusted RAM after BL1
+ * load.
+ */
const meminfo_t *mem_layout = bl1_plat_sec_mem_layout();
- if ((image_desc->image_info.image_base < mem_layout->free_base) ||
- (image_desc->image_info.image_base + image_size >
- mem_layout->free_base + mem_layout->free_size)) {
+ if (!is_mem_free(mem_layout->free_base, mem_layout->free_size,
+ image_desc->image_info.image_base,
+ image_size)) {
WARN("BL1-FWU: Copy not allowed due to insufficient"
" resources.\n");
return -ENOMEM;
base_addr = image_desc->image_info.image_base;
total_size = image_desc->image_info.image_size;
} else {
- if ((!image_src) || (!image_size)) {
+ if ((!image_src) || (!image_size) ||
+ check_uptr_overflow(image_src, image_size - 1)) {
WARN("BL1-FWU: Auth not allowed due to invalid"
" image source/size\n");
return -ENOMEM;
#include <plat_arm.h>
#include <platform_def.h>
#include <tbbr_img_desc.h>
-
+#include <utils.h>
/* Struct to keep track of usable memory */
typedef struct bl1_mem_info {
assert(mem_base);
assert(mem_size);
+ /*
+ * The caller of this function is responsible for checking upfront that
+ * the end address doesn't overflow. We double-check this in debug
+ * builds.
+ */
+ assert(!check_uptr_overflow(mem_base, mem_size - 1));
/*
* Check the given image source and size.