Skip to content

Commit

Permalink
tools: kwboot: Do not modify kwbimage header before increasing its size
Browse files Browse the repository at this point in the history
This ensures that kwboot_img_grow_hdr() function still sees valid kwbimage
header.

Signed-off-by: Pali Rohár <[email protected]>
Reviewed-by: Marek Behún <[email protected]>
Reviewed-by: Stefan Roese <[email protected]>
  • Loading branch information
pali authored and stroese committed Nov 3, 2021
1 parent ed792c2 commit e511cc3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/kwboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,17 +1352,18 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)
uint32_t num_args;
uint32_t offset;
uint32_t ohdrsz;
uint8_t *prev_ext;

if (hdr->ext & 0x1) {
for_each_opt_hdr_v1 (ohdr, img)
if (opt_hdr_v1_next(ohdr) == NULL)
break;

*opt_hdr_v1_ext(ohdr) |= 1;
ohdr = opt_hdr_v1_next(ohdr);
prev_ext = opt_hdr_v1_ext(ohdr);
ohdr = _opt_hdr_v1_next(ohdr);
} else {
hdr->ext |= 1;
ohdr = (void *)(hdr + 1);
prev_ext = &hdr->ext;
}

/*
Expand All @@ -1377,6 +1378,8 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)
ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4;
kwboot_img_grow_hdr(hdr, size, ohdrsz);

*prev_ext |= 1;

ohdr->headertype = OPT_HDR_V1_BINARY_TYPE;
ohdr->headersz_msb = ohdrsz >> 16;
ohdr->headersz_lsb = cpu_to_le16(ohdrsz & 0xffff);
Expand Down

0 comments on commit e511cc3

Please sign in to comment.