From nobody Thu Aug 17 22:11:32 2023 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 4RRfNj2Q6bz4qDw7; Thu, 17 Aug 2023 22:11:33 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RRfNj1ZGtz4Zdv; Thu, 17 Aug 2023 22:11:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692310293; 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=I1IkIQ+rkEtrI1ePU0mg0t58WJxumV5BvnjNcLkZdys=; b=xCYBQIo9RlyAD1e4KbC9O1wMMDQel50Q2iet3dzXTn574Pzv6xygDTumictzrYGyCnCdRW wSzJdOk/2W/WRvnw8v64VxCd/bFEEMKxTCJs2BMsuI9dsBfsXjnPFrAWu4+PNOmAx+4uhk U72eFuaDiW/b6Mhqz+krltNBdVEHeduJjglH2oKcKGPs5vLwbmKOVPD6J2QaDUOguovJtt SE4rCMvUnP6lh8BCupCjisB+VyqbrCyyDsofPP9JEJS4gp5AOHCPUQZsMCyuIeNkH/5053 Y5DYPc111qnvMnn4rjIqojNh/s81uC+eLWoUd1haKHK/FD+7xxpw5OeSEU4e/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692310293; 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=I1IkIQ+rkEtrI1ePU0mg0t58WJxumV5BvnjNcLkZdys=; b=R5wS3kP7x14TWoCYysDPwMbVnUPVznuIrjLcq2VidAv5Kta+8a8dOXZeS6SIUzzaRLaX+9 wttZaPGieokLFum8GIM9GqqnZjWHwH0YKl1+6bDF2Goy7KhSomEggDvQj5UMnMimJEUVwG 1R4tUq5UdzhtWLh29DEH5bTHZJbywbaGNy6yZTd6MiFEFiYRNcwQmYfTc/uVKBrHuKByc8 bI03cvH8mZ5Xru5Y9aGhgdQpP4g338069wkI6kl+NFKhFHaRmkK6IMK44067fvnzbvCBz/ q6jW6vgt2FxIZVbOerIJV1ZxJ/rosXTvuDYSmf3ommhT4bHDGvWiuuwcwEX+9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692310293; a=rsa-sha256; cv=none; b=CNuqdBE+b5lWPpj+Z1mTRkjKv7+AqqSLEWNgoZHgJ8YDAICT5QKdn6os98+yrcRZomKWnx AwWq5Cd5xFLpqYVnyAsaGZAgcD3dp1JiLruCJLmEfHxdIxG1jCAzrKM6aLEKkx7w0LlPCw poZ3Ves2G/n+nT6uKBdUhadYqWzD2FT+avaRRNRYCr2qHcDR3psCuBzcaYh8SRrTWcq9W8 a7PSXVylxAtVzkXlOZev6brRxV39N1BSpnjj9jOH+j/Xy2hXYBORi43wuWstq157wK0siY HEPzc2pro/hNHnpv+Yk76TKqm07AyHJfxAlSHsoih8ed4r2ISeb/nuP/RuPrWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RRfNj0WMgzrRl; Thu, 17 Aug 2023 22:11:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37HMBWic011851; Thu, 17 Aug 2023 22:11:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37HMBW0h011848; Thu, 17 Aug 2023 22:11:32 GMT (envelope-from git) Date: Thu, 17 Aug 2023 22:11:32 GMT Message-Id: <202308172211.37HMBW0h011848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 5635d5b61e21 - main - vmm: Fix VM_GET_CPUS compatibility 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5635d5b61e2113b91db921267cb476b1fde93e9e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5635d5b61e2113b91db921267cb476b1fde93e9e commit 5635d5b61e2113b91db921267cb476b1fde93e9e Author: Mark Johnston AuthorDate: 2023-08-17 18:49:54 +0000 Commit: Mark Johnston CommitDate: 2023-08-17 22:10:02 +0000 vmm: Fix VM_GET_CPUS compatibility bhyve in a 13.x jail fails to boot guests with more than one vCPU because they pass too small a buffer to VM_GET_CPUS, causing the ioctl handler to return ERANGE. Handle this the same way as cpuset system calls: make sure that the result can fit in the truncated space, and relax the check on the cpuset buffer. As a side effect, fix an insufficient bounds check on "size". The signed/unsigned comparison with sizeof(cpuset_t) fails to exclude negative values, so we can end up allocating impossibly large amounts of memory. Reviewed by: jhb MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41496 --- sys/amd64/vmm/vmm_dev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/amd64/vmm/vmm_dev.c b/sys/amd64/vmm/vmm_dev.c index c13adfd599ee..cae15d7059cb 100644 --- a/sys/amd64/vmm/vmm_dev.c +++ b/sys/amd64/vmm/vmm_dev.c @@ -989,11 +989,12 @@ vmmdev_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag, error = 0; vm_cpuset = (struct vm_cpuset *)data; size = vm_cpuset->cpusetsize; - if (size < sizeof(cpuset_t) || size > CPU_MAXSIZE / NBBY) { + if (size < 1 || size > CPU_MAXSIZE / NBBY) { error = ERANGE; break; } - cpuset = malloc(size, M_TEMP, M_WAITOK | M_ZERO); + cpuset = malloc(max(size, sizeof(cpuset_t)), M_TEMP, + M_WAITOK | M_ZERO); if (vm_cpuset->which == VM_ACTIVE_CPUS) *cpuset = vm_active_cpus(sc->vm); else if (vm_cpuset->which == VM_SUSPENDED_CPUS) @@ -1002,6 +1003,8 @@ vmmdev_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag, *cpuset = vm_debug_cpus(sc->vm); else error = EINVAL; + if (error == 0 && size < howmany(CPU_FLS(cpuset), NBBY)) + error = ERANGE; if (error == 0) error = copyout(cpuset, vm_cpuset->cpus, size); free(cpuset, M_TEMP);