From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79C377263E; Tue, 30 Sep 2025 09:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759224400; cv=none; b=FdZpe/15oLYXz+Ca8pdjcwrwwr0zIFPVr9gVquoYkcka+PyrEYfdlOkLwlZ5HGMnNyBboj8eW+iTH83hBrw4JnowVT9I3h3YVsP2mGMCNvXwohsgtzDHCP8u1UrpJKHYbL5VuMVwX94I/7WuKlYVXEim+OcxF2MZsaLETa5zEsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759224400; c=relaxed/simple; bh=LaLrgzwGba7zEB59O3aUOQQtLOL8fsXMk/3VcDu5h8g=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=hp3sJiKR29HIn7rwvH+EwfYW3SUIw01JsUMYL0ulQzEgYaf4IHPN5GZ/mbccM8BPFeI8o8Zo5u3NA+dM6bXmyWWJvl/UfMvW1da7Cpo2yg2ul86x/bc0aNWr/id8L+hi019e46+b6b8BE6K097h4z4DGD4bRTFVFD0uQ5DBTWkg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uiqPMkVo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uiqPMkVo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC850C4CEF0; Tue, 30 Sep 2025 09:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759224400; bh=LaLrgzwGba7zEB59O3aUOQQtLOL8fsXMk/3VcDu5h8g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uiqPMkVoAAyFcaFejM03jcImMGzyrGNTqKOVW5R0dcLbFWFxEzf9zuaZkeTQgyB3r 8E0dZpXg3LpdTABAM5pGciwB7bSKPJHiAeTRMFicox6zqgjZbYaZq75L5fqXba2Uxe gktSLySiCOks4FQl5Jf4YwwaHZBgrcd0HEy7EKGwkxE5jBLTdEKL0DPuRbnkDy0c2A n263DH/oNYadjpi5aKz24IGRInkn4Z0d/9H5/VVJuVsG7rHH+Q/8TgVWCLZMK8lFnv F9GSow3Ge0bQU1yL9iwpGIejf8kswIdHo3XzijSlCZNsj9YrJYHZYs5EopmsRro68p S9xrdBTJp2IkQ== 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.98.2) (envelope-from ) id 1v3Wd3-0000000AUmY-3Vg9; Tue, 30 Sep 2025 09:26:37 +0000 Date: Tue, 30 Sep 2025 10:26:37 +0100 Message-ID: <86v7l0z3xu.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, Joey Gouly , Suzuki K Poulose , Zenghui Yu , stable@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Prevent access to vCPU events before init In-Reply-To: <20250930085237.108326-1-oliver.upton@linux.dev> References: <20250930085237.108326-1-oliver.upton@linux.dev> 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/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: oliver.upton@linux.dev, kvmarm@lists.linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, stable@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 On Tue, 30 Sep 2025 09:52:37 +0100, Oliver Upton wrote: > > Another day, another syzkaller bug. KVM erroneously allows userspace to > pend vCPU events for a vCPU that hasn't been initialized yet, leading to > KVM interpreting a bunch of uninitialized garbage for routing / > injecting the exception. > > In one case the injection code and the hyp disagree on whether the vCPU > has a 32bit EL1 and put the vCPU into an illegal mode for AArch64, > tripping the BUG() in exception_target_el() during the next injection: > > kernel BUG at arch/arm64/kvm/inject_fault.c:40! > Internal error: Oops - BUG: 00000000f2000800 [#1] SMP > CPU: 3 UID: 0 PID: 318 Comm: repro Not tainted 6.17.0-rc4-00104-g10fd0285305d #6 PREEMPT > Hardware name: linux,dummy-virt (DT) > pstate: 21402009 (nzCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) > pc : exception_target_el+0x88/0x8c > lr : pend_serror_exception+0x18/0x13c > sp : ffff800082f03a10 > x29: ffff800082f03a10 x28: ffff0000cb132280 x27: 0000000000000000 > x26: 0000000000000000 x25: ffff0000c2a99c20 x24: 0000000000000000 > x23: 0000000000008000 x22: 0000000000000002 x21: 0000000000000004 > x20: 0000000000008000 x19: ffff0000c2a99c20 x18: 0000000000000000 > x17: 0000000000000000 x16: 0000000000000000 x15: 00000000200000c0 > x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 > x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 > x8 : ffff800082f03af8 x7 : 0000000000000000 x6 : 0000000000000000 > x5 : ffff800080f621f0 x4 : 0000000000000000 x3 : 0000000000000000 > x2 : 000000000040009b x1 : 0000000000000003 x0 : ffff0000c2a99c20 > Call trace: > exception_target_el+0x88/0x8c (P) > kvm_inject_serror_esr+0x40/0x3b4 > __kvm_arm_vcpu_set_events+0xf0/0x100 > kvm_arch_vcpu_ioctl+0x180/0x9d4 > kvm_vcpu_ioctl+0x60c/0x9f4 > __arm64_sys_ioctl+0xac/0x104 > invoke_syscall+0x48/0x110 > el0_svc_common.constprop.0+0x40/0xe0 > do_el0_svc+0x1c/0x28 > el0_svc+0x34/0xf0 > el0t_64_sync_handler+0xa0/0xe4 > el0t_64_sync+0x198/0x19c > Code: f946bc01 b4fffe61 9101e020 17fffff2 (d4210000) > > Reject the ioctls outright as no sane VMM would call these before > KVM_ARM_VCPU_INIT anyway. Even if it did the exception would've been > thrown away by the eventual reset of the vCPU's state. > > Cc: stable@vger.kernel.org # 6.17 > Fixes: b7b27facc7b5 ("arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS") > Signed-off-by: Oliver Upton > --- > > While the blamed commit is indeed broken, only 6.17+ kernels actually > hit the BUG() due to commit efa1368ba9f4 ("KVM: arm64: Commit exceptions > from KVM_SET_VCPU_EVENTS immediately). > > arch/arm64/kvm/arm.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index a59b4046617c..c44357d26ee8 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1795,6 +1795,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > case KVM_GET_VCPU_EVENTS: { > struct kvm_vcpu_events events; > > + if (!kvm_vcpu_initialized(vcpu)) > + return -ENOEXEC; > + > if (kvm_arm_vcpu_get_events(vcpu, &events)) > return -EINVAL; > > @@ -1806,6 +1809,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > case KVM_SET_VCPU_EVENTS: { > struct kvm_vcpu_events events; > > + if (!kvm_vcpu_initialized(vcpu)) > + return -ENOEXEC; > + > if (copy_from_user(&events, argp, sizeof(events))) > return -EFAULT; > > LGTM, but the -ENOEXEC part will eventually need being documented. I'll queue this now though, as it fixes an annoying bug. Thanks, M. -- Without deviation from the norm, progress is not possible.