From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: barebox@lists.infradead.org, bodhi <tlibertin@gmail.com>
Subject: Re: [PATCH 1/2] scripts: kwboot: fix image check for padded images
Date: Tue, 14 Feb 2017 08:47:49 +0100 [thread overview]
Message-ID: <20170214074749.4eqvjtshejqrvinw@pengutronix.de> (raw)
In-Reply-To: <20170211195752.13616-1-u.kleine-koenig@pengutronix.de>
On Sat, Feb 11, 2017 at 08:57:51PM +0100, Uwe Kleine-König wrote:
> When there is some padding between header and payload the claim
>
> header_size + image_size == file_size
>
> fails. Relax the check accordingly to:
>
> header_size <= image_offset &&
> image_offset + image_size == file_size
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> scripts/kwboot.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/scripts/kwboot.c b/scripts/kwboot.c
> index 9e4181e539ac..3ab26cd936c5 100644
> --- a/scripts/kwboot.c
> +++ b/scripts/kwboot.c
> @@ -603,7 +603,7 @@ static int
> kwboot_check_image(unsigned char *img, size_t size)
> {
> size_t i;
> - size_t header_size, image_size;
> + size_t header_size, image_size, image_offset;
> unsigned char csum = 0;
>
> if (size < 0x20) {
> @@ -640,12 +640,20 @@ kwboot_check_image(unsigned char *img, size_t size)
>
> image_size = img[0x4] | (img[0x5] << 8) |
> (img[0x6] << 16) | (img[0x7] << 24);
> + image_offset = img[0xc] | (img[0xd] << 8) |
> + (img[0xe] << 16) | (img[0xf] << 24);
>
> header_size = (img[0x9] << 16) | img[0xa] | (img[0xb] << 8);
>
> - if (header_size + image_size != size) {
> - fprintf(stderr, "Size mismatch (%zu + %zu != %zu)\n",
> - header_size, image_size, size);
> + if (header_size > image_offset) {
> + fprintf(stderr, "Header (%zu) expands over image start (%zu)\n",
> + header_size, image_offset);
> + return 1;
> + }
> +
> + if (image_offset + image_size != size) {
> + fprintf(stderr, "Image doesn't end at file end (%zu + %zu != %zu)\n",
> + image_offset, image_size, size);
> return 1;
> }
>
> --
> 2.11.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
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
prev parent reply other threads:[~2017-02-14 7:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-11 19:57 Uwe Kleine-König
2017-02-11 19:57 ` [PATCH 2/2] scripts/kwboot: new parameter -n to skip a number of NAKs Uwe Kleine-König
2017-02-14 7:47 ` Sascha Hauer [this message]
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=20170214074749.4eqvjtshejqrvinw@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=tlibertin@gmail.com \
--cc=u.kleine-koenig@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