NetBSD Problem Report #60545

From www@netbsd.org  Thu Aug  6 01:23:30 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "YR2" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 23FED1A9249
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  6 Aug 2026 01:23:30 +0000 (UTC)
Message-Id: <20260806012329.2E1891A924A@mollari.NetBSD.org>
Date: Thu,  6 Aug 2026 01:23:29 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: nvmm_x86_vmx: stale exit reason on launch/resume failure
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60545
>Category:       kern
>Synopsis:       nvmm_x86_vmx: stale exit reason on launch/resume failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 06 01:25:00 +0000 2026
>Closed-Date:    
>Last-Modified:  Sat Aug 08 15:03:10 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The NmiBSD Virtualization, Inc.
>Environment:
>Description:

	If vmx_vmresume or vmx_vmlaunch fails, VMCS_EXIT_REASON is
	invalid (left over from the last successful VMRESUME or
	VMLAUNCH, probably), and should not be used:

   2450 		if (launched) {
   2451 			ret = vmx_vmresume(cpudata->gprs);
   2452 		} else {
   2453 			ret = vmx_vmlaunch(cpudata->gprs);
   2454 		}
   2455 		cpudata->gcr2 = rcr2();
   2456 		vmx_htlb_flush_ack(cpudata, machgen);
   2457 		exitcode = vmx_vmread(VMCS_EXIT_REASON);
   2458 		exitcode &= __BITS(15,0);
   2459 		if (exitcode == VMCS_EXITCODE_EXC_NMI) {
   2460 			/* handle nmi before vmx_sti() */
   2461 			vmx_exit_exc_nmi(mach, vcpu, exit);
   2462 		}
   2463 		vmx_sti();
   2464 		vmx_vcpu_guest_fpu_leave(vcpu);
   2465 
   2466 		if (__predict_false(ret != 0)) {
   2467 			vmx_exit_invalid(exit, -1);
   2468 			break;
   2469 		}

https://nxr.netbsd.org/xref/src/sys/dev/nvmm/x86/nvmm_x86_vmx.c?r=1.96#2450

	Reported by maxv.

>How-To-Repeat:

	code inspection

>Fix:

	Surround the vmx_vmread(VMCS_EXIT_REASON) and use of its result
	in:

	if (__predict_true(ret == 0)) {
        	...
	}

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 08 Aug 2026 15:03:10 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-11 (also pullup-10 if
https://mail-index.netbsd.org/source-changes/2026/03/22/msg161131.html
is ever pulled up; no PR associated with it)

Tagged the commit message with the wrong pattern, here's the fix:


Module Name:    src
Committed By:   riastradh
Date:           Sat Aug  8 12:47:47 UTC 2026

Modified Files:
        src/sys/dev/nvmm/x86: nvmm_x86_vmx.c

Log Message:
nvmm(4) vmx: Don't read VMCS_EXIT_REASON if vmlaunch/vmresume failed.

It is not valid in that case; we might end up operating on the
_previous_ successful vmlaunch/vmresume's now-stale exit reason.

kern/60545: nvmm_x86_vmx: stale exit reason on launch/resume failure


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.