From nobody Fri May 27 16:43:24 2022 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 09FC01B5454C for ; Fri, 27 May 2022 16:43:25 +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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L8rGN4rZsz4R2m for ; Fri, 27 May 2022 16:43:24 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8647C26058 for ; Fri, 27 May 2022 16:43:24 +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 24RGhOr2019286 for ; Fri, 27 May 2022 16:43:24 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 24RGhOh8019285 for virtualization@FreeBSD.org; Fri, 27 May 2022 16:43:24 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 264294] guest can trick bhyve xhci into reading through a guest-controlled pointer Date: Fri, 27 May 2022 16:43:24 +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: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: rtm@lcs.mit.edu 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 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 List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653669804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dTw0oEAEEQxv3G/ZnH695lePEKvzxCrRg3ZDr9o6Ylw=; b=aFTbOb4UgihnnByGB1P/j1NzfJKMHFQlQKs0uB2u+Hpn1e3mtx3FtDMYNJokPVZb0BTTQA 4K1ffj6iQ8sn17VofdaOm23UmrZziprb+q8WLQeHAmza6J36xBECDAz+bskuI8QJAt1xk5 sEhLmsUQKpQOmnFOMgcfUZeNGtk5RgnNdiKoHuUm/R9LWWKRI+euUg/qfM+vbavVSXz1qv ry4Gd8kuzMg6E9XACb1H1k207Cw7/sAgVECnpPn3GUkp8n+od3Va3PdXusTqa2nIdkLEHA kFTFZzKG9Zj8RL+vX+nmeA+n/1xLN2J9b6Vm8jd2DwuOg5txKAG888aZh51KpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653669804; a=rsa-sha256; cv=none; b=qmTNh38Uzu7GzfKRIpsY5YLIpbvYpOhkGLVKDp7iYrFF07Zyu/JB9deOkMG2jm3ufvMEdK ikVn/WN64VXLh7nFSK9er1597E5oixGU1SjbeuSZwl0ROvNqk01ASEf1mSRGG97Fmkyayt z4J9ctPGbGGubilLINZlRXwqizv3kL0mD+lg8qeuE4mRmAi+0suVtjeOgBzs68vwinCZp4 pnH6oS49yYjS5fOjpQjXBv0SlqSmJ6p6yWIbvV0UWT3YDvi0yVnlQ5+yvRsTY0akjLdmqU 1N+1qYIcy9DzvmxOdhtzPL206ompWK/GEgS+VppcVKnv/r2SrEgSXFDf+Nyjow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D264294 Bug ID: 264294 Summary: guest can trick bhyve xhci into reading through a guest-controlled pointer Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bhyve Assignee: virtualization@FreeBSD.org Reporter: rtm@lcs.mit.edu The second union in Bhyve's struct pci_xhci_dev_ep causes these two fields to occupy the same memory: #define ep_ringaddr _ep_trb_rings._epu_trb.ringaddr #define ep_sctx_trbs _ep_trb_rings._epu_sctx_trbs Which of the two bhyve's pci_xhci.c uses depends on whether the guest configures the number of streams to be non-zero. Bhyve interprets one as a guest address that must be checked and mapped before each use, and the other as a host address that can be used directly with no checking. In the former case, the guest provides the value; in the latter, Bhyve. The number of streams is determined by bits in ep_ctx->dwEpCtx0, which lives in guest memory. So it's possible for the guest to tell byhve's xhci to configure an endpoint with the number of streams set to zero, which causes pci_xhci_init_ep() to set devep->ep_ringaddr to a guest-provided value XYZ (assumed to be an address in guest memory, but can be anything the guest wants). Later, the guest can change ep_ctx->dwEpCtx0 to indicate multiple streams, and write to an xhci doorbell register, causing Byhyve's pci_xhci_device_doorbell() to execute: sctx_tr =3D &devep->ep_sctx_trbs[streamid]; ringaddr =3D sctx_tr->ringaddr; which interprets devep->ep_sctx_trbs as a *host* pointer. But those bits contain the guest-provided value XYZ previously written there by pci_xhci_init_ep(). So "sctx_tr->ringaddr" will dereference a pointer provided by the guest, without any checks. I have a modified FreeBSD guest that makes Bhyve crash due to this bug. --=20 You are receiving this mail because: You are the assignee for the bug.=