From nobody Fri Nov 11 01:24:36 2022 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 4N7gwh4cd4z4f0br; Fri, 11 Nov 2022 01:24:36 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N7gwh3YZ9z3H0c; Fri, 11 Nov 2022 01:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668129876; 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=uHUZWnAkyBaXgGbY3gCs+E790Ecevi4KliMwOUDrM7A=; b=jWA01gIOErMYwIgXo0npL/HwvHXKGNmGafjud9ps1Q3qzAzX/HtlW4Dwhp66zWRmty6zxr ycI1BZEbSCCxI4FrFTIj3dnl51Z/1vQ8U774WBKhfXG/Zx6ZyU0i3KGek1y4fJ8QU/HhRZ kr7ba2XrupKH7NKSarVB8hRaNumf5Lustw4YiZojzvNIcDovDUdJDjVsXgdGRcBrymvekq TYper3gC1W/jbxx7BnbfnUhdfBjPu354pG6zMP6vZ+0nqKsyKF8hllPkeHGmnHdYL7PPa+ QVtBobq0FEajvN6wBFvO6TgGI8bIKJQXb/EfCohsLqEhR7bCPk1qW/gf+WWPmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668129876; 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=uHUZWnAkyBaXgGbY3gCs+E790Ecevi4KliMwOUDrM7A=; b=m+o6GR8TqOQGPbEENOPBS6pPjF2Vy+6zQvZpvI+oBPpecqkIc29XtFoko34qkTmNrgFZlE 8Tx1peE/+4RQhdfJyCBqXwem7cfzNtUXY1p6apmF+fRVwLRtsSBXm+vuvechdPFp0Q0K/Q 3uXO0SdegpoeiXj0DGq1efCLnHxcdqLZycQB1ZNKABtIqsxZXDVQMy0lwCvk9TjgzRNC4H wlNFbblXbZ6lu1SHbUsMnG6ON3ixz2DxMyk6DZG2fUhbYvvZPEsnEyd83dwENJjhIoTIOf fmRh1Trz1cK1sojhj5s6C0f1c+txu/HXLOt/rgFKpRq0lNy/pLBCOF7TKidTRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668129876; a=rsa-sha256; cv=none; b=tdYlvFihVH0ltIdtg0lXkV/oDNYRU29fRwVpHWKr3VFGndw+75cWwQsCdDIXfQNFtXIIBf mzbNLPphV6Jt9TXXASGfisV1wuWsMxt79dq7QY3sXBPooJREYYXM7FIr/rRvaLz9uyCnYH F5wHM88hdhQlI1u1LMpTJcMkaz/3yPuREYdhxsP4gz+cw2Eff/tNm+Kq6tkL5MW3JaN01j lQWK3jwmVcJOUnBNdWVfOH3a9o2czflCwdMwsKa+UNZyPhNPQ/BpQZbwgFwj2TQuwHz1K3 Qk4OrCV80BBWXlAMwO4QPm/iSEvmGBLpzN1dv2AkG8Ido55Edbp5viyZFHkmzw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4N7gwh2ZqPzNYv; Fri, 11 Nov 2022 01:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AB1Oan4027397; Fri, 11 Nov 2022 01:24:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AB1Oaa0027396; Fri, 11 Nov 2022 01:24:36 GMT (envelope-from git) Date: Fri, 11 Nov 2022 01:24:36 GMT Message-Id: <202211110124.2AB1Oaa0027396@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 1282bf40f7b9 - stable/12 - bhyve virtio-scsi: Avoid out of bounds accesses to guest requests. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 1282bf40f7b90af1fa90223125e10c8e4edb5c39 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=1282bf40f7b90af1fa90223125e10c8e4edb5c39 commit 1282bf40f7b90af1fa90223125e10c8e4edb5c39 Author: John Baldwin AuthorDate: 2022-08-29 22:36:11 +0000 Commit: John Baldwin CommitDate: 2022-11-11 01:13:19 +0000 bhyve virtio-scsi: Avoid out of bounds accesses to guest requests. - Ignore I/O requests with insufficiently sized input or output buffers (those not containing compete request headers). - Ignore control requests with improperly sized buffers. - While here, explicitly zero the output header of an I/O request to avoid leaking malloc garbage from the host if the header is not fully populated. PR: 264521 Reported by: Robert Morris Reviewed by: mav, emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36271 (cherry picked from commit bb31aee26bd13307d97c5d5bf2b10bf05bdc18fd) --- usr.sbin/bhyve/pci_virtio_scsi.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c index 542098631f90..0bce6ef66613 100644 --- a/usr.sbin/bhyve/pci_virtio_scsi.c +++ b/usr.sbin/bhyve/pci_virtio_scsi.c @@ -363,14 +363,27 @@ pci_vtscsi_control_handle(struct pci_vtscsi_softc *sc, void *buf, struct pci_vtscsi_ctrl_an *an; uint32_t type; + if (bufsize < sizeof(uint32_t)) { + WPRINTF("ignoring truncated control request"); + return (0); + } + type = *(uint32_t *)buf; if (type == VIRTIO_SCSI_T_TMF) { + if (bufsize != sizeof(*tmf)) { + WPRINTF("ignoring tmf request with size %zu", bufsize); + return (0); + } tmf = (struct pci_vtscsi_ctrl_tmf *)buf; return (pci_vtscsi_tmf_handle(sc, tmf)); } if (type == VIRTIO_SCSI_T_AN_QUERY) { + if (bufsize != sizeof(*an)) { + WPRINTF("ignoring AN request with size %zu", bufsize); + return (0); + } an = (struct pci_vtscsi_ctrl_an *)buf; return (pci_vtscsi_an_handle(sc, an)); } @@ -467,6 +480,15 @@ pci_vtscsi_request_handle(struct pci_vtscsi_queue *q, struct iovec *iov_in, uint32_t ext_data_len = 0, ext_sg_entries = 0; int err; + if (count_iov(iov_out, niov_out) < VTSCSI_OUT_HEADER_LEN(sc)) { + WPRINTF("ignoring request with insufficient output"); + return (0); + } + if (count_iov(iov_in, niov_in) < VTSCSI_IN_HEADER_LEN(sc)) { + WPRINTF("ignoring request with incomplete header"); + return (0); + } + seek_iov(iov_in, niov_in, data_iov_in, &data_niov_in, VTSCSI_IN_HEADER_LEN(sc)); seek_iov(iov_out, niov_out, data_iov_out, &data_niov_out, @@ -476,7 +498,7 @@ pci_vtscsi_request_handle(struct pci_vtscsi_queue *q, struct iovec *iov_in, truncate_iov(iov_out, &niov_out, VTSCSI_OUT_HEADER_LEN(sc)); iov_to_buf(iov_in, niov_in, (void **)&cmd_rd); - cmd_wr = malloc(VTSCSI_OUT_HEADER_LEN(sc)); + cmd_wr = calloc(1, VTSCSI_OUT_HEADER_LEN(sc)); io = ctl_scsi_alloc_io(sc->vss_iid); ctl_scsi_zero_io(io);