crosvm/src
Daniel Verkamp 6a84706795 linux: check memory size calculation overflow
On systems where usize is 32 bits wide (e.g. 32-bit arm), the
calculation of memory_size in bytes based on the -m configuration option
in megabytes would silently overflow when the resulting value was wider
than 32 bits.

Change the shift that converts megabytes to bytes into a checked_mul so
that a suitable error is produced if the size overflows.

Additionally, change the cfg.memory type to u64 instead of usize; this
is representing a size in megabytes, so its maximum value isn't related
to the size of an object in memory anyway, and this avoids the need for
a cast in the memory_size calculation.  Requesting a memory size larger
than the crosvm process can map will still result in an error at a later
stage in guest startup.

BUG=chromium:1028747
TEST=`crosvm run -m $((5 * 1024)) ...` on kevin

Change-Id: I8fef7070bab4dafff70ed54738b26d0bb7632150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937551
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 09:37:52 +00:00
..
plugin resource: Rename device memory to mmio 2019-11-10 06:39:34 +00:00
argument.rs split crosvm into a library and a main "crosvm" binary 2019-08-06 19:23:06 +00:00
crosvm.rs linux: check memory size calculation overflow 2019-12-06 09:37:52 +00:00
linux.rs linux: check memory size calculation overflow 2019-12-06 09:37:52 +00:00
main.rs Add fs device to --shared-dir 2019-11-19 17:59:47 +00:00
panic_hook.rs edition: Fill in macro imports 2019-04-15 02:06:07 -07:00