lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241228020119.12379-1-goldside000@outlook.com>
Date: Sat, 28 Dec 2024 02:01:27 +0000
From: Steven Davis <goldside000@...look.com>
To: "maz@...nel.org" <maz@...nel.org>, "oliver.upton@...ux.dev"
	<oliver.upton@...ux.dev>, "catalin.marinas@....com"
	<catalin.marinas@....com>, "will@...nel.org" <will@...nel.org>
CC: "joey.gouly@....com" <joey.gouly@....com>, "suzuki.poulose@....com"
	<suzuki.poulose@....com>, "yuzenghui@...wei.com" <yuzenghui@...wei.com>,
	"linux-arm-kernel@...ts.infradead.org"
	<linux-arm-kernel@...ts.infradead.org>, "kvmarm@...ts.linux.dev"
	<kvmarm@...ts.linux.dev>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, Steven Davis <goldside000@...look.com>
Subject: [PATCH] arm64: kvm: Fix potential overflow in len

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.

Signed-off-by: Steven Davis <goldside000@...look.com>
---
 arch/arm64/kvm/mmio.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c
index ab365e839..e4132dbc3 100644
--- a/arch/arm64/kvm/mmio.c
+++ b/arch/arm64/kvm/mmio.c
@@ -124,12 +124,15 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu)
 		len = kvm_vcpu_dabt_get_as(vcpu);
 		data = kvm_mmio_read_buf(run->mmio.data, len);
 
-		if (kvm_vcpu_dabt_issext(vcpu) &&
-		    len < sizeof(unsigned long)) {
-			mask = 1U << ((len * 8) - 1);
-			data = (data ^ mask) - mask;
+		if (kvm_vcpu_dabt_issext(vcpu)) {
+			if (len > 0 && len < sizeof(unsigned long)) {
+				mask = 1U << ((len * 8) - 1);
+				data = (data ^ mask) - mask;
+			}
 		}
 
+
+
 		if (!kvm_vcpu_dabt_issf(vcpu))
 			data = data & 0xffffffff;
 
-- 
2.39.5

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ