From nobody Thu Aug 24 13:41:11 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 4RWkkb477fz4r9xV; Thu, 24 Aug 2023 13:41:11 +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 4RWkkb3hxcz3gR4; Thu, 24 Aug 2023 13:41:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692884471; 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=w05P+l4rp0AYUr4jDPTzE0iCMstLTwsIbhLzE3U38tg=; b=ZCs6TXVsoAxdZ5oZcSapjZqFECiICtR5MmisCsa9/R86g5SsCyYVBtsaJLkOQ3BU9Ac2WS 1RPIP2mh4LP2N/by7YBKcOYrxWZvROOjhSeDIP4FOS0t2sWkhT/kucjngEAI81zEr+uP3S kfyVYfnKP8H/Cot49j7VCqSRn1MqLlzbTa7IQhLz0pWDzhS+Q+UpApCVaMjhHWfN5Jc4K1 oIzT5rYfxEXtKsBqTdCgvvHXt4epl+UHiKgebzekBvSFxxuo/+J9ZYoGsNmRNQK29KSds+ YXQOVCi/8qzPl7DX7SfxrXRT2q6jtarT3RTJ1KrD627PvVYPIFvpGfSkc/6KbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692884471; 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=w05P+l4rp0AYUr4jDPTzE0iCMstLTwsIbhLzE3U38tg=; b=iuzZMrbJanaW+4dzqBoJuKtwmDsk58rYB8csvOt59ZpZgsBVcuf6kV6HrjS8JptF+luD7X A0AyYm9sAqSZ4Tg+z1IYuSYTuQnkwWDNWGDLvlFwiBY+gD5p667uK/pNlUq5+PX7d1l3u2 zolMqlkURwiI1sN4WUiqUkZNKLfID5KRVMXgnFa6BwpoN5Ia6sDe5IFArqhK2fV1mkBBHU TZTHccJojX9+JmiZQ/IpySrWvYKlmOmvf8/NLbzHIs/p8brjAhLKu1UlbAV8foHzyEYv0e +qk3ucE4EU5kXJAWj2PVbwdUFe1HC8666F5Ic+nMHqR2cJHbJz9BrD/dld0u4Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692884471; a=rsa-sha256; cv=none; b=DRNHcWu47L9AbIWFCH9BfsU4SaD0bnAe5PYQlXJIh0KHpDxFFhyIEQicY+fplmwDZBVYL+ PmPRULqrGYxz7IWkhUmAEGwoUac0NaCEzoKnGKJe/2OoeuM2bGjZBFryk5zL0TjUfYQWXv 1Tsvd6kXTdJ+wMLbaJsPEdhbxhh6Tp7CRlGMcqLycHb8V1Rt6sItsrcENSoU0ZmoCtHKtz ZaSB13cRclS67N31WZTcuCZ+jsZmS3kVITtIpGSlHT1VQ7Uac44WNSrZJkqxCdfwJdXBVK vghRRuxqpdnQJJ40bMAhIca8HFi+2VsqGOglBslBVOFv0Gs6J3u//xInnnGRpQ== 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 4RWkkb2WCjzTdP; Thu, 24 Aug 2023 13:41:11 +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 37ODfBvK023716; Thu, 24 Aug 2023 13:41:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37ODfB3l023713; Thu, 24 Aug 2023 13:41:11 GMT (envelope-from git) Date: Thu, 24 Aug 2023 13:41:11 GMT Message-Id: <202308241341.37ODfB3l023713@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7756dcc46f3b - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 7756dcc46f3b1059e68fdd0099ca26618d5d8d62 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7756dcc46f3b1059e68fdd0099ca26618d5d8d62 commit 7756dcc46f3b1059e68fdd0099ca26618d5d8d62 Author: Mark Johnston AuthorDate: 2023-08-17 18:49:54 +0000 Commit: Mark Johnston CommitDate: 2023-08-24 13:33:11 +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 70434a44e5f4..46faccf9b7e3 100644 --- a/sys/amd64/vmm/vmm_dev.c +++ b/sys/amd64/vmm/vmm_dev.c @@ -878,11 +878,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) @@ -891,6 +892,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);