Skip to contentSkip to conversation

image-sig: Ensure that hashed-nodes is null-terminated

PATCH New Tom Rini 2 participants 6 messages Nov 7, 2018 – Nov 17, 2018

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/2 image-sig: Ensure that hashed-nodes is null-terminated

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image leads to memory corruption in the stack when using the verified boot feature. The function fit_config_check_sig has a logic error that makes it possible to write past the end of the stack allocated array node_inc. This could potentially be used to bypass the signature check when using verified boot.

This change ensures that the number of strings is correct when counted.

---
 common/image-sig.c | 5 +++++
 1 file changed, 5 insertions(+)
common/image-sig.c +5 -0
index 5a269d3289bf..5d860e126637 100644
@@ -334,6 +334,11 @@ int fit_config_check_sig(const void *fit, int noffset, int required_keynode,
 		return -1;
 	}
 
+	if (prop && prop_len > 0 && prop[prop_len - 1] != '\0') {
+		*err_msgp = "hashed-nodes property must be null-terminated";
+		return -1;
+	}
+
 	/* Add a sanity check here since we are using the stack */
 	if (count > IMAGE_MAX_HASHED_NODES) {
 		*err_msgp = "Number of hashed nodes exceeds maximum";
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 image-sig: Ensure that hashed-nodes is null-terminated

Quoted 8 lines · Tom Rini

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image leads to memory corruption in the stack when using the verified boot feature. The function fit_config_check_sig has a logic error that makes it possible to write past the end of the stack allocated array node_inc. This could potentially be used to bypass the signature check when using verified boot.

Quoted 4 lines

This change ensures that the number of strings is correct when counted.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181117/b460938b/attachment.sig>
#2 lore raw

PATCH 1/2 image-sig: Ensure that hashed-nodes is null-terminated

In reply to Tom Rini
Quoted 8 lines · Tom Rini

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image leads to memory corruption in the stack when using the verified boot feature. The function fit_config_check_sig has a logic error that makes it possible to write past the end of the stack allocated array node_inc. This could potentially be used to bypass the signature check when using verified boot.

Quoted 6 lines

This change ensures that the number of strings is correct when counted.

---
 common/image-sig.c | 5 +++++
 1 file changed, 5 insertions(+)
author
#3 lore raw

PATCH 2/2 fdt_region: Ensure that depth never goes below -1

In reply to Tom Rini

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image makes it possible to overflow the stack with controlled values when using the verified boot feature. Depending on the memory layout, this could be used to overwrite configuration variables on the heap and setting them to 0, e.g. disable signature verification, thus bypassing it.

This change fixes a bug in fdt_find_regions where the fdt structure is parsed. A lower value than -1 of depth can lead to a buffer underflow write on the stack.

---
 lib/libfdt/fdt_region.c | 3 +++
 1 file changed, 3 insertions(+)
lib/libfdt/fdt_region.c +3 -0
index d3b9a60e994f..7e9fa9272e80 100644
@@ -96,6 +96,9 @@ int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
 			break;
 
 		case FDT_END_NODE:
+			/* Depth must never go below -1 */
+			if (depth < 0)
+				return -FDT_ERR_BADSTRUCTURE;
 			include = want;
 			want = stack[depth--];
 			while (end > path && *--end != '/')
Signature · 1 line
2.7.4
#4 lore raw

PATCH 2/2 fdt_region: Ensure that depth never goes below -1

Quoted 8 lines · Tom Rini

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image makes it possible to overflow the stack with controlled values when using the verified boot feature. Depending on the memory layout, this could be used to overwrite configuration variables on the heap and setting them to 0, e.g. disable signature verification, thus bypassing it.

Quoted 9 lines

This change fixes a bug in fdt_find_regions where the fdt structure is parsed. A lower value than -1 of depth can lead to a buffer underflow write on the stack.

---
 lib/libfdt/fdt_region.c | 3 +++
 1 file changed, 3 insertions(+)
author
#5 lore raw

PATCH 2/2 fdt_region: Ensure that depth never goes below -1

In reply to Tom Rini
Quoted 8 lines · Tom Rini

From: Konrad Beckmann <[email protected]>

A specially crafted FIT image makes it possible to overflow the stack with controlled values when using the verified boot feature. Depending on the memory layout, this could be used to overwrite configuration variables on the heap and setting them to 0, e.g. disable signature verification, thus bypassing it.

Quoted 6 lines

This change fixes a bug in fdt_find_regions where the fdt structure is parsed. A lower value than -1 of depth can lead to a buffer underflow write on the stack.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181117/b6a29d72/attachment.sig>