Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Sep 2019 10:14:38 +0000
From:      bugzilla-noreply@freebsd.org
To:        virtualization@FreeBSD.org
Subject:   [Bug 240272] bhyve/pci_fbuf.c: gc_image NULL pointer dereference
Message-ID:  <bug-240272-27103@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D240272

            Bug ID: 240272
           Summary: bhyve/pci_fbuf.c: gc_image NULL pointer dereference
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bhyve
          Assignee: virtualization@FreeBSD.org
          Reporter: mohdfakhrizulkifli@gmail.com

Created attachment 207095
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D207095&action=
=3Dedit
pci_fbuf.patch

The sc->gc_image at line 166 and line 172 can be NULL. Dereference it can c=
ause
a segmentation fault. This is unlikely to happen without root privilege as =
the
driver must first be loaded in order to interact with the pci_fbuf. However,
the checking for NULL should be handled within the pci_fbuf itself and not
relying on the driver loaded.

File: pci_fbuf.c
166:     if (!sc->gc_image->vgamode && sc->memregs.width =3D=3D 0 &&
167:         sc->memregs.height =3D=3D 0) {
168:         DPRINTF(DEBUG_INFO, ("switching to VGA mode\r\n"));
169:         sc->gc_image->vgamode =3D 1;
170:         sc->gc_width =3D 0;
171:         sc->gc_height =3D 0;
172:     } else if (sc->gc_image->vgamode && sc->memregs.width !=3D 0 &&
173:         sc->memregs.height !=3D 0) {
174:         DPRINTF(DEBUG_INFO, ("switching to VESA mode\r\n"));
175:         sc->gc_image->vgamode =3D 0;
176:     }=20

Proof-of-Crash:
Thread 13 "vcpu 2" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 100571 of process 4094]
0x0000000000231802 in pci_fbuf_write (ctx=3D<optimized out>, vcpu=3D<optimi=
zed
out>, pi=3D<optimized out>, baridx=3D<optimized out>, offset=3D<optimized o=
ut>,
size=3D<optimized out>,
 value=3D1953719668) at /usr/src/usr.sbin/bhyve/pci_fbuf.c:166
166     if (!sc->gc_image->vgamode && sc->memregs.width =3D=3D 0 &&
(gdb) p sc->gc_image
$1 =3D (struct bhyvegc_image *) 0x0
(gdb) bt
#0 0x0000000000231802 in pci_fbuf_write (ctx=3D<optimized out>, vcpu=3D<opt=
imized
out>, pi=3D<optimized out>, baridx=3D<optimized out>, offset=3D<optimized o=
ut>,
size=3D<optimized out>,
 value=3D1953719668) at /usr/src/usr.sbin/bhyve/pci_fbuf.c:166
#1 0x0000000000230522 in pci_emul_mem_handler (ctx=3D0x80028e080, vcpu=3D2,
dir=3D<optimized out>, addr=3D<optimized out>, size=3D4, val=3D0x7fffde9f2d=
40,
arg1=3D0x800a9aa00, arg2=3D0)
 at /usr/src/usr.sbin/bhyve/pci_emul.c:415
#2 0x0000000000224ae4 in mem_write (ctx=3D0x80028e080, vcpu=3D2, gpa=3D3,
wval=3D1953719668, size=3D0, arg=3D0x0) at /usr/src/usr.sbin/bhyve/mem.c:162
#3 0x00000000002486ae in emulate_mov (vm=3D<optimized out>, vcpuid=3D<optim=
ized
out>, gpa=3D<optimized out>, vie=3D<optimized out>, memread=3D<optimized ou=
t>,
 memwrite=3D<optimized out>, arg=3D<optimized out>) at
/usr/src/sys/amd64/vmm/vmm_instruction_emul.c:517
#4 vmm_emulate_instruction (vm=3D<optimized out>, vcpuid=3D<optimized out>,
gpa=3D<optimized out>, vie=3D<optimized out>, paging=3D<optimized out>,
memread=3D<optimized out>,
 memwrite=3D0x224ab0 <mem_write>, memarg=3D0x800aad100) at
/usr/src/sys/amd64/vmm/vmm_instruction_emul.c:1510
#5 0x000000000022448f in emulate_mem_cb (ctx=3D0x80028e080, vcpu=3D2,
paddr=3D34370857472, mr=3D0x0, arg=3D<optimized out>) at
/usr/src/usr.sbin/bhyve/mem.c:238
#6 0x00000000002243da in access_memory (ctx=3D0x80028e080, vcpu=3D2,
paddr=3D3221241856, cb=3D0x224470 <emulate_mem_cb>, arg=3D0x7fffde9f2ec8) at
/usr/src/usr.sbin/bhyve/mem.c:215
#7 0x00000000002242b9 in emulate_mem (ctx=3D0x80028e080, vcpu=3D2,
paddr=3D34370857472, vie=3D<optimized out>, paging=3D<optimized out>) at
/usr/src/usr.sbin/bhyve/mem.c:251
#8 0x000000000021bc75 in vmexit_inst_emul (ctx=3D0x80028e080, vmexit=3D0x24=
f780
<vmexit+272>, pvcpu=3D<optimized out>) at /usr/src/usr.sbin/bhyve/bhyverun.=
c:630
#9 0x000000000021b6da in vm_loop (ctx=3D0x80028e080, vcpu=3D2, startrip=3D<=
optimized
out>) at /usr/src/usr.sbin/bhyve/bhyverun.c:748
#10 0x000000000021a969 in fbsdrun_start_thread (param=3D0x24e050
<mt_vmm_info+48>) at /usr/src/usr.sbin/bhyve/bhyverun.c:353
#11 0x000000080061b776 in ?? () from /lib/libthr.so.3
#12 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffde9f3000

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-240272-27103>