From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 66D0752FE5F; Wed, 30 Sep 2026 18:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790793805; cv=none; b=Iht2QrOc1wxsVFg8Vy+e7KyPMEBsM9J3L+wpjf1cPaAUQiOuTuHz4Pn3MQSgYSs1g8DqQxthfejlEAEkf15f6F+oex+HTWrzgFq+f3tC4h3sqwaSUGiFn1Xq+AG4d/Y80owEK2avapcIsmA3Zy5vmqlhPAEPQQ2sMAxufwf7EKM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790793805; c=relaxed/simple; bh=5SQuCYp+O/WlMwAsCW6tRGjgnCEISyUKXKywyA2NXOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGz0yhf96Ogy+gcauC+agYnNWr+9cMklX8aFU6BMm6un9WtPiTGSZ6seYKFIC9xG66qr1WiZmrPhHjrBzxp7UpcljZpX0hYGkzGD+SYsYWus6iimCrwO1TBp/68STa3cj0VSm9qsJTKIoh7H3vPjsprsuGBAWMZWxgUpm8CBhmk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0rjjd1lV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0rjjd1lV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C18C01F000FF; Wed, 30 Sep 2026 18:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790793804; bh=UO8t8cyCyDyd15OA2hBwoWHzIht/LEUNTFQVPx+6Unc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0rjjd1lVOhK8X6K4rEcRo6LJgvjgK4+BgQKSC+fooep2mBSAvjKxuLmyQqw3xxyja AuqyFe5CuWU/NPfGAYuMerseb+Uf4U8UdGpFbY+QeBGk0hhDZWdnNPvTKWM629yfMw Lxjn+0y9WJVpN9fcKwIPPNpaf4fQg5d94pt+81vQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiakai Xu , Jiakai Xu , Anup Patel , Sasha Levin Subject: [PATCH 6.18 384/395] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr() Date: Wed, 30 Sep 2026 17:30:46 +0200 Message-ID: <20260930152349.030631950@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152340.591469096@linuxfoundation.org> References: <20260930152340.591469096@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiakai Xu [ Upstream commit aeb1d17d1af5924f7357d7204a293bd8fc06ea13 ] Add a null pointer check for imsic_state before dereferencing it in kvm_riscv_aia_imsic_rw_attr(). While the function checks that the vcpu exists, it doesn't verify that the vcpu's imsic_state has been initialized, leading to a null pointer dereference when accessed. The crash manifests as: Unable to handle kernel paging request at virtual address dfffffff00000006 ... kvm_riscv_aia_imsic_rw_attr+0x2d8/0x854 arch/riscv/kvm/aia_imsic.c:958 aia_set_attr+0x2ee/0x1726 arch/riscv/kvm/aia_device.c:354 kvm_device_ioctl_attr virt/kvm/kvm_main.c:4744 [inline] kvm_device_ioctl+0x296/0x374 virt/kvm/kvm_main.c:4761 vfs_ioctl fs/ioctl.c:51 [inline] ... The fix adds a check to return -ENODEV if imsic_state is NULL and moves isel assignment after imsic_state NULL check. Fixes: 5463091a51cfaa ("RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip") Signed-off-by: Jiakai Xu Signed-off-by: Jiakai Xu Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260127072219.3366607-1-xujiakai2025@iscas.ac.cn Signed-off-by: Anup Patel Stable-dep-of: 8ae12ccaec6e ("RISC-V: KVM: Serialize IMSIC attributes with vCPU migration") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kvm/aia_imsic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/riscv/kvm/aia_imsic.c +++ b/arch/riscv/kvm/aia_imsic.c @@ -952,8 +952,10 @@ int kvm_riscv_aia_imsic_rw_attr(struct k if (!vcpu) return -ENODEV; - isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type); imsic = vcpu->arch.aia_context.imsic_state; + if (!imsic) + return -ENODEV; + isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type); read_lock_irqsave(&imsic->vsfile_lock, flags);