Skip to contentSkip to conversation

common: buffer access out-of-bounds

PATCH Superseded Abdelrahman Youssef 2 participants 2 messages Oct 18, 2024

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 common: buffer access out-of-bounds

in file_detect_type() to detect file of type socfpga_xload you need at least 68 bytes bytes, so we need to check if we have enough bufsize. So I moved it after checking if bufsize >= 256.

---
This patch is a replacement of the last one because there were some issues with it
---
To: Sascha Hauer <[email protected]>
To: open list:BAREBOX <[email protected]>

---
 common/filetype.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/filetype.c +3 -3
index 3690d4ae07..67ae4916d1 100644
@@ -374,9 +374,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (le32_to_cpu(buf[5]) == 0x504d5453)
 		return filetype_mxs_bootstream;
 
-	if (buf[16] == 0x31305341)
-		return filetype_socfpga_xload;
-
 	if (is_barebox_arm_head(_buf))
 		return filetype_arm_barebox;
 	if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01)
@@ -388,6 +385,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 256)
 		return filetype_unknown;
 
+	if (buf[16] == 0x31305341)
+		return filetype_socfpga_xload;
+
 	if (strncmp(buf8, "STM\x32", 4) == 0) {
 		if (buf8[74] == 0x01) {
 			switch(le32_to_cpu(buf[63])) {

---
base-commit: 9d47ff66c3892c5a6ddd4704993365a797fbeb68
change-id: 20241018-overflow-dc42def7e4f6

Best regards,

Signature · 1 line
Abdelrahman Youssef <[email protected]>
Reviewed-by on v4 1/1
#1 lore raw
Quoted 7 lines · On 18.10.24 18:24, Abdelrahman Youssef via B4 Relay wrote:

From: Abdelrahman Youssef <[email protected]>

in file_detect_type() to detect file of type socfpga_xload you need at least 68 bytes bytes, so we need to check if we have enough bufsize. So I moved it after checking if bufsize >= 256.

Quoted 2 lines

---
This patch is a replacement of the last one because there were some issues with it

As mentioned in the v3 feedback, it's customary to write a changelog here.

Cheers,
Ahmad

Quoted 38 lines

---
To: Sascha Hauer <[email protected]>
To: open list:BAREBOX <[email protected]>

---
 common/filetype.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/filetype.c +3 -4
index 3690d4ae07..67ae4916d1 100644
@@ -374,9 +374,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (le32_to_cpu(buf[5]) == 0x504d5453)
 		return filetype_mxs_bootstream;
 
-	if (buf[16] == 0x31305341)
-		return filetype_socfpga_xload;
-
 	if (is_barebox_arm_head(_buf))
 		return filetype_arm_barebox;
 	if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01)
@@ -388,6 +385,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 256)
 		return filetype_unknown;
 
+	if (buf[16] == 0x31305341)
+		return filetype_socfpga_xload;
+
 	if (strncmp(buf8, "STM\x32", 4) == 0) {
 		if (buf8[74] == 0x01) {
 			switch(le32_to_cpu(buf[63])) {
 
---

base-commit: 9d47ff66c3892c5a6ddd4704993365a797fbeb68
change-id: 20241018-overflow-dc42def7e4f6

Best regards,

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |