All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Sean Anderson <sean.anderson@seco.com>
Cc: u-boot@lists.denx.de,
	Gary Bisson <gary.bisson@boundarydevices.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>,
	Heiko Schocher <hs@denx.de>, Simon Glass <sjg@chromium.org>,
	Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH] fastboot: Fix overflow when calculating chunk size
Date: Wed, 26 May 2021 09:12:30 +0200	[thread overview]
Message-ID: <20210526091230.0a51acc2@ktm> (raw)
In-Reply-To: <3564f958-a796-f081-4a81-c9f2308eb387@seco.com>

[-- Attachment #1: Type: text/plain, Size: 3690 bytes --]

Hi Sean,

> On 5/13/21 11:54 AM, Sean Anderson wrote:
> > Hi Lukasz,
> > 
> > Can this make it into 2020.07? Thanks,  
> 
> ping? Should Tom pick this up instead?
> 

Yes, Tom please pick it up - as I will not prepare PR sooner than June.

> --Sean
> 
> > 
> > --Sean
> > 
> > On 4/16/21 5:58 PM, Sean Anderson wrote:  
> >> If a chunk was larger than 4GiB, then chunk_data_sz would overflow
> >> and blkcnt would not be calculated correctly. Upgrade it to a u64
> >> and cast its multiplicands as well. Also fix bytes_written while
> >> we're at it.
> >>
> >> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> >> ---
> >>
> >>   lib/image-sparse.c | 12 ++++++------
> >>   1 file changed, 6 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/lib/image-sparse.c b/lib/image-sparse.c
> >> index 187ac28cd3..52c8dcc08c 100644
> >> --- a/lib/image-sparse.c
> >> +++ b/lib/image-sparse.c
> >> @@ -55,10 +55,10 @@ int write_sparse_image(struct sparse_storage
> >> *info, lbaint_t blk;
> >>       lbaint_t blkcnt;
> >>       lbaint_t blks;
> >> -    uint32_t bytes_written = 0;
> >> +    uint64_t bytes_written = 0;
> >>       unsigned int chunk;
> >>       unsigned int offset;
> >> -    unsigned int chunk_data_sz;
> >> +    uint64_t chunk_data_sz;
> >>       uint32_t *fill_buf = NULL;
> >>       uint32_t fill_val;
> >>       sparse_header_t *sparse_header;
> >> @@ -132,7 +132,7 @@ int write_sparse_image(struct sparse_storage
> >> *info, sizeof(chunk_header_t));
> >>           }
> >> -        chunk_data_sz = sparse_header->blk_sz *
> >> chunk_header->chunk_sz;
> >> +        chunk_data_sz = ((u64)sparse_header->blk_sz) *
> >> chunk_header->chunk_sz; blkcnt = chunk_data_sz / info->blksz;
> >>           switch (chunk_header->chunk_type) {
> >>           case CHUNK_TYPE_RAW:
> >> @@ -162,7 +162,7 @@ int write_sparse_image(struct sparse_storage
> >> *info, return -1;
> >>               }
> >>               blk += blks;
> >> -            bytes_written += blkcnt * info->blksz;
> >> +            bytes_written += ((u64)blkcnt) * info->blksz;
> >>               total_blocks += chunk_header->chunk_sz;
> >>               data += chunk_data_sz;
> >>               break;
> >> @@ -222,7 +222,7 @@ int write_sparse_image(struct sparse_storage
> >> *info, blk += blks;
> >>                   i += j;
> >>               }
> >> -            bytes_written += blkcnt * info->blksz;
> >> +            bytes_written += ((u64)blkcnt) * info->blksz;
> >>               total_blocks += chunk_data_sz /
> >> sparse_header->blk_sz; free(fill_buf);
> >>               break;
> >> @@ -253,7 +253,7 @@ int write_sparse_image(struct sparse_storage
> >> *info, debug("Wrote %d blocks, expected to write %d blocks\n",
> >>             total_blocks, sparse_header->total_blks);
> >> -    printf("........ wrote %u bytes to '%s'\n", bytes_written,
> >> part_name);
> >> +    printf("........ wrote %llu bytes to '%s'\n", bytes_written,
> >> part_name); if (total_blocks != sparse_header->total_blks) {
> >>           info->mssg("sparse image write failure", response);
> >>  



Best regards,

Lukasz Majewski

--

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-05-26  7:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 21:58 [PATCH] fastboot: Fix overflow when calculating chunk size Sean Anderson
2021-04-19  4:31 ` Heiko Schocher
2021-04-19 14:13   ` Sean Anderson
2021-05-13 15:54 ` Sean Anderson
2021-05-25 15:45   ` Sean Anderson
2021-05-26  7:12     ` Lukasz Majewski [this message]
2021-05-26 21:25 ` Tom Rini

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=20210526091230.0a51acc2@ktm \
    --to=lukma@denx.de \
    --cc=gary.bisson@boundarydevices.com \
    --cc=hs@denx.de \
    --cc=patrick.delaunay@foss.st.com \
    --cc=roman.kovalivskyi@globallogic.com \
    --cc=sean.anderson@seco.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --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.