From nobody Fri Oct 11 15:53:46 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 4XQB4V4dsKz5Z40V; Fri, 11 Oct 2024 15:53:46 +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 4XQB4V48xPz4wJ1; Fri, 11 Oct 2024 15:53:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728662026; 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=bsAzMNTf+m4ZlbZsIyZFEI2apPVgmj5PlUb3sXT0VA8=; b=rBph1Z0+VraiMcBNHh4lYfBYRBWMQm+iMtItNbx5oO/fiJLvMHK6EJZR+LOIo1waYJgLfT 8Dim8PH183cSBaLpw47PmJUJHFB90dx9AdKG+TNl0QB/ZqLm6BaQ30icjGcQUMz5rMfgG2 MOleHozK3ewjZ38JRv0aAc1GIWzCBuSfrk8qF+irdlY4sDt2OKcMcrv4wPJY9Y+cLwux2/ PB0tZ3J1A0AVN2K2P3n01RWKZdLXMSJJzdMg5PTD0I1bkncYaTsPRPWfTaEieA0sZe8OAw nIgBRVJ9XGakHmL6MH6TTzb4MPGEl9iQigceH49lNibCekb1YZqjEUu5EwrBvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728662026; 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=bsAzMNTf+m4ZlbZsIyZFEI2apPVgmj5PlUb3sXT0VA8=; b=o4uOd5kojumSvzR5LmlqCYcr9ItWXVi0xImQT8beq3FebrWfGXvazxwwxnXlayaqoVGwH3 IOlw4rFbpcsKnXQ8NZG/SnSZun+W4i2KNl7GAUi1rx0+iOZ2PIuqeZ7sMXY4fPLb+0nVmK bI53NSodB7r91JD3MuaKQRNAEuu4RVVRNkYeac0uCwhCB5xRAGEYt2HX7M3I+kWh0Ps/4D 15uu89mjiRfWY2IvzGD4E7fG0Ux7qeWqrOOPAXqlfSGQg5JMl/349n2SewS+qItolFM9lM g5G/bNu2Bw55O3MDwwpOkV7vA3+mKQJ/0bWGc8h+SOHVegRlK3TpMffMD+XEdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728662026; a=rsa-sha256; cv=none; b=DURGw7X6dNczJJOQmiOYVy/9zwP6Y00feUPnoGCg7nopGc+FIBgdaFHjGa2ooJkvkdp55H m+tYGrxzS4LomWS5K19lHn3QGW/4ES/Xx9rBjFXFsQSX2825EUp/oViooIUKateB9M7E8D 5tbUyvAtxQcgp9tv63oScS+9Q4oUE73rB6m2RGNYh9tUVGra1kLMDl7WDcJHvmSEmmpDFj kXyMvs4upvhG+AInyWoBuqwNtUBeEazJgRGdKOmD8aN9SvghcWTQ5oTiXhwH2iRqaoqnlf s87MeW7IFCE0zw0KdrmW73GKBUCR3glvhKcigOSjLviFhGM26RYbIG8MkuPhnQ== 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 4XQB4V3lMbznrb; Fri, 11 Oct 2024 15:53:46 +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 49BFrk8V087827; Fri, 11 Oct 2024 15:53:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49BFrkgf087824; Fri, 11 Oct 2024 15:53:46 GMT (envelope-from git) Date: Fri, 11 Oct 2024 15:53:46 GMT Message-Id: <202410111553.49BFrkgf087824@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: 2e7f4728fa73 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 2e7f4728fa738a7a7b6c4e4c46eb68952386efce Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=2e7f4728fa738a7a7b6c4e4c46eb68952386efce commit 2e7f4728fa738a7a7b6c4e4c46eb68952386efce Author: Pierre Pronchery AuthorDate: 2024-07-19 17:32:27 +0000 Commit: Ed Maste CommitDate: 2024-10-11 15:53: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 Sponsored by: The Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46044 (cherry picked from commit 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47) --- 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 de759f81bc86..5c33645f0f0d 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -8314,6 +8314,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;