Summary: | bhyve/pci_fbuf.c: gc_image NULL pointer dereference | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Fakhri Zulkifli <mohdfakhrizulkifli> | ||||
Component: | bhyve | Assignee: | freebsd-virtualization (Nobody) <virtualization> | ||||
Status: | New --- | ||||||
Severity: | Affects Some People | Keywords: | patch | ||||
Priority: | --- | ||||||
Version: | CURRENT | ||||||
Hardware: | Any | ||||||
OS: | Any | ||||||
Attachments: |
|
Created attachment 207095 [details] pci_fbuf.patch The sc->gc_image at line 166 and line 172 can be NULL. Dereference it can cause 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 == 0 && 167: sc->memregs.height == 0) { 168: DPRINTF(DEBUG_INFO, ("switching to VGA mode\r\n")); 169: sc->gc_image->vgamode = 1; 170: sc->gc_width = 0; 171: sc->gc_height = 0; 172: } else if (sc->gc_image->vgamode && sc->memregs.width != 0 && 173: sc->memregs.height != 0) { 174: DPRINTF(DEBUG_INFO, ("switching to VESA mode\r\n")); 175: sc->gc_image->vgamode = 0; 176: } 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=<optimized out>, vcpu=<optimized out>, pi=<optimized out>, baridx=<optimized out>, offset=<optimized out>, size=<optimized out>, value=1953719668) at /usr/src/usr.sbin/bhyve/pci_fbuf.c:166 166 if (!sc->gc_image->vgamode && sc->memregs.width == 0 && (gdb) p sc->gc_image $1 = (struct bhyvegc_image *) 0x0 (gdb) bt #0 0x0000000000231802 in pci_fbuf_write (ctx=<optimized out>, vcpu=<optimized out>, pi=<optimized out>, baridx=<optimized out>, offset=<optimized out>, size=<optimized out>, value=1953719668) at /usr/src/usr.sbin/bhyve/pci_fbuf.c:166 #1 0x0000000000230522 in pci_emul_mem_handler (ctx=0x80028e080, vcpu=2, dir=<optimized out>, addr=<optimized out>, size=4, val=0x7fffde9f2d40, arg1=0x800a9aa00, arg2=0) at /usr/src/usr.sbin/bhyve/pci_emul.c:415 #2 0x0000000000224ae4 in mem_write (ctx=0x80028e080, vcpu=2, gpa=3, wval=1953719668, size=0, arg=0x0) at /usr/src/usr.sbin/bhyve/mem.c:162 #3 0x00000000002486ae in emulate_mov (vm=<optimized out>, vcpuid=<optimized out>, gpa=<optimized out>, vie=<optimized out>, memread=<optimized out>, memwrite=<optimized out>, arg=<optimized out>) at /usr/src/sys/amd64/vmm/vmm_instruction_emul.c:517 #4 vmm_emulate_instruction (vm=<optimized out>, vcpuid=<optimized out>, gpa=<optimized out>, vie=<optimized out>, paging=<optimized out>, memread=<optimized out>, memwrite=0x224ab0 <mem_write>, memarg=0x800aad100) at /usr/src/sys/amd64/vmm/vmm_instruction_emul.c:1510 #5 0x000000000022448f in emulate_mem_cb (ctx=0x80028e080, vcpu=2, paddr=34370857472, mr=0x0, arg=<optimized out>) at /usr/src/usr.sbin/bhyve/mem.c:238 #6 0x00000000002243da in access_memory (ctx=0x80028e080, vcpu=2, paddr=3221241856, cb=0x224470 <emulate_mem_cb>, arg=0x7fffde9f2ec8) at /usr/src/usr.sbin/bhyve/mem.c:215 #7 0x00000000002242b9 in emulate_mem (ctx=0x80028e080, vcpu=2, paddr=34370857472, vie=<optimized out>, paging=<optimized out>) at /usr/src/usr.sbin/bhyve/mem.c:251 #8 0x000000000021bc75 in vmexit_inst_emul (ctx=0x80028e080, vmexit=0x24f780 <vmexit+272>, pvcpu=<optimized out>) at /usr/src/usr.sbin/bhyve/bhyverun.c:630 #9 0x000000000021b6da in vm_loop (ctx=0x80028e080, vcpu=2, startrip=<optimized out>) at /usr/src/usr.sbin/bhyve/bhyverun.c:748 #10 0x000000000021a969 in fbsdrun_start_thread (param=0x24e050 <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