From nobody Tue Oct 29 18:53:42 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 4XdKCp3yP4z5bn5l; Tue, 29 Oct 2024 18:53:42 +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 4XdKCp2xnKz45x5; Tue, 29 Oct 2024 18:53:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730228022; 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=jMuaIl3FSUl2gen8JLNe/kCHuxNBlqrgOJgx3MLLvbs=; b=K6cI4c6q7EfzWaTXrDzxcY36abzEkz4vVp9J5wnonmF/RJd3OpdLjI33lp4wirGawXTbcJ oP23TCm0T37BcifIewCK4DCOfY+9hWw9D8g//kU3v6w75LKPKrCJvepxkpXuEYCUBckjln 4iiUM1T2uI1LFiSt5TTsIpUqbtFuSfIaKOpVNeatBOCNygc0JBcskLOVccZa5T6OxpPRdq D9HHRHccoy5StTgJXA3x1Ft1N4izJ7vZxlBKnt9hsgtfeqAhto+0dnjW6FUa6zUeTxT8Zn oa5IHKt1AaDgdzQ/Bo4TjjbIQR2smL5lew8zQkl2SCRR0YG8o54l8soCQyFVRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730228022; 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=jMuaIl3FSUl2gen8JLNe/kCHuxNBlqrgOJgx3MLLvbs=; b=ey5DvZpganueF2aq+5+VZMOFNcN/lIkLEOS3b+lnPV6kM4KclPFiML7Ahu/kYV411eIP26 88qt7UadxLIUIFW+gTTaXQL7IFVmQMrmnZZfoCVKiUZ02EwbUQAI6kBf/y8f7fLGUlqoE0 e1TuTbuY0R6CVhrVTcuBqNfHDH1p4Fa5gMOGvGjN/hJqKX9lFrX0KPvHqgIuPIxPFRjFm9 JPKWPDBhz3B01AD5hUTH2G0Ow3sZ5/lgz1GYiHCcQ0iljixjY46BiFZKbs0poSZFRfkfqL GbP7EJvrjlBs4Xitmb3XtWH9mFQkAlEZd6D+UPWR3BEKQWy8L6FN0VmoyK49XA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730228022; a=rsa-sha256; cv=none; b=anFlE4hny/CaPJ3wi4f47lHM7jmIgkEv48fHsWMLTX7lXUJWKsWXdVKymnSpMOr4d7cjq9 kr8BcYziPeWc3M+pnES6p2FNZtotDIsIU2xFZ8yjl8f06BnC6GrmS6tC89o2CyDj2XV6nu XYi2zEoE0ze2/2uLinZ47GKdpWW45ILDQEKnx5VTcPZEwcAQQuXZFs5MPtw6NsttNYzetv QhSa4zbAn/K4/4PW0nZOgs9s3RoLsoYH90tD5L0Z+g91MCpQE0WYYRgl1IloHqGtEOvoaz d1/S5O1C5b78LbUJOTc9VjbRstTzt/M/SrA/T0C238tCs69bNwocnAhICj8grA== 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 4XdKCp2HdqzbYj; Tue, 29 Oct 2024 18:53:42 +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 49TIrgCb035274; Tue, 29 Oct 2024 18:53:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TIrgCZ035271; Tue, 29 Oct 2024 18:53:42 GMT (envelope-from git) Date: Tue, 29 Oct 2024 18:53:42 GMT Message-Id: <202410291853.49TIrgCZ035271@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: 9867aebc1d04 - releng/13.3 - 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.3 X-Git-Reftype: branch X-Git-Commit: 9867aebc1d042c93635134199b5d5feed2354fe9 Auto-Submitted: auto-generated The branch releng/13.3 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=9867aebc1d042c93635134199b5d5feed2354fe9 commit 9867aebc1d042c93635134199b5d5feed2354fe9 Author: Pierre Pronchery AuthorDate: 2024-07-19 17:32:27 +0000 Commit: Ed Maste CommitDate: 2024-10-29 18:53:00 +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;