All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: "Marek Behún" <kabel@kernel.org>
Cc: u-boot@lists.denx.de, "Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>
Subject: Re: [PATCH u-boot-marvell 04/11] tools: kwbimage: Fix validation of kwbimage v0
Date: Wed, 10 Nov 2021 09:24:42 +0100	[thread overview]
Message-ID: <0ded6e30-7f8b-5304-8c03-d0fa8eee83f9@denx.de> (raw)
In-Reply-To: <20211108171251.25382-5-kabel@kernel.org>

On 08.11.21 18:12, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> kwbimage v0 sldo has 32-bit data checksum at the end like kwbimage v1.
> 
> Use same data checksum validation for both v0 and v1 image types.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 80 ++++++++++++++++++++++++++----------------------
>   1 file changed, 43 insertions(+), 37 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 38b6e2fed2..a176b39b08 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -1680,6 +1680,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
>   				  struct image_tool_params *params)
>   {
>   	size_t header_size = kwbheader_size(ptr);
> +	uint8_t blockid;
> +	uint32_t offset;
> +	uint32_t size;
>   	uint8_t csum;
>   
>   	if (header_size > image_size)
> @@ -1699,61 +1702,64 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
>   			if (csum != ext_hdr->checksum)
>   				return -FDT_ERR_BADSTRUCTURE;
>   		}
> +
> +		blockid = mhdr->blockid;
> +		offset = le32_to_cpu(mhdr->srcaddr);
> +		size = le32_to_cpu(mhdr->blocksize);
>   	} else if (kwbimage_version(ptr) == 1) {
>   		struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
>   		const uint8_t *mhdr_end;
>   		struct opt_hdr_v1 *ohdr;
> -		uint32_t offset;
> -		uint32_t size;
>   
>   		mhdr_end = (uint8_t *)mhdr + header_size;
>   		for_each_opt_hdr_v1 (ohdr, ptr)
>   			if (!opt_hdr_v1_valid_size(ohdr, mhdr_end))
>   				return -FDT_ERR_BADSTRUCTURE;
>   
> +		blockid = mhdr->blockid;
>   		offset = le32_to_cpu(mhdr->srcaddr);
> +		size = le32_to_cpu(mhdr->blocksize);
> +	} else {
> +		return -FDT_ERR_BADSTRUCTURE;
> +	}
>   
> -		/*
> -		 * For SATA srcaddr is specified in number of sectors.
> -		 * The main header is must be stored at sector number 1.
> -		 * This expects that sector size is 512 bytes and recalculates
> -		 * data offset to bytes relative to the main header.
> -		 */
> -		if (mhdr->blockid == IBR_HDR_SATA_ID) {
> -			if (offset < 1)
> -				return -FDT_ERR_BADSTRUCTURE;
> -			offset -= 1;
> -			offset *= 512;
> -		}
> +	/*
> +	 * For SATA srcaddr is specified in number of sectors.
> +	 * The main header is must be stored at sector number 1.
> +	 * This expects that sector size is 512 bytes and recalculates
> +	 * data offset to bytes relative to the main header.
> +	 */
> +	if (blockid == IBR_HDR_SATA_ID) {
> +		if (offset < 1)
> +			return -FDT_ERR_BADSTRUCTURE;
> +		offset -= 1;
> +		offset *= 512;
> +	}
>   
> -		/*
> -		 * For SDIO srcaddr is specified in number of sectors.
> -		 * This expects that sector size is 512 bytes and recalculates
> -		 * data offset to bytes.
> -		 */
> -		if (mhdr->blockid == IBR_HDR_SDIO_ID)
> -			offset *= 512;
> +	/*
> +	 * For SDIO srcaddr is specified in number of sectors.
> +	 * This expects that sector size is 512 bytes and recalculates
> +	 * data offset to bytes.
> +	 */
> +	if (blockid == IBR_HDR_SDIO_ID)
> +		offset *= 512;
>   
> -		/*
> -		 * For PCIe srcaddr is always set to 0xFFFFFFFF.
> -		 * This expects that data starts after all headers.
> -		 */
> -		if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF)
> -			offset = header_size;
> +	/*
> +	 * For PCIe srcaddr is always set to 0xFFFFFFFF.
> +	 * This expects that data starts after all headers.
> +	 */
> +	if (blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF)
> +		offset = header_size;
>   
> -		if (offset > image_size || offset % 4 != 0)
> -			return -FDT_ERR_BADSTRUCTURE;
> +	if (offset > image_size || offset % 4 != 0)
> +		return -FDT_ERR_BADSTRUCTURE;
>   
> -		size = le32_to_cpu(mhdr->blocksize);
> -		if (size < 4 || offset + size > image_size || size % 4 != 0)
> -			return -FDT_ERR_BADSTRUCTURE;
> +	if (size < 4 || offset + size > image_size || size % 4 != 0)
> +		return -FDT_ERR_BADSTRUCTURE;
>   
> -		if (image_checksum32(ptr + offset, size - 4) !=
> -		    *(uint32_t *)(ptr + offset + size - 4))
> -			return -FDT_ERR_BADSTRUCTURE;
> -	} else {
> +	if (image_checksum32(ptr + offset, size - 4) !=
> +	    *(uint32_t *)(ptr + offset + size - 4))
>   		return -FDT_ERR_BADSTRUCTURE;
> -	}
>   
>   	return 0;
>   }
> 

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

  reply	other threads:[~2021-11-10  8:24 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 17:12 [PATCH u-boot-marvell 00/11] Another kwbimage series Marek Behún
2021-11-08 17:12 ` [PATCH u-boot-marvell 01/11] tools: kwbimage: Add support for new commands UART_PORT and UART_MPP Marek Behún
2021-11-10  8:23   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 02/11] tools: kwbimage: Explicitly set version also for kwbimage v0 Marek Behún
2021-11-10  8:23   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 03/11] tools: kwbimage: Set BOOT_FROM by default to SPI Marek Behún
2021-11-10  8:23   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 04/11] tools: kwbimage: Fix validation of kwbimage v0 Marek Behún
2021-11-10  8:24   ` Stefan Roese [this message]
2021-11-08 17:12 ` [PATCH u-boot-marvell 05/11] tools: kwbimage: Remove unused enums and prototypes Marek Behún
2021-11-10  8:25   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 06/11] tools: kwbimage: Align final UART image to 128 bytes Marek Behún
2021-11-10  8:28   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 07/11] tools: kwbimage: Do not put final image padding to the image data size Marek Behún
2021-11-10  8:28   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 08/11] tools: kwbimage: Align kwbimage header to proper size Marek Behún
2021-11-10  8:28   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 09/11] tools: kwbimage: Fill the real header size into the main header Marek Behún
2021-11-10  8:29   ` Stefan Roese
2021-12-25 17:48   ` Pierre Bourdon
2021-12-25 17:57     ` Pali Rohár
2021-12-25 18:06       ` Pierre Bourdon
2021-12-25 18:10         ` Pali Rohár
2021-12-25 18:18           ` Pierre Bourdon
2021-12-25 19:11             ` Pali Rohár
2021-12-25 19:48               ` Pierre Bourdon
2021-12-25 20:01                 ` Pali Rohár
2021-12-25 20:15                   ` Pierre Bourdon
2021-12-25 20:42                     ` Pali Rohár
2021-11-08 17:12 ` [PATCH u-boot-marvell 10/11] tools: kwbimage: Properly calculate and align kwbimage v0 header size Marek Behún
2021-11-10  8:30   ` Stefan Roese
2021-11-08 17:12 ` [PATCH u-boot-marvell 11/11] tools: kwbimage: Properly set srcaddr in kwbimage v0 Marek Behún
2021-11-10  8:30   ` Stefan Roese
2021-11-10  5:41 ` [PATCH u-boot-marvell 00/11] Another kwbimage series Stefan Roese
2021-11-10  8:19   ` Pali Rohár
2021-11-10 13:52 ` Stefan Roese

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=0ded6e30-7f8b-5304-8c03-d0fa8eee83f9@denx.de \
    --to=sr@denx.de \
    --cc=kabel@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=u-boot@lists.denx.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 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.