mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>,
	barebox@lists.infradead.org
Subject: Re: [PATCH v2 13/16] arm: uncompress: verify sha256 if enabled
Date: Mon, 05 Aug 2019 12:42:25 +0200	[thread overview]
Message-ID: <1565001745.2323.5.camel@pengutronix.de> (raw)
In-Reply-To: <779cf1615ca931b2687c6fa8a4b5f4e481f8af82.1564997015.git-series.r.czerwinski@pengutronix.de>

Am Montag, den 05.08.2019, 11:23 +0200 schrieb Rouven Czerwinski:
> Add piggydata verification before the ARM uncompress function.
> This calculates the sha256sum of the compressed barebox binary and only
> continues if the builtin sha256sum matches the calculated sha256sum.
> 
> > Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  arch/arm/cpu/uncompress.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
> index c7851c5..4c69b4c 100644
> --- a/arch/arm/cpu/uncompress.c
> +++ b/arch/arm/cpu/uncompress.c
> @@ -42,14 +42,18 @@ unsigned long free_mem_end_ptr;
>  extern unsigned char input_data[];
>  extern unsigned char input_data_end[];
>  
> +extern unsigned char sha_sum[];
> +extern unsigned char sha_sum_end[];
> +
>  void __noreturn barebox_multi_pbl_start(unsigned long membase,
> >  		unsigned long memsize, void *boarddata)
>  {
> > -	uint32_t pg_len, uncompressed_len;
> > +	uint32_t pg_len, uncompressed_len, pbl_hash_len;
> >  	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
> >  	unsigned long endmem = membase + memsize;
> >  	unsigned long barebox_base;
> >  	void *pg_start, *pg_end;
> > +	void *pbl_hash_start, *pbl_hash_end;
> >  	unsigned long pc = get_pc();
>  
> >  	pg_start = input_data + global_variable_offset();
> @@ -92,6 +96,17 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
> >  	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
> >  			pg_start, pg_len, barebox_base, uncompressed_len);
>  
> > +	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
> > +		pbl_hash_start = sha_sum + global_variable_offset();
> +		pbl_hash_end = sha_sum_end + global_variable_offset();

This code is executed after relocation, so there is no point in adding
the global variable offset. It doesn't harm, as the offset is always 0
at that point, but better don't start cargo-culting here.

Regards,
Lucas

> +		pbl_hash_len = pbl_hash_end - pbl_hash_start;
> > +		if (pbl_barebox_verify(pg_start, pg_len, pbl_hash_start,
> > +				       pbl_hash_len) != 0) {
> > +			putc_ll('!');
> > +			panic("hash mismatch, refusing to decompress");
> > +		}
> > +	}
> +
> >  	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
>  
> >  	sync_caches_for_execution();

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2019-08-05 10:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-05  9:23 [PATCH v2 00/16] HAB for i.MX8MQ Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 01/16] i.MX: HABv4: ignore return for i.MX28/6 initcalls Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 02/16] i.MX: HABv4: implement interface for i.MX8MQ Rouven Czerwinski
2019-08-05 12:12   ` Lucas Stach
2019-08-05  9:23 ` [PATCH v2 03/16] mach-imx: enable HAB on i.MX8MQ Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 04/16] arm: lib: add CSF section between PBL and piggy Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 05/16] esdhc-pbl: extract header parsing from image start Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 06/16] esdhc-pbl: add piggy load function Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 07/16] sections: fix macro for barebox_pbl_size Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 08/16] scripts: imx: support signing for i.MX8MQ Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 09/16] images: always build sha256sum into pbl Rouven Czerwinski
2019-08-05 12:20   ` Lucas Stach
2019-08-05 12:52     ` Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 10/16] pbl: add sha256 and piggy verification to PBL Rouven Czerwinski
2019-08-05 11:00   ` Lucas Stach
2019-08-05 12:57     ` Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 11/16] stdio: puts and putchar static inline wrappers Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 12/16] pbl: support panic with log output Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 13/16] arm: uncompress: verify sha256 if enabled Rouven Czerwinski
2019-08-05 10:42   ` Lucas Stach [this message]
2019-08-05  9:23 ` [PATCH v2 14/16] mach-imx: add gencsf header for i.MX8MQ Rouven Czerwinski
2019-08-05  9:23 ` [PATCH v2 15/16] mach-imx: hab: select piggy verification for i.MX8 Rouven Czerwinski
2019-08-05 10:39   ` Lucas Stach
2019-08-05  9:23 ` [PATCH v2 16/16] boards: nxp-mx8-evk: rework to different boot flow Rouven Czerwinski
2019-08-05 10:37   ` Lucas Stach
2019-08-05 12:59     ` Rouven Czerwinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1565001745.2323.5.camel@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=r.czerwinski@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox