mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: "Daniel Brát" <danek.brat@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] image-fit: use real size of fit image
Date: Mon, 8 Aug 2022 15:20:40 +0200	[thread overview]
Message-ID: <20220808132040.GP31528@pengutronix.de> (raw)
In-Reply-To: <20220729205441.9512-1-danek.brat@gmail.com>

On Fri, Jul 29, 2022 at 10:54:41PM +0200, Daniel Brát wrote:
> The real size of the fit image might be significantly smaller than it may
> appear to be based on the specified filename. For example, if path to raw disk
> partition is passed (eg. /dev/disk0.1), the size of the partition itself
> might be several times larger than the fit image it contains at the moment
> (so it has headroom for possible future image size changes).
> This modification uses the fdt header field 'totalsize' to read-in only what
> is needed.
> 
> Signed-off-by: Daniel Brát <danek.brat@gmail.com>
> ---
> v2: use fdt32_to_cpu to read the totalsize from header
> ---
>  common/image-fit.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/common/image-fit.c b/common/image-fit.c
> index a410632d7..de65e3dd1 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -774,13 +774,18 @@ struct fit_handle *fit_open_buf(const void *buf, size_t size, bool verbose,
>  				enum bootm_verify verify)
>  {
>  	struct fit_handle *handle;
> +	struct fdt_header *header;
>  	int ret;
>  
> +	if (size < sizeof(*header))
> +		return ERR_PTR(-EINVAL);
> +
> +	header = (struct fdt_header*)buf;
>  	handle = xzalloc(sizeof(struct fit_handle));
>  
>  	handle->verbose = verbose;
>  	handle->fit = buf;
> -	handle->size = size;
> +	handle->size = fdt32_to_cpu(header->totalsize);

Should we check that header->totalsize doesn't exceed the passed buffer
size?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2022-08-08 13:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29 20:54 Daniel Brát
2022-08-08 13:20 ` 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=20220808132040.GP31528@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=danek.brat@gmail.com \
    /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