From nobody Fri Oct 04 00:22:40 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 4XKTlP3JYRz5XZ9w; Fri, 04 Oct 2024 00:22:41 +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 4XKTlP17Stz4WPq; Fri, 4 Oct 2024 00:22:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728001361; 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=4OY8KoQ8EYvC9++34TupyaXk1cRu2qokLZ3KWrvAkrM=; b=h2fkbFiN5A4hWJbstY1t+cFvvdBgMcIRaFY3pTtwS40/Mkcfwz19CmDizuo2LH81hhZDEx 8ckAv5Ua3Hcat+6IhPp1iLHQ+M2YsJX/9UyKK3TiJmp4he/vFlMGOErDvshUUXfXh3mSKw hOmmhR1e3iuK7ip7TLjsMRemVRLC2ir6wqGas+eQdaaxdDkv7QBK546Co2z2p6dJYfb7aK o/hv1rfWc+hJVK45QEYCZNVdMt2KYksqx3dXt08XmYHA2llvhQ/anPnx0MJLVpi51TCKOh uTItUpZYiQomw6nm8cb/35qM+4LYrdtu8WCecPuodKVXAwzQUcaxTWIYoFIsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728001361; 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=4OY8KoQ8EYvC9++34TupyaXk1cRu2qokLZ3KWrvAkrM=; b=Q7UvW1Q4S7nsSDuLQthgqvGTfg/yX6PfHG69ZkQgWP9y6FoJsUjSOpzvlRsbUKVRsPZEAm RFsb/nwNAR1PNCKJsdcQSxQDATJbsu1wSWboJ5HaJ4OXP9BDRCzz27/LzkfBgy3YGP31Qc ViFmhDcMxKbJ60AekGEn8mOSKsdiK5JdkSnVlqHaxBzehMCddSKrQc7HENScL6XEPdnbxz xah5uVEylRMwGg108lVayk52ezYkWIXl481tbirWtrpzfnYoePxqTZdoS1a+4yWLxdp173 gCTvcabV5qN+jtH0PrtSO6sxdf0Xgz5ojIj4EOuYYa/VABuNRVizyEoGG5uxrg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728001361; a=rsa-sha256; cv=none; b=AHRNNrGCcukMHqg4v2OUua8qkH2rCOV0UzYVjIE0V+5LYFh+kw5QtCaHO4eshIFJjT0pHo iqo5Rnh5li16glnrxx+oGvPKKYEUyBycY7uY54VapjclhB5LYXB+MJjwgBufeLjCxLp3GB stm7zNR8B/Cf0HsNEWOXVf4R/pkUDBfwWnllBj2kV50R1aWAmVyStyH0IUcgvsxWiJ+eeX vPEFHzsAJaDDVq7OAKwR3QemZCJ38jTKFtuJsu5tY7XGdPCGTUfBsdcptdurnkCn6vOAKX PD9VRhclmDaJ2hWrurHtvf9NA6tLHT1xG26iyiDCcmDPpuJ4hs/ICWkbUYLNnQ== 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 4XKTlP0kdCz1BL9; Fri, 4 Oct 2024 00:22:41 +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 4940Mfpo073209; Fri, 4 Oct 2024 00:22:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4940MejF073206; Fri, 4 Oct 2024 00:22:40 GMT (envelope-from git) Date: Fri, 4 Oct 2024 00:22:40 GMT Message-Id: <202410040022.4940MejF073206@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 64b0f52be2c9 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=64b0f52be2c9d7bcecebfeef393f8ec56cb85f47 commit 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47 Author: Pierre Pronchery AuthorDate: 2024-07-19 17:32:27 +0000 Commit: Ed Maste CommitDate: 2024-10-04 00:22:34 +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 Sponsored by: The Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46044 --- 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 b1367cd79fab..da147f0ec914 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -8269,6 +8269,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;