]> git.baikalelectronics.ru Git - uboot.git/commit
tools: mkimage: Ensure munmap unmaps the same length that was mapped
authorMark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Tue, 28 Aug 2018 22:51:14 +0000 (10:51 +1200)
committerTom Rini <trini@konsulko.com>
Tue, 11 Sep 2018 01:19:32 +0000 (21:19 -0400)
commit8448befae8b456bc0739575e5f6aec612b9d42de
tree168dceaa4be9885b4415a925acb78911308a48c3
parent0bad5ae8bafa64fd7ad1d7a7288ac6e538b3ce24
tools: mkimage: Ensure munmap unmaps the same length that was mapped

The set_header call in kwbimage.c adds a checksum to the end of the
image in addition to setting up the header. It 'helpfully' updates the
st_size to match the fact that the file is now longer. However, mkimage
uses this length in the munmap call. This can lead to unmapping an extra
page, of perhaps required data. When this happens, a SEGV can occur.

To prevent this from happening, the munmap call now uses the same length
that was passed to mmap. This could also have been fixed by not changing
the length in kwbimage.c, however changing it in the main file means
that other plugins will also not fall for the same trap.

Signed-off-by: Mark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
[cp: resolve checkpatch complaints]
Tested-by: Chris Packham <judge.packham@gmail.com>
tools/mkimage.c