From nobody Tue Oct 29 18:45:37 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 4XdK2V2L68z5bmhP; Tue, 29 Oct 2024 18:45:38 +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 4XdK2V06Yhz41Hh; Tue, 29 Oct 2024 18:45:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730227538; 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=VhuT8tzMLw5yz6Sg9g+mUd61lvBmE4nX1PY+4NRzpjE=; b=N0YO1+aCGA3ykfdupTtRjCnS7RA8A5BFY3P+AlFdqIGfbwdTjrda6z4KriT9gMQmYQ/Hsz 1mL8YHLvDr7GNY0n8mn63emqyIc8lE6NjjkQ85G6ULKSeCg8GxuCSwGtztGrswkN2PLXUK ZWk2sR78Glou1nH516ePLvgFkxfC/+weOP33GS6F8b3/7E6n+CQS0z+11N8suvDejdNydA 93q06zRMDiHkCeiH7ETHlyLfRW5vDEA0uvBjW0KFVRARQtGY63Q0dyIRsWrh3R0TMDFjCt igDWKfUoZzQzPQ4g7NgaHSIAUsHPhIGUQ0rVMC1EzNuYmfwUNUBaWMNlWhxklw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730227538; 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=VhuT8tzMLw5yz6Sg9g+mUd61lvBmE4nX1PY+4NRzpjE=; b=Qnf+V1cmdkb8pZpXieFx2lMth9Lw99JaTR2IY/0mzUHs8P22wAJNB7I71AAPnSpXU4b3fQ XUbH9aTHw3c1uXqwExgIowU02NGhhmXJR31Ka26WaxCFPNmaZeC7/zEH9YJviig3zbkJut Rp6h9glKMRLzk/KsU3pB58vBtVlXQK0Dx44dCGE/uRwENIy9ebA4aTgmKwtfQYwbVn5OEP 2wZSghASKlSfAEI0VJ8UGdK72qpS2cuwb/QRL8PmpHhMm6jYUUcVIG4wFDGiEp7mGKjj2b uGKZ0DdBIGWEg5zrPJgn17qa03XLkGnEB+itNzd9WbIYegrnWOMciN0j2o/pag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730227538; a=rsa-sha256; cv=none; b=Qx5vs7v3AoVA1/JzegBDsos7bAhEvXqCLP0ntar+hSmX31LQfG7t8gusgu9oaXCaGKsmpa bdduOdT1RhjR2gGiAIv/4zQG3Is08Xtnm6nmlNdgnGIvQBfxYxxDfCcFGtnYeHs6BkGf2E w+4h9fJZTI1ZaNKSI6D8450zzoUBPYdn2YMEzlU7c4w25eeymjo2yuklClgO++uGwoT9Zf NfXxn3ZQquW5mspbZIutoJFbkZoM+6dxIRFdcTCyjZOJWIpyTfJ96O2RIbJpyGZkaquDEJ lpoxzoLnH/qQoUIg8cgUiBvHjYrUn8ZRFEs3f4Y2vtxt66vXVzWmt6BMIuXXSQ== 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 4XdK2T6rL2zbXc; Tue, 29 Oct 2024 18:45:37 +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 49TIjbH4017118; Tue, 29 Oct 2024 18:45:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TIjbE2017115; Tue, 29 Oct 2024 18:45:37 GMT (envelope-from git) Date: Tue, 29 Oct 2024 18:45:37 GMT Message-Id: <202410291845.49TIjbE2017115@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: a8df23541444 - releng/14.1 - 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/14.1 X-Git-Reftype: branch X-Git-Commit: a8df23541444f6630a572bcce90ba26327ba25df Auto-Submitted: auto-generated The branch releng/14.1 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=a8df23541444f6630a572bcce90ba26327ba25df commit a8df23541444f6630a572bcce90ba26327ba25df Author: Pierre Pronchery AuthorDate: 2024-07-19 17:32:27 +0000 Commit: Ed Maste CommitDate: 2024-10-29 18:44:17 +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) --- 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 0e0d79d15d8f..420d9088c27b 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -8320,6 +8320,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;