]> git.ipfire.org Git - thirdparty/grub.git/commit
disk/cryptodisk: Fix unintentional integer overflow
authorAlec Brown <alec.r.brown@oracle.com>
Fri, 14 Oct 2022 21:47:08 +0000 (17:47 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 27 Oct 2022 13:57:14 +0000 (15:57 +0200)
commitc76a07e15f09e7d06bb3c30666caa35f13d8b3a7
tree275e19dde6dbaedb3042e19ec3af89d9db80a7e6
parent17975d10a80e2457e5237f87fa58a7943031983e
disk/cryptodisk: Fix unintentional integer overflow

In the function grub_cryptodisk_endecrypt(), a for loop is incrementing the
variable i by (1U << log_sector_size). The variable i is of type grub_size_t
which is a 64-bit unsigned integer on x86_64 architecture. On the other hand, 1U
is a 32-bit unsigned integer. By performing a left shift on a 32-bit value and
assigning it to a 64-bit variable, the 64-bit variable may have incorrect values
in the high 32-bits if the shift has an overflow. To avoid this, we replace 1U
with (grub_size_t)1.

Fixes: CID 307788
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/disk/cryptodisk.c