mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 10/13] arm: uncompress: verify sha256 if enabled
Date: Mon, 1 Jul 2019 08:45:14 +0200	[thread overview]
Message-ID: <20190701064514.jlocqt2nptmivx3l@pengutronix.de> (raw)
In-Reply-To: <a833d9b85f9449df778aec4e990a284379190993.camel@pengutronix.de>

On Mon, Jul 01, 2019 at 08:19:13AM +0200, Rouven Czerwinski wrote:
> On Wed, 2019-06-26 at 09:52 +0200, Sascha Hauer wrote:
> > On Wed, Jun 26, 2019 at 06:58:51AM +0200, Rouven Czerwinski wrote:
> > > 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 | 18 +++++++++++++++++-
> > >  1 file changed, 17 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
> > > index e527165..ce5f2c1 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,18 @@ 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();
> > > +		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('!');
> > > +			pr_err("hash mismatch, refusing to
> > > decompress");
> > > +			panic("hash mismatch, refusing to decompress");
> > 
> > Isn't printing the string in panic() enough?
> 
> Unfortunately not, pbl/misc.c defines panic as:
> 
> void __noreturn panic(const char *fmt, ...)
> {
> 	while(1);
> }

Then maybe we should add the printf here. We have static inline wrappers
for printf when the cosnole is disabled in the PBL.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2019-07-01  6:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26  4:58 [PATCH 00/13] HAB for i.MX8MQ Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 01/13] hab: implement interface " Rouven Czerwinski
2019-06-26  7:31   ` Sascha Hauer
2019-06-26 10:26     ` Roland Hieber
2019-06-26  4:58 ` [PATCH 02/13] mach-imx: enable HAB on i.MX8MQ Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 03/13] arm: lib: add CSF section between PBL and piggy Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 04/13] esdhc-pbl: extract header parsing from image start Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 05/13] esdhc-pbl: add piggy load function Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 06/13] sections: fix macro for barebox_pbl_size Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 07/13] scripts: imx: support signing for i.MX8MQ Rouven Czerwinski
2019-06-26  7:51   ` Sascha Hauer
2019-07-02  5:47     ` Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 08/13] images: always build sha256sum into pbl Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 09/13] pbl: add sha256 and piggy verification to PBL Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 10/13] arm: uncompress: verify sha256 if enabled Rouven Czerwinski
2019-06-26  7:52   ` Sascha Hauer
2019-07-01  6:19     ` Rouven Czerwinski
2019-07-01  6:45       ` Sascha Hauer [this message]
2019-06-26  4:58 ` [PATCH 11/13] mach-imx: add gencsf header for i.MX8MQ Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 12/13] mach-imx: hab: select piggy verification for i.MX8 Rouven Czerwinski
2019-06-26  4:58 ` [PATCH 13/13] boards: nxp-mx8-evk: rework to different boot flow 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=20190701064514.jlocqt2nptmivx3l@pengutronix.de \
    --to=s.hauer@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