From nobody Tue Oct 29 18:49:56 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 4XdK7T0s4Vz5bn7G; Tue, 29 Oct 2024 18:49:57 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XdK7S57jvz43wy; Tue, 29 Oct 2024 18:49:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730227796; 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=HQK8BwbsjUqVFQckbhuA326j74Udm/L1nReCKnOTIvM=; b=wF5go3ZiKZwqQf79jdOjYWM/HDxFb8K3SpkuVADYctShYi+BAWsXHMgxsoUyVmp/lkD7ED M/UZXV+esNMRzNhmvcnHM3iGaBPmIjsQucy1mOBhWnRuTVPGa5JR3J+FUIA83/7QyKIDhv jlGUgnyhy1IBzVVV16etWznab8fVN0s3H5hvqXNUwuimEeGCGtfhCBiLXgrF1D3FiiE+Rk pBBjLySFJG5gsLzuavW9PVqEDRSTFlt/S62agie4JoP51F2CyIi3F6Qy4fxeo2J+KyQAk+ aQjpituvn8+zeBEsEfsy7RKt4yIwQw0dW2KINOLKTiCaR/fmdwhRtRXi3EwgGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730227796; 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=HQK8BwbsjUqVFQckbhuA326j74Udm/L1nReCKnOTIvM=; b=HvPxYSCA1kwmWY2JO3xHctthrAZRYQaWlJHdxPeWuAnUl2V2MUwyGp8EsZ44hEgJ/Ai+BX LkJvs6EE3/G3wlD0oht1bwJdWwrL0yisRWIA16JRr00SFhFAVw0QCaISYzaFziKQi8gLi+ rtnjSAJfsyQpl3H5FjTmRcUezkt1bPcEQaumbH8CRsqhp8hKZvZ4PaIn01QFlhtvkkK64j syr79kML571xzfoamyMsV6z+ybewm4XVOgGwF4BHuQLkeSeU1RaW6u/Jug90Ba2D0pzGD/ MVPb69NAdtRylY5ro8i7P6z40AA5b8QVx9txK5sbn8kudrUh62thczHi7VCMIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730227796; a=rsa-sha256; cv=none; b=I2ZTZAfiTfVAdspFLW3TX1hUVooobdh5NgjEpxt0aWQMAhdEtBmqCF2Iy5AyK5pk94hdL+ 9wNUwp8qieN+ielf98wqJ5GLGHmrpki4Q+VY8wHSJv39QFuKeMPEYd6Hz3pG/BDeHIhqiM NOdnSyaAeAL0SMGV1KPITJzJNUyA9DCqOT2kwsmyk1VFiNPaLTVTLwD4QkJRTHlSn6gIPJ o/7Klqd7HFQ6thoPrUwcJRYexg9w0LjhciCUKzDrEapn5+GFlclp1oi//xCyzQmovvdURd NYPTY7cyQkblRMRFM8DPutGsr3QRgZgN65uVQ3+YvEJ93/7MSsKHCTATpYsM+Q== 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 4XdK7S4h9KzbZp; Tue, 29 Oct 2024 18:49:56 +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 49TInuFZ018761; Tue, 29 Oct 2024 18:49:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TInu1A018758; Tue, 29 Oct 2024 18:49:56 GMT (envelope-from git) Date: Tue, 29 Oct 2024 18:49:56 GMT Message-Id: <202410291849.49TInu1A018758@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: e389eb99fb63 - releng/13.4 - ctl: limit memory allocation in pci_virtio_scsi 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/releng/13.4 X-Git-Reftype: branch X-Git-Commit: e389eb99fb630627155879acab03373889848857 Auto-Submitted: auto-generated The branch releng/13.4 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=e389eb99fb630627155879acab03373889848857 commit e389eb99fb630627155879acab03373889848857 Author: Pierre Pronchery AuthorDate: 2024-07-19 17:32:27 +0000 Commit: Ed Maste CommitDate: 2024-10-29 18:49:18 +0000 ctl: limit memory allocation in pci_virtio_scsi The virtio_scsi device allows a VM guest to directly send SCSI commands (ctsio->cdb array) to the kernel driver exposed on /dev/cam/ctl (ctl.ko). All kernel commands accessible from the guest are defined by ctl_cmd_table. The command ctl_persistent_reserve_out (cdb[0]=0x5F and cbd[1]=0) allows the caller to call malloc() with an arbitrary size (uint32_t). This can be used by the guest to overload the kernel memory (DOS attack). Reported by: Synacktiv Reviewed by: asomers Security: HYP-08 Security: FreeBSD-SA-24:18.ctl Approved by: so Sponsored by: The Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46044 (cherry picked from commit 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47) (cherry picked from commit 2e7f4728fa738a7a7b6c4e4c46eb68952386efce) (cherry picked from commit 367d8c86a182813d88f728fdb2c3ef1a4679a852) --- sys/cam/ctl/ctl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index b0f34cafac80..f94ab17c8ba0 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -8319,6 +8319,18 @@ ctl_persistent_reserve_out(struct ctl_scsiio *ctsio) param_len = scsi_4btoul(cdb->length); + /* validate the parameter length */ + if (param_len != 24) { + ctl_set_invalid_field(ctsio, + /*sks_valid*/ 1, + /*command*/ 1, + /*field*/ 5, + /*bit_valid*/ 1, + /*bit*/ 0); + ctl_done((union ctl_io *)ctsio); + return (CTL_RETVAL_COMPLETE); + } + if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { ctsio->kern_data_ptr = malloc(param_len, M_CTL, M_WAITOK); ctsio->kern_data_len = param_len;