From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1650FE7718F for ; Sat, 28 Dec 2024 10:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vljshgwoJytuspWRpwGKRUIGfL/K8c61lXKz+TO5gn0=; b=weXPk+uT/oxkSOGp5Lxj6ftCS+ b/CG4/EYt8pI4mwstDouSuvhWKlYOzHjM+Bva696uwhQN2bnCrUZSIqRv4GL4lGmVuiOjZukcU5+C 3V/SHm4Ufv/2RWDyVb9JZ3WYNo+c/RSEWqWP6vDvEuGXwejzXe6UNhrUSaZET0za/7MoSIPWs/dvf JCfjTQ/9oerj1pkAKTkvRXF3RSTTwtq+KA0y5PXDlZtsCI8TUZrI1JIVnxiFshfYp96ymPrW5eylL UY+/Hu6QHqKXnH4xCXAa9Sj6RgXgOGTLXwvuqDIBDahpDDst/izOeGKr00OIDWZeNxReMEOST6mM1 c//1S0tQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tRTly-00000001huN-3Mpi; Sat, 28 Dec 2024 10:10:18 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tRTjb-00000001hcy-1Xpl for linux-arm-kernel@lists.infradead.org; Sat, 28 Dec 2024 10:07:52 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3646B5C4ABA; Sat, 28 Dec 2024 10:07:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A70CC4CECD; Sat, 28 Dec 2024 10:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735380470; bh=YLgD9eimGEFiztCLYuVJVZB87yEhKC50Hf8bnQfMVHA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PVkxFkW/RQ5Mz+51SY5V7br71skXrRCzCH785yUeFXKbZuawZECj52Lri4gSCev9K jtm0ffLDnGci9QiCTkVNCMtCO/EY1X7EAOpp698yoq/+k/v6XaBkeGv8swIqY/I3bW v7lo218YUeylrxjV/MzNCm4e1C1pQOedYuIpddqFMe8Wv4PXR/CuQicOn76E/ALTK4 VD8xu1/sWCPs1ge9/EZfVsIRtBv2G/Iwrtg5lfszIReOqm8ZztEnIYEe4Das7BUReu OoM6PFcjs+7bpqpudTeoLLl9wD6VtVeAiKJmkACiv85VhBkICpWrAMZPwcHdrSTl4W jPO4peHwpaTAQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tRTjY-007NEB-1n; Sat, 28 Dec 2024 10:07:48 +0000 Date: Sat, 28 Dec 2024 10:07:47 +0000 Message-ID: <86jzbkp1cc.wl-maz@kernel.org> From: Marc Zyngier To: Steven Davis Cc: "oliver.upton@linux.dev" , "catalin.marinas@arm.com" , "will@kernel.org" , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] arm64: kvm: Fix potential overflow in len In-Reply-To: <20241228020119.12379-1-goldside000@outlook.com> References: <20241228020119.12379-1-goldside000@outlook.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: goldside000@outlook.com, oliver.upton@linux.dev, catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241228_020751_451334_EF36D875 X-CRM114-Status: GOOD ( 14.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 28 Dec 2024 02:01:27 +0000, Steven Davis 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.