@@ -963,7 +963,7 @@ int fit_image_get_emb_data(const void *fit, int noffset, const void **data,
* 0, on success
* -ENOENT if the property could not be found
*/
-int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset)
+int fit_image_get_data_offset(const void *fit, int noffset, u32 *data_offset)
{
const fdt32_t *val;
@@ -988,7 +988,7 @@ int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset)
* -ENOENT if the property could not be found
*/
int fit_image_get_data_position(const void *fit, int noffset,
- int *data_position)
+ u32 *data_position)
{
const fdt32_t *val;
@@ -1012,7 +1012,7 @@ int fit_image_get_data_position(const void *fit, int noffset,
* 0, on success
* -ENOENT if the property could not be found
*/
-int fit_image_get_data_size(const void *fit, int noffset, int *data_size)
+int fit_image_get_data_size(const void *fit, int noffset, u32 *data_size)
{
const fdt32_t *val;
@@ -1070,18 +1070,13 @@ int fit_image_get_data(const void *fit, int noffset, const void **data,
size_t *size)
{
bool external_data = false;
- int offset;
- int len;
int ret;
size_t fdt_total_size_aligned;
+ u32 offset;
+ u32 len;
uintptr_t max_offset;
if (!fit_image_get_data_position(fit, noffset, &offset)) {
- if (offset < 0) {
- printf("Invalid external data position: %d\n", offset);
- return -EINVAL;
- }
-
external_data = true;
} else if (!fit_image_get_data_offset(fit, noffset, &offset)) {
/*
@@ -1090,9 +1085,9 @@ int fit_image_get_data(const void *fit, int noffset, const void **data,
* for the data-offset properties in each image.
*/
fdt_total_size_aligned = ((fdt_totalsize(fit) + 3) & ~3);
- /* The resulting offset cannot exceed INT_MAX */
- if (offset < 0 || fdt_total_size_aligned > INT_MAX - offset) {
- printf("Invalid external data offset: %d\n", offset);
+ /* The resulting offset cannot exceed UINT32_MAX */
+ if (fdt_total_size_aligned > UINT32_MAX - offset) {
+ printf("Invalid external data offset: %u\n", offset);
return -EINVAL;
}
offset += fdt_total_size_aligned;
@@ -1106,16 +1101,12 @@ int fit_image_get_data(const void *fit, int noffset, const void **data,
max_offset = UINTPTR_MAX - (uintptr_t)fit;
/* Check that external data offset is within the addressable range */
if (offset > max_offset) {
- printf("Invalid external data offset: %d\n", offset);
+ printf("Invalid external data offset: %u\n", offset);
return -EINVAL;
}
ret = fit_image_get_data_size(fit, noffset, &len);
if (!ret) {
- if (len < 0) {
- printf("Invalid external data size: %d\n", len);
- return -EINVAL;
- }
/*
* For non-signed FIT images, we can only check that
* (offset + len) doesn't exceed the addressable range.
@@ -1135,7 +1126,7 @@ int fit_image_get_data(const void *fit, int noffset, const void **data,
len > CONFIG_VAL(FIT_SIGNATURE_MAX_SIZE) - offset
#endif
) {
- printf("FIT external data is out of bounds (offset=%d, size=%d)\n",
+ printf("FIT external data is out of bounds (offset=%u, size=%u)\n",
offset, len);
return -EINVAL;
}
@@ -216,9 +216,9 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
const struct spl_fit_info *ctx, int node,
struct spl_image_info *image_info, ulong max_size)
{
- int offset;
+ u32 offset;
+ u32 len;
size_t length;
- int len;
ulong size;
ulong load_addr;
void *load_ptr;
@@ -351,7 +351,7 @@ static int splash_load_fit(struct splash_location *location, ulong bmp_load_addr
const void *internal_splash_data;
size_t internal_splash_size;
int external_splash_addr;
- int external_splash_size;
+ u32 external_splash_size;
bool is_splash_external = false;
struct legacy_img_hdr *img_header;
const u32 *fit_header;
@@ -547,7 +547,8 @@ static int first_loading_rbf_to_buffer(struct udevice *dev,
u32 *loadable = buffer_p;
size_t buffer_size = *buffer_bsize;
size_t fit_size;
- int ret, i, count, confs_noffset, images_noffset, rbf_offset, rbf_size;
+ int ret, i, count, confs_noffset, images_noffset;
+ u32 rbf_offset, rbf_size;
const char *fpga_node_name = NULL;
const char *uname = NULL;
@@ -1263,10 +1263,10 @@ int fit_image_get_load(const void *fit, int noffset, ulong *load);
int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
int fit_image_get_emb_data(const void *fit, int noffset, const void **data,
size_t *size);
-int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset);
+int fit_image_get_data_offset(const void *fit, int noffset, u32 *data_offset);
int fit_image_get_data_position(const void *fit, int noffset,
- int *data_position);
-int fit_image_get_data_size(const void *fit, int noffset, int *data_size);
+ u32 *data_position);
+int fit_image_get_data_size(const void *fit, int noffset, u32 *data_size);
int fit_image_get_data_size_unciphered(const void *fit, int noffset,
size_t *data_size);
int fit_image_get_data(const void *fit, int noffset, const void **data,
@@ -700,12 +700,12 @@ def test_vboot_ext_data_bounds(ubman):
fd.write(500 * b'\0')
testcases = [
- ('negative data-position',
- {'data-position': 0xffffffff}, 'Invalid external data position'),
- ('negative data-offset',
+ ('invalid data-position',
+ {'data-position': 0xffffffff}, 'FIT external data is out of bounds'),
+ ('invalid data-offset',
{'data-offset': 0xffffffff}, 'Invalid external data offset'),
- ('negative data-size',
- {'data-size': 0xffffffff}, 'Invalid external data size'),
+ ('invalid data-size',
+ {'data-size': 0xffffffff}, 'FIT external data is out of bounds'),
('off-bounds data-position',
{'data-position': 0x7fffffff}, 'FIT external data is out of bounds'),
('off-bounds data-offset',