Skip to contentSkip to conversation

spl: fit: Skip attempting to load 0 length image

PATCH In review Nishanth Menon 3 participants 3 messages Oct 19, 2021 – Dec 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: fit: Skip attempting to load 0 length image

When, for various reasons, a bad FIT image is used where a loadable image is marked as 0 length, attempt is made for a 0 length allocation and read of 0 byte read operation.

Instead provide warning in log and skip attempting to do such a load.

---
 common/spl/spl_fit.c | 7 +++++++
 1 file changed, 7 insertions(+)
common/spl/spl_fit.c +7 -0
index f41abca0ccb5..e9540dc2167a 100644
@@ -286,6 +286,13 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 		if (fit_image_get_data_size(fit, node, &len))
 			return -ENOENT;
 
+		/* Dont bother to copy 0 byte data, but warn, though */
+		if (!len) {
+			log_warning("%s: Skip load '%s': image size is 0!\n",
+				    __func__, fit_get_name(fit, node, NULL));
+			return 0;
+		}
+
 		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
 		length = len;
 
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Nishanth Menon

When, for various reasons, a bad FIT image is used where a loadable image is marked as 0 length, attempt is made for a 0 length allocation and read of 0 byte read operation.

Instead provide warning in log and skip attempting to do such a load.

---

Thanks,
Aswath

Quoted 22 lines
 common/spl/spl_fit.c | 7 +++++++
 1 file changed, 7 insertions(+)
common/spl/spl_fit.c +7 -0
index f41abca0ccb5..e9540dc2167a 100644
@@ -286,6 +286,13 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 		if (fit_image_get_data_size(fit, node, &len))
 			return -ENOENT;
 
+		/* Dont bother to copy 0 byte data, but warn, though */
+		if (!len) {
+			log_warning("%s: Skip load '%s': image size is 0!\n",
+				    __func__, fit_get_name(fit, node, NULL));
+			return 0;
+		}
+
 		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
 		length = len;