Skip to content

Commit

Permalink
dbootimg: Fix sigsegv while updating kernel with no dtb
Browse files Browse the repository at this point in the history
Trying to update a kernel with no appended dtb resulted in:

root@qt5506:~# dbootimg /dev/disk/by-partlabel/boot -u kernel /boot/Image.gz
DTB not found in boot image
[ 2130.770995] audit: type=1701 audit(1533805111.476:2): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=3453 comm="dbootimg" exe="/usr/bin/dbootimg" sig=11 res=1
Segmentation fault (core dumped)

This patch allows upding the dtb IIF the old image contained an appended
dtb.

Signed-off-by: Ricardo Ribalda Delgado <[email protected]>
  • Loading branch information
ribalda committed Aug 9, 2018
1 parent 6f39447 commit 228fd29
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/dbootimg/src/dbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,21 @@ static void *aboot_update_dtb(void *boot, void *dtb, bool force)
static void *aboot_update_kernel(void *boot, void *kernel)
{
struct aboot_hdr *aboot, *old_aboot = boot;
ssize_t page_sz, kernel_sz, align_sz;
ssize_t page_sz, kernel_sz, align_sz, dtb_sz;
void *old_kernel, *dtb, *ptr;
int diff;

page_sz = le32_to_cpu(old_aboot->page_size);
old_kernel = aboot_get_kernel(old_aboot);
kernel_sz = kernelgz_size(kernel);
dtb = aboot_get_dtb(old_aboot);

if (kernel_has_appended_dtb(kernel)){
dtb = aboot_get_dtb(old_aboot);
dtb_sz = dtb_size(dtb);
} else {
dtb = NULL;
dtb_sz = 0;
}

diff = kernel_sz - kernelgz_size(old_kernel);

Expand All @@ -457,11 +464,11 @@ static void *aboot_update_kernel(void *boot, void *kernel)
ptr += kernel_sz;

/* copy appended dtb */
memcpy(ptr, dtb, dtb_size(dtb));
ptr += dtb_size(dtb);
memcpy(ptr, dtb, dtb_sz);
ptr += dtb_sz;

/* modify kernel size (kernel.gz + dtb) */
aboot->kernel_size = cpu_to_le32(kernel_sz + dtb_size(dtb));
aboot->kernel_size = cpu_to_le32(kernel_sz + dtb_sz);

/* align on page */
align_sz = page_sz - le32_to_cpu(aboot->kernel_size) % page_sz;
Expand Down

0 comments on commit 228fd29

Please sign in to comment.