All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fit_image: Use calloc() to fix reproducibility issue
@ 2020-07-28  0:03 Fabio Estevam
  2020-07-28 19:07 ` Vagrant Cascadian
  2020-08-05 20:28 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Fabio Estevam @ 2020-07-28  0:03 UTC (permalink / raw)
  To: u-boot

Vagrant Cascadian reported that mx6cuboxi target no longer builds
reproducibility on Debian.

One example of builds mismatches:

00096680: 696e 6700 736f 756e 642d 6461 6900 6465  ing.sound-dai.de
-00096690: 7465 6374 2d67 7069 6f73 0000            tect-gpios..
+00096690: 7465 6374 2d67 7069 6f73 0061            tect-gpios.a

This problem happens because all the buffers in fit_image.c are
allocated via malloc(), which does not zero out the allocated buffer.

Using calloc() fixes this unpredictable behaviour as it guarantees
that the allocated buffer are zero initialized.

Reported-by: Vagrant Cascadian <vagrant@reproducible-builds.org>
Suggested-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
Changes since v1:
- Improve the commit log description by stating why calloc() helps.

 tools/fit_image.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/fit_image.c b/tools/fit_image.c
index a082d9386d..0c6185d892 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -388,7 +388,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 	size = fit_calc_size(params);
 	if (size < 0)
 		return -1;
-	buf = malloc(size);
+	buf = calloc(1, size);
 	if (!buf) {
 		fprintf(stderr, "%s: Out of memory (%d bytes)\n",
 			params->cmdname, size);
@@ -467,7 +467,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 	 * Allocate space to hold the image data we will extract,
 	 * extral space allocate for image alignment to prevent overflow.
 	 */
-	buf = malloc(fit_size + (align_size * image_number));
+	buf = calloc(1, fit_size + (align_size * image_number));
 	if (!buf) {
 		ret = -ENOMEM;
 		goto err_munmap;
@@ -572,7 +572,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 
 	/* Allocate space to hold the new FIT */
 	size = sbuf.st_size + 16384;
-	fdt = malloc(size);
+	fdt = calloc(1, size);
 	if (!fdt) {
 		fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
 			__func__, size);
@@ -673,7 +673,7 @@ static int copyfile(const char *src, const char *dst)
 		goto out;
 	}
 
-	buf = malloc(512);
+	buf = calloc(1, 512);
 	if (!buf) {
 		printf("Can't allocate buffer to copy file\n");
 		goto out;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] fit_image: Use calloc() to fix reproducibility issue
  2020-07-28  0:03 [PATCH v2] fit_image: Use calloc() to fix reproducibility issue Fabio Estevam
@ 2020-07-28 19:07 ` Vagrant Cascadian
  2020-08-05 20:28 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Vagrant Cascadian @ 2020-07-28 19:07 UTC (permalink / raw)
  To: u-boot

On 2020-07-27, Fabio Estevam wrote:
> Vagrant Cascadian reported that mx6cuboxi target no longer builds
> reproducibility on Debian.
>
> One example of builds mismatches:
>
> 00096680: 696e 6700 736f 756e 642d 6461 6900 6465  ing.sound-dai.de
> -00096690: 7465 6374 2d67 7069 6f73 0000            tect-gpios..
> +00096690: 7465 6374 2d67 7069 6f73 0061            tect-gpios.a
>
> This problem happens because all the buffers in fit_image.c are
> allocated via malloc(), which does not zero out the allocated buffer.
>
> Using calloc() fixes this unpredictable behaviour as it guarantees
> that the allocated buffer are zero initialized.
>
> Reported-by: Vagrant Cascadian <vagrant@reproducible-builds.org>
> Suggested-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Fabio Estevam <festevam@gmail.com>

Tested that it boots on the mx6cuboxi supported board hummingboard i2ex,
and that it fixes the reproducibility issues.

Thanks!

Tested-by: Vagrant Cascadian <vagrant@reproducible-builds.org>

live well,
  vagrant

> ---
> Changes since v1:
> - Improve the commit log description by stating why calloc() helps.
>
>  tools/fit_image.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/fit_image.c b/tools/fit_image.c
> index a082d9386d..0c6185d892 100644
> --- a/tools/fit_image.c
> +++ b/tools/fit_image.c
> @@ -388,7 +388,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
>  	size = fit_calc_size(params);
>  	if (size < 0)
>  		return -1;
> -	buf = malloc(size);
> +	buf = calloc(1, size);
>  	if (!buf) {
>  		fprintf(stderr, "%s: Out of memory (%d bytes)\n",
>  			params->cmdname, size);
> @@ -467,7 +467,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
>  	 * Allocate space to hold the image data we will extract,
>  	 * extral space allocate for image alignment to prevent overflow.
>  	 */
> -	buf = malloc(fit_size + (align_size * image_number));
> +	buf = calloc(1, fit_size + (align_size * image_number));
>  	if (!buf) {
>  		ret = -ENOMEM;
>  		goto err_munmap;
> @@ -572,7 +572,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
>  
>  	/* Allocate space to hold the new FIT */
>  	size = sbuf.st_size + 16384;
> -	fdt = malloc(size);
> +	fdt = calloc(1, size);
>  	if (!fdt) {
>  		fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
>  			__func__, size);
> @@ -673,7 +673,7 @@ static int copyfile(const char *src, const char *dst)
>  		goto out;
>  	}
>  
> -	buf = malloc(512);
> +	buf = calloc(1, 512);
>  	if (!buf) {
>  		printf("Can't allocate buffer to copy file\n");
>  		goto out;
> -- 
> 2.17.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200728/6c5a507b/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] fit_image: Use calloc() to fix reproducibility issue
  2020-07-28  0:03 [PATCH v2] fit_image: Use calloc() to fix reproducibility issue Fabio Estevam
  2020-07-28 19:07 ` Vagrant Cascadian
@ 2020-08-05 20:28 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2020-08-05 20:28 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 27, 2020 at 09:03:13PM -0300, Fabio Estevam wrote:

> Vagrant Cascadian reported that mx6cuboxi target no longer builds
> reproducibility on Debian.
> 
> One example of builds mismatches:
> 
> 00096680: 696e 6700 736f 756e 642d 6461 6900 6465  ing.sound-dai.de
> -00096690: 7465 6374 2d67 7069 6f73 0000            tect-gpios..
> +00096690: 7465 6374 2d67 7069 6f73 0061            tect-gpios.a
> 
> This problem happens because all the buffers in fit_image.c are
> allocated via malloc(), which does not zero out the allocated buffer.
> 
> Using calloc() fixes this unpredictable behaviour as it guarantees
> that the allocated buffer are zero initialized.
> 
> Reported-by: Vagrant Cascadian <vagrant@reproducible-builds.org>
> Suggested-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> Tested-by: Vagrant Cascadian <vagrant@reproducible-builds.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/84aaaa32/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-05 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28  0:03 [PATCH v2] fit_image: Use calloc() to fix reproducibility issue Fabio Estevam
2020-07-28 19:07 ` Vagrant Cascadian
2020-08-05 20:28 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.