From nobody Thu Oct 17 12:34:25 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 4XTnMj3fSRz5Yxs8; Thu, 17 Oct 2024 12:34:25 +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 4XTnMj2wTrz4f08; Thu, 17 Oct 2024 12:34:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729168465; 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=BxYB8yFRYgO34BWXt6og4Gscz7PlY4IrUqyDc9bnJcg=; b=rDTgPVf4DUoeH6WA+S7CCdhwopWk3UMCnYDXow906cLaG3a/6sSupZ2NBi+lxbVmMmXz1b lfzrZD1k52R+L9SUORK0l5okcHenXBYXtvFwVJ/CNcHfGlEwjBngXgLQu2eSger+/dR0Qg 5HoTLqiyQKky+9oIb6WMpeVV9VWAMUm8USLgM3ApGi7bs8l00Ej+YsGddpVgpdFRGgRqIU 2YU8efulH5N4ORvdMrySfv9/T/xHsRiDe5Gy5TgL+cmPue3tYBEC183BGfGfxDdEi5RzmM k336Kl/bHybtEBaboZ+lI5xomScHlIEPGnhvxnlraDdCsB31leZby5jUr7iQkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729168465; 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=BxYB8yFRYgO34BWXt6og4Gscz7PlY4IrUqyDc9bnJcg=; b=u6oblt1XsTIBj9n9zliGyEOxJDPM8f9nkWBWvNpOkgjXvctWMv8HwlP0UF3eT62UYCToaA 0Y76a32uIavU/ZGMoqzHWDBeiLxKkMJHZBaRXl/3fSflbDcnLDUNHIJpPkjaZpl2ztmN0u /br7or8LhaJBfvt7HAup3+IfjBBExAfzokQYwk+ORlFkYCUUG/00f0jFdhorZKAwXc4Oup /uKcK+03bZJ9qmOYY32L8hhVEf7UpDpkWggpxNvEW6/8O/OIyQBSpzjyFMJ4yLltvajCJV xkY5ISn9Mzgq+nU2EBRfpB3N3Ktx0om7WVfZSPeUb4uPwePxMLm+T2fRFuZP0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729168465; a=rsa-sha256; cv=none; b=HG96rHd4JNSyaVt5LLqIzqvhmiQs8jw7FGJuu/kMuOCfKtWESpQGqWxgLiQW3U2QeYAvNa A1xBzpNXZYuZcVgAp6RFSCMC+h0jVGVCMu069LwfOXMI2Cmqp2Gzj2L69UvgckxNmERqZe UJ1+Ory8imKmu99IE6yJ++BKlsB7C/MpVJxcmHj5UziVaz+c84F8OhsJiNlvpzdQ9EaRQa acHPA/58laSlgVvGID2feqMye26Ly0J9pmFJpnj4ZtAqJd1wzvQ2i4CP3tl9fXC4KAxyDE N8ocw2z4jwAXziopaFVUVBc5G0Ag6nkFZHtS+DNdni/nIhapCM7b2luVVJqBMA== 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 4XTnMj2QvczqLt; Thu, 17 Oct 2024 12:34:25 +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 49HCYPJe025678; Thu, 17 Oct 2024 12:34:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49HCYPnW025675; Thu, 17 Oct 2024 12:34:25 GMT (envelope-from git) Date: Thu, 17 Oct 2024 12:34:25 GMT Message-Id: <202410171234.49HCYPnW025675@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: c4ec2918f26e - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: c4ec2918f26e0277e7243ed4fa0ac890b1ce12cd Auto-Submitted: auto-generated The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=c4ec2918f26e0277e7243ed4fa0ac890b1ce12cd commit c4ec2918f26e0277e7243ed4fa0ac890b1ce12cd Author: Pierre Pronchery AuthorDate: 2024-07-24 18:23:12 +0000 Commit: Ed Maste CommitDate: 2024-10-17 12:34:11 +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) (cherry picked from commit c17d96fe79529b2490011e7c857739f41a7c3ce6) --- 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); }