From nobody Thu Oct 17 12:32:06 2024 X-Original-To: dev-commits-src-all@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 4XTnK237N9z5YxYR; Thu, 17 Oct 2024 12:32:06 +0000 (UTC) (envelope-from git@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XTnK22dBxz4dgm; Thu, 17 Oct 2024 12:32:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729168326; 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=+EB9/aTQNHnWjWnRwdInxvzp7bVAs18CXF4bwjjHz/U=; b=xnhzIjaJzRpyCAq+Ng2FNyOPVHqJAIcvVZssKe+MgNKBYDi7FEQz5cCt4BRvDT2ccHkVcq r0LnCMjc2tOe/7ZXTf9uD3Ch7IHPHbfbB3Cwx3v2vXs4FOeHIUkPc/DlO6VlyIU3M2Pxv6 p3hdUPKrJ9JCkKF98Ng7qqHNG61m/m6Do5gvoIOcqITeoaNRxDIwU497FGOLg/Uzh4VRko WqnTsfGyfesGfguoyWexDINzjaRtXCgzEsbepDk0rUz0kK0Cj+ZMwTEhwoaWIjti0RuF+H XLGT34gDNjj/DfubviUCca/14EHGnwPfhqbYZp50B/8eOAd4Zyppjy20uvbiwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729168326; 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=+EB9/aTQNHnWjWnRwdInxvzp7bVAs18CXF4bwjjHz/U=; b=LW+d5kMAPo8VoN5KBb7WXXHGflPh6RqwFUIdSt5Tdr1c1IBQ1WslTQc9KXWCupoj3X2CI3 bNgRFqt5q4PqbsgX6FayRvKW36Uw0GyvUccicykeO/YGQhsrj0qRTBwHwa4CWEQOhtmoPa LZYKdxAQFWbiAWKv4FbtjTTT2UJH8avd8fv1wfrUZyguVphxBe3KCcLyZUL6kZGd0DONiW 3fte9RkUviqzrOap6sKlAzAkI/XMUOFvjRv/hgzTeeqcY829N5gDP1BBeW0nYTKs1FxQlA GPGcasU9Jpq+GISaTZlYvkIc9xVp8E7pGVDfiBDIx6LrjVoVpYiHSoKnHUtp3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729168326; a=rsa-sha256; cv=none; b=BZWIimoho9bsEGOzshayXWCCjrvjxO2chee7iRDtq+NXjKG4plbtwjCecr7Nb8AGE68DC2 NIQqQQAlOvH1RvTVTdTbs9jhs/cPr4yXo8Y10OCllDd6uitk5n01L3kU09zNqZBJXxXlhl lMaikWOftxbTlO4qG6/olj5xdi1DYCG/LTF6ENVzkR+gQ6crgBm9Keetsxw6tMfKu5XhNw +IN6r1pN4WLGHLGXZav0ea1oWl+7TmJf4l6awE1mh6vCsxmDx8G19CjOGtB2iRSsWOe+xL qX4Q4qBew4hZxFmhwkBEy/gM8Yi1cfx6ZSSZJkpt2wFZDZO8M7p3RJEd+os7sg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 4XTnK2276yzq9R; Thu, 17 Oct 2024 12:32:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49HCW6dm024159; Thu, 17 Oct 2024 12:32:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49HCW67D024156; Thu, 17 Oct 2024 12:32:06 GMT (envelope-from git) Date: Thu, 17 Oct 2024 12:32:06 GMT Message-Id: <202410171232.49HCW67D024156@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: c17d96fe7952 - stable/14 - bhyve: avoid buffer overflow in pci_vtcon_control_send List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c17d96fe79529b2490011e7c857739f41a7c3ce6 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=c17d96fe79529b2490011e7c857739f41a7c3ce6 commit c17d96fe79529b2490011e7c857739f41a7c3ce6 Author: Pierre Pronchery AuthorDate: 2024-07-24 18:23:12 +0000 Commit: Ed Maste CommitDate: 2024-10-17 12:31:39 +0000 bhyve: avoid buffer overflow in pci_vtcon_control_send The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. Inside the function pci_vtcon_control_send, the length of the iov buffer is not validated before copy of the payload. Reported by: Synacktiv Reviewed by: markj Security: HYP-19 Sponsored by: The Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46105 (cherry picked from commit 8934002959e02bcf5e3262730c3a731af95afb15) This is a follow-up to the fix for HYP-19, addressing another condition where an overflow might still occur. (Spotted by jhb@, thanks!) Reported by: Synacktiv Reviewed by: markj Security: HYP-19 Sponsored by: Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46882 (cherry picked from commit b34a4edefb0a40ced9b17ffd640f52fe55edc1f5) --- usr.sbin/bhyve/pci_virtio_console.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c index a0bb8591811c..183dd1da934d 100644 --- a/usr.sbin/bhyve/pci_virtio_console.c +++ b/usr.sbin/bhyve/pci_virtio_console.c @@ -573,6 +573,9 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc, struct iovec iov; int n; + if (len > SIZE_T_MAX - sizeof(struct pci_vtcon_control)) + return; + vq = pci_vtcon_port_to_vq(&sc->vsc_control_port, true); if (!vq_has_descs(vq)) @@ -581,11 +584,15 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc, n = vq_getchain(vq, &iov, 1, &req); assert(n == 1); + if (iov.iov_len < sizeof(struct pci_vtcon_control) + len) + goto out; + memcpy(iov.iov_base, ctrl, sizeof(struct pci_vtcon_control)); - if (payload != NULL && len > 0) + if (len > 0) memcpy((uint8_t *)iov.iov_base + sizeof(struct pci_vtcon_control), payload, len); +out: vq_relchain(vq, req.idx, sizeof(struct pci_vtcon_control) + len); vq_endchains(vq, 1); }