From owner-freebsd-virtualization@freebsd.org Mon Sep 2 10:14:38 2019 Return-Path: Delivered-To: freebsd-virtualization@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E1974D8E0B for ; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 46MQtQ5lFWz4X9D for ; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id C4EDFD8E0A; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) Delivered-To: virtualization@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C4AD0D8E09 for ; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46MQtQ4smfz4X9C for ; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8A7D3188CE for ; Mon, 2 Sep 2019 10:14:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id x82AEcaR037125 for ; Mon, 2 Sep 2019 10:14:38 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id x82AEcpK037124 for virtualization@FreeBSD.org; Mon, 2 Sep 2019 10:14:38 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: virtualization@FreeBSD.org Subject: [Bug 240272] bhyve/pci_fbuf.c: gc_image NULL pointer dereference Date: Mon, 02 Sep 2019 10:14:38 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bhyve X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: mohdfakhrizulkifli@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: virtualization@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Sep 2019 10:14:38 -0000 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, vcpu=3D, pi=3D, baridx=3D, offset=3D, size=3D, 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, vcpu=3D, pi=3D, baridx=3D, offset=3D, size=3D, 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, addr=3D, 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, vcpuid=3D, gpa=3D, vie=3D, memread=3D, memwrite=3D, arg=3D) at /usr/src/sys/amd64/vmm/vmm_instruction_emul.c:517 #4 vmm_emulate_instruction (vm=3D, vcpuid=3D, gpa=3D, vie=3D, paging=3D, memread=3D, memwrite=3D0x224ab0 , 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) at /usr/src/usr.sbin/bhyve/mem.c:238 #6 0x00000000002243da in access_memory (ctx=3D0x80028e080, vcpu=3D2, paddr=3D3221241856, cb=3D0x224470 , arg=3D0x7fffde9f2ec8) at /usr/src/usr.sbin/bhyve/mem.c:215 #7 0x00000000002242b9 in emulate_mem (ctx=3D0x80028e080, vcpu=3D2, paddr=3D34370857472, vie=3D, paging=3D) at /usr/src/usr.sbin/bhyve/mem.c:251 #8 0x000000000021bc75 in vmexit_inst_emul (ctx=3D0x80028e080, vmexit=3D0x24= f780 , pvcpu=3D) 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 ) 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.=