[Bug 300847] bhyve: AHCI CLB change leaves stale cmd_lst and NULL dereference

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 17 Nov 2026 16:10:00 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300847

            Bug ID: 300847
           Summary: bhyve: AHCI CLB change leaves stale cmd_lst and NULL
                    dereference
           Product: Base System
           Version: 15.1-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bhyve
          Assignee: virtualization@FreeBSD.org
          Reporter: 1350430676@qq.com

Created attachment 277400
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277400&action=edit
Reproduction bundle: PoC source, test script, runtime logs, crash output, and
SHA-256 manifest.

Environment:
- FreeBSD 15.1-RELEASE-p3 with snapshot-enabled bhyve/bhyvectl.
- Source releng/15.1 commit 88e7371d9.
- Device: AHCI at 0:1:0.

While the port is running, changing PxCLB updates the guest-visible base but
does not remap or invalidate cmd_lst. The snapshot saves cmd_lst, clb, and clbu
independently. After restore, rewriting PxCMD=ST remaps the poisoned CLB,
stores NULL, and PxCI enters ahci_handle_port(), which reads through cmd_lst.

Steps to reproduce:
1. Establish a valid CLB and command header.
2. Change only PxCLB to 0x80000000.
3. Clear MEMEN, save normally, and restore the unmodified snapshot.
4. Re-enable MEMEN, rewrite PxCMD=ST, and set PxCI=1.

Expected: reject the unmapped CLB or stop/remap the port safely.
Actual: SIGSEGV at NULL+8 in ahci_handle_port, bhyve exit 139.

Current status: the same control flow is present in main c8e73127e and
releng/15.1 95719d8a8 (15.1-RELEASE-p6).

Impact: denial of service and loss of the VM. The consuming code is ordinary
runtime code; restore is not claimed as the only trigger.

Suggested fix: reject an unmapped CLB, remap or stop the port on CLB writes,
reconcile cmd_lst and rfis at restore, and check the cached pointer before
command processing.

-- 
You are receiving this mail because:
You are the assignee for the bug.