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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 96D24C5AD49 for ; Mon, 2 Jun 2025 13:39:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1003346.1382905 (Exim 4.92) (envelope-from ) id 1uM5Nn-00037V-1B; Mon, 02 Jun 2025 13:39:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1003346.1382905; Mon, 02 Jun 2025 13:39:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uM5Nm-00037O-T2; Mon, 02 Jun 2025 13:39:18 +0000 Received: by outflank-mailman (input) for mailman id 1003346; Mon, 02 Jun 2025 13:39:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uM5Nj-00037I-Nv for xen-devel@lists.xenproject.org; Mon, 02 Jun 2025 13:39:18 +0000 Received: from postout1.mail.lrz.de (postout1.mail.lrz.de [129.187.255.137]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f93cb0e5-3fb6-11f0-a300-13f23c93f187; Mon, 02 Jun 2025 15:39:14 +0200 (CEST) Received: from lxmhs51.srv.lrz.de (localhost [127.0.0.1]) by postout1.mail.lrz.de (Postfix) with ESMTP id 4b9w1G468hzySV for ; Mon, 2 Jun 2025 15:39:14 +0200 (CEST) Received: from postout1.mail.lrz.de ([127.0.0.1]) by lxmhs51.srv.lrz.de (lxmhs51.srv.lrz.de [127.0.0.1]) (amavis, port 20024) with LMTP id ZlMNUrqWyXHe for ; Mon, 2 Jun 2025 15:39:13 +0200 (CEST) Received: from [IPV6:2a02:2455:1858:e00:e0bb:e98d:8f46:dc66] (unknown [IPv6:2a02:2455:1858:e00:e0bb:e98d:8f46:dc66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by postout1.mail.lrz.de (Postfix) with ESMTPSA id 4b9w1D6JC4zyVm for ; Mon, 2 Jun 2025 15:39:12 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f93cb0e5-3fb6-11f0-a300-13f23c93f187 Authentication-Results: postout.lrz.de (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=tum.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tum.de; h= in-reply-to:references:content-language:subject:subject:from :from:user-agent:mime-version:date:date:message-id:content-type :content-type:received:received; s=tu-postout21; t=1748871553; bh=bfukpYZo80PMkfvoZk9FkrYpOY/fDD2jTTnWUQHlWZw=; b=PFohczUPpyQs 7MhbiivoDShwyQUZZ86x2wIKgdlU6hWrTGtzjNtfb5Kbl3wdQX3HpxRz/caahJd9 E1Sve6lQRsf7V8nDo8gqFqQfIy+ax3Pft09yxNIMfymM+qMLxd4NcEZBOOe6fury 6atZRFmD7/uyfWKFckUhASbzKzMXV77ma1gixl32TVOQhn4keJ5bbLKIcN/zmpkq LMOJxkTsDznWueGn+WTQNDJeIi8EoJJcVUQO/inQeWJXy6bkjtn0A4uwlDHnuJeg jS2Tcp0mKpHVGioZzOcS/mIc4z5m+hEpqwAQoyVz+zprITWHKF6QucdlR++HPMR2 ov5s1iz4nA== X-Virus-Scanned: by amavisd-new at lrz.de in lxmhs51.srv.lrz.de Content-Type: multipart/mixed; boundary="------------7k0v5mQ5ROhNHfbSS6tpHkwi" Message-ID: <6d28eb0c-caed-4c58-a6ac-cbf8da357d22@tum.de> Date: Mon, 2 Jun 2025 15:39:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Manuel Andreas Subject: Nullptr dereference in nested VMX when shadow VMCS support is available Content-Language: en-US References: <5f258e25-a4ed-4f9a-8ca6-9ea3400e2369@tum.de> To: xen-devel@lists.xenproject.org Autocrypt: addr=manuel.andreas@tum.de; keydata= xjMEY9Zx/RYJKwYBBAHaRw8BAQdALWzRzW9a74DX4l6i8VzXGvv72Vz0qfvj9s7bjBD905nN Jk1hbnVlbCBBbmRyZWFzIDxtYW51ZWwuYW5kcmVhc0B0dW0uZGU+wokEExYIADEWIQQuSfNX 11QV6exAUmOqZGwY4LuingUCY9Zx/QIbAwQLCQgHBRUICQoLBRYCAwEAAAoJEKpkbBjgu6Ke McQBAPyP530S365I50I5rM2XjH5Hr9YcUQATD5dusZJMDgejAP9T/wUurwQSuRfm1rK8cNcf w4wP3+PLvL+J+kuVku93CM44BGPWcf0SCisGAQQBl1UBBQEBB0AmCAf31tLBD5tvtdZ0XX1B yGLUAxhgmFskGyPhY8wOKQMBCAfCeAQYFggAIBYhBC5J81fXVBXp7EBSY6pkbBjgu6KeBQJj 1nH9AhsMAAoJEKpkbBjgu6Kej6YA/RvJdXMjsD5csifolLw53KX0/ElM22SvaGym1+KiiVND AQDy+y+bCXI+J713/AwLBsDxTEXmP7Cp49ZqbAu83NnpBQ== In-Reply-To: <5f258e25-a4ed-4f9a-8ca6-9ea3400e2369@tum.de> This is a multi-part message in MIME format. --------------7k0v5mQ5ROhNHfbSS6tpHkwi Content-Type: multipart/alternative; boundary="------------5mUg0o6IZ2M7iPMMkaAxDZ0X" --------------5mUg0o6IZ2M7iPMMkaAxDZ0X Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Dear all, I've discovered an issue in the nested VMX implementation, where an unprivileged domain is able to force Xen to dereference a NULL pointer, resulting in a panic. This is possible when: 1. The malicious domain has nested HVM capabilities. 2. The CPU is running on top of VMX and supports shadow VMCS. To trigger the bug, the domain must first enable VMX operation for itself, execute VMXON and then finally execute VMPTRLD on a guest physical address that is backed by a non-writable p2m mapping. In `nvmx_handle_vmptrld`, after attempting to map the nested VMCS, Xen will check whether or not this mapping is suitable for writing and if not immediately unmap the nested VMCS again and abort the setup of `nvcpu->nv_vvmcx`. However, Xen at this point erroneously continues emulation of the VMPTRLD. In particular, if VMCS shadowing is available, Xen will nonetheless attempt to link up the nested VMCS to its own VMCS in `nvmx_set_vmcs_pointer`. Importantly, Xen here attempts to dereference the presumably mapped nested VMCS (which now is merely a NULL pointer) in order to mark it as a shadow VMCS by applying the `VMCS_RID_TYPE_MASK` to its revision identifier. Following, the page fault handler will panic Xen. I've attached an XTF reproducer that triggers the bug. To setup such a non-writable p2m mapping for the malicious VMCS, I first setup an appropriate grant table entry. I've tested it on Xen version 4.20.0. To fix the issue I believe the following patch should be suitable: --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1817,7 +1817,9 @@ static int nvmx_handle_vmptrld(struct cpu_user_regs *regs)              else              {                  hvm_unmap_guest_frame(vvmcx, 1); -                vvmcx = NULL; +                vmfail(regs, VMX_INSN_VMPTRLD_INVALID_PHYADDR); + +                return X86EMUL_OKAY;              }          }          else The VMX error AFAICT does not strictly adhere to the Intel SDM, but providing the guest some indication on what went wrong is likely more sensible than silently failing. Best, Manuel --------------5mUg0o6IZ2M7iPMMkaAxDZ0X Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Dear all,

I've discovered an issue in the nested VMX implementation, where an unprivileged domain is able to force Xen to dereference a NULL pointer, resulting in a panic.

This is possible when:

  1. The malicious domain has nested HVM capabilities.
  2. The CPU is running on top of VMX and supports shadow VMCS.

To trigger the bug, the domain must first enable VMX operation for itself, execute VMXON and then finally execute VMPTRLD on a guest physical address that is backed by a non-writable p2m mapping.
In `nvmx_handle_vmptrld`, after attempting to map the nested VMCS, Xen will check whether or not this mapping is suitable for writing and if not immediately unmap the nested VMCS again and abort the setup of `nvcpu->nv_vvmcx`. However, Xen at this point erroneously continues emulation of the VMPTRLD. In particular, if VMCS shadowing is available, Xen will nonetheless attempt to link up the nested VMCS to its own VMCS in `nvmx_set_vmcs_pointer`. Importantly, Xen here attempts to dereference the presumably mapped nested VMCS (which now is merely a NULL pointer) in order to mark it as a shadow VMCS by applying the `VMCS_RID_TYPE_MASK` to its revision identifier. Following, the page fault handler will panic Xen.

I've attached an XTF reproducer that triggers the bug. To setup such a non-writable p2m mapping for the malicious VMCS, I first setup an appropriate grant table entry. I've tested it on Xen version 4.20.0.

To fix the issue I believe the following patch should be suitable:

--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -1817,7 +1817,9 @@ static int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
             else
             {
                 hvm_unmap_guest_frame(vvmcx, 1);
-                vvmcx = NULL;
+                vmfail(regs, VMX_INSN_VMPTRLD_INVALID_PHYADDR);
+
+                return X86EMUL_OKAY;
             }
         }
         else

The VMX error AFAICT does not strictly adhere to the Intel SDM, but providing the guest some indication on what went wrong is likely more sensible than silently failing.

Best,
Manuel

--------------5mUg0o6IZ2M7iPMMkaAxDZ0X-- --------------7k0v5mQ5ROhNHfbSS6tpHkwi Content-Type: application/gzip; name="poc-nested-vmx-shadow-vmcs-vmptrld-nullderef.tar.gz" Content-Disposition: attachment; filename="poc-nested-vmx-shadow-vmcs-vmptrld-nullderef.tar.gz" Content-Transfer-Encoding: base64 H4sIAAAAAAAAA+1Y/3PauBLvz/wVe34vHdMCIYSkGfry5ihxcpkJkAk0l/fyGI+xZdDVljyS IeTa/u+3KxtiWq4tfTPtdBrNYGxpv2g/uyutlEi/KphOWVCdx4uqnnqBvMNXX+MjSVUUVMUs igKmWLgbe1zU/Cfbtjq2w2aT/vdeHNSL//TaaDQOn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