Re: [PATCH] arm64: kvm: Fix potential overflow in len
From: Marc Zyngier
Date: Sat Dec 28 2024 - 05:08:15 EST
On Sat, 28 Dec 2024 02:01:27 +0000,
Steven Davis <goldside000@xxxxxxxxxxx> wrote:
>
> The MMIO sign-extension logic in kvm_handle_mmio_return can
> trigger an integer overflow or undefined behavior when len
> is invalid (e.g., len == 0 or len exceeds the size of unsigned
> long). Specifically, the expression (len * 8) - 1 may result
> in an out-of-bounds shift in the computation of the mask.
>
> This patch adds validation to ensure len is greater than
> 0 and less than the size of unsigned long before performing
> the sign-extension logic. If len falls outside this range,
> the problematic logic is skipped, preventing potential issues.
I'd be curious to understand how you came to this conclusion, given
how len is computed. If anything, we could *remove* some of the
checks, rather than adding additional ones.
Also, "skipping" things is rarely an acceptable behaviour when
emulating hardware behaviour.
M.
--
Without deviation from the norm, progress is not possible.