Skip to contentSkip to conversation

libfdt: fix fdt_check_full buffer overrun

PATCH Applied [email protected] 2 participants 2 messages Jul 9, 2020 – Jul 10, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfdt: fix fdt_check_full buffer overrun

From: Patrick Oppenlander <[email protected]>

fdt_check_header assumes that its argument points to a complete header and can read data beyond the FDT_V1_SIZE bytes which fdt_check_full can provide.

fdt_header_size can safely return a header size with FDT_V1_SIZE bytes available and will return a usable value even for a corrupted header.

---
 libfdt/fdt_check.c | 2 ++
 1 file changed, 2 insertions(+)
libfdt/fdt_check.c +2 -0
index 7f6a96c..9ddfdbf 100644
@@ -22,6 +22,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)
 
 	if (bufsize < FDT_V1_SIZE)
 		return -FDT_ERR_TRUNCATED;
+	if (bufsize < fdt_header_size(fdt))
+		return -FDT_ERR_TRUNCATED;
 	err = fdt_check_header(fdt);
 	if (err != 0)
 		return err;
Signature · 1 line
2.27.0
Applied
#2 lore raw
In reply to a message not in the archive
Quoted 10 lines · On Thu, Jul 09, 2020 at 02:14:51PM +1000…

From: Patrick Oppenlander <[email protected]>

fdt_check_header assumes that its argument points to a complete header and can read data beyond the FDT_V1_SIZE bytes which fdt_check_full can provide.

fdt_header_size can safely return a header size with FDT_V1_SIZE bytes available and will return a usable value even for a corrupted header.

Applied, thanks.

Quoted 17 lines
---
 libfdt/fdt_check.c | 2 ++
 1 file changed, 2 insertions(+)
libfdt/fdt_check.c +2 -0
index 7f6a96c..9ddfdbf 100644
@@ -22,6 +22,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)
 
 	if (bufsize < FDT_V1_SIZE)
 		return -FDT_ERR_TRUNCATED;
+	if (bufsize < fdt_header_size(fdt))
+		return -FDT_ERR_TRUNCATED;
 	err = fdt_check_header(fdt);
 	if (err != 0)
 		return err;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson