Skip to contentSkip to conversation

Prevent a buffer overflow in mkimage when signing with SHA256

PATCH Superseded Michael van der Westhuizen 3 participants 7 messages May 26, 2014 – Jun 6, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

---
Changes in v2:
* Use the HASH_MAX_DIGEST_SIZE constant from hash.h for the FIT_MAX_HASH_LEN.
* Hide use of struct lmb behind USE_HOSTCC being undefined.

include/image.h | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
include/image.h +0 -0
index 1886168..cbbdf26 100644
@@ -45,6 +45,8 @@ struct lmb;

#endif /* USE_HOSTCC */

#if defined(CONFIG_FIT)
+#include <command.h>
+#include <hash.h>
#include <libfdt.h>
#include <fdt_support.h>

# ifdef CONFIG_SPL_BUILD
@@ -328,7 +330,7 @@ typedef struct bootm_headers {
#define BOOTM_STATE_OS_GO (0x00000400)
 int state;

-#ifdef CONFIG_LMB
+#if defined(CONFIG_LMB) && !defined(USE_HOSTCC)
struct lmb lmb; /* for memory mgmt */
#endif
} bootm_headers_t;
@@ -703,7 +705,7 @@ int bootz_setup(ulong image, ulong *start, ulong *end); #define FIT_FDT_PROP "fdt"
#define FIT_DEFAULT_PROP "default"

-#define FIT_MAX_HASH_LEN 20 /* max(crc32_len(4), sha1_len(20)) */ +#define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE

/* cmdline argument format parsing */
int fit_parse_conf(const char *spec, ulong addr_curr,

Signature · 1 line
2.0.0.rc4
#1 lore raw

PATCH v2 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

Hi Michael,

Quoted 11 lines · Michael van der Westhuizen

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

---
Changes in v2:
* Use the HASH_MAX_DIGEST_SIZE constant from hash.h for the FIT_MAX_HASH_LEN.
* Hide use of struct lmb behind USE_HOSTCC being undefined.

This seems to have whitespace problems, or it could be your mailer. There should be tabs in there somewhere. Did you use patman to check/send?

Regards,
Simon

#2 lore raw

PATCH v2 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

Hi Simon,

That's very odd. I'll regenerate the patch and resend.

I'm using git send-email, so things should not be getting mangled.

Michael

Quoted 22 lines · Simon Glass

Hi Michael,

Quoted 11 lines · Michael van der Westhuizen

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

---
Changes in v2:
* Use the HASH_MAX_DIGEST_SIZE constant from hash.h for the FIT_MAX_HASH_LEN.
* Hide use of struct lmb behind USE_HOSTCC being undefined.

This seems to have whitespace problems, or it could be your mailer. There should be tabs in there somewhere. Did you use patman to check/send?

Regards,
Simon

#3 lore raw

PATCH v3 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

In reply to Michael van der Westhuizen

From: Michael van der Westhuizen <[email protected]>

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

---
Changes in v3:
* Regenerate to correct mailer damage.
Changes in v2:
* Use the HASH_MAX_DIGEST_SIZE constant from hash.h for the FIT_MAX_HASH_LEN.
* Hide use of struct lmb behind USE_HOSTCC being undefined.

 include/image.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/image.h +4 -2
index 1886168..cbbdf26 100644
@@ -45,6 +45,8 @@ struct lmb;
 #endif /* USE_HOSTCC */
 
 #if defined(CONFIG_FIT)
+#include <command.h>
+#include <hash.h>
 #include <libfdt.h>
 #include <fdt_support.h>
 # ifdef CONFIG_SPL_BUILD
@@ -328,7 +330,7 @@ typedef struct bootm_headers {
 #define	BOOTM_STATE_OS_GO	(0x00000400)
 	int		state;
 
-#ifdef CONFIG_LMB
+#if defined(CONFIG_LMB) && !defined(USE_HOSTCC)
 	struct lmb	lmb;		/* for memory mgmt */
 #endif
 } bootm_headers_t;
@@ -703,7 +705,7 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_FDT_PROP		"fdt"
 #define FIT_DEFAULT_PROP	"default"
 
-#define FIT_MAX_HASH_LEN	20	/* max(crc32_len(4), sha1_len(20)) */
+#define FIT_MAX_HASH_LEN	HASH_MAX_DIGEST_SIZE
 
 /* cmdline argument format parsing */
 int fit_parse_conf(const char *spec, ulong addr_curr,
Signature · 1 line
1.9.1
#4 lore raw

PATCH v3 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

Quoted 8 lines · On 30 May 2014 12:59, <[email protected]> wrote:

From: Michael van der Westhuizen <[email protected]>

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

Regards,
Simon

#5 lore raw

PATCH v3 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

In reply to michael at smart-africa.com
Quoted 9 lines · Michael van der Westhuizen

From: Michael van der Westhuizen <[email protected]>

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

Applied to u-boot/master (with a rework to hash.h to avoid breaking various platforms when host tools start adding command.h) , thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140605/55ca4c56/attachment.pgp>
#6 lore raw

PATCH v3 1/1 Prevent a buffer overflow in mkimage when signing with SHA256

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 7 lines · Michael van der Westhuizen

From: Michael van der Westhuizen <[email protected]>

Due to the FIT_MAX_HASH_LEN constant not having been updated to support SHA256 signatures one will always see a buffer overflow in fit_image_process_hash when signing images that use this larger hash. This is exposed by vboot_test.sh.

Quoted 5 lines
Quoted 2 lines

Applied to u-boot/master (with a rework to hash.h to avoid breaking various platforms when host tools start adding command.h) , thanks!

Thanks - I was about to mention that!

Regards,
Simon