From nobody Fri Jan 05 06:22:04 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 4T5tf45FCgz56F83; Fri, 5 Jan 2024 06:22:04 +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 4T5tf44mTyz4lQd; Fri, 5 Jan 2024 06:22:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704435724; 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=nEGSLhCfQZ626oBPW/8SnmQ9CjI96UWddoT+sEFNL4w=; b=MX2YlPsKMCPrCcqXbr4DTdKVhuEtkaZIbQo9qdL3saJvEOFMnXKW23cPJA+2uCv7Y422j5 EdALRTWzZt6wzIeSpZ0iJ4OQdA48iOFNuTXljoswdGsZJ59Yv25u3rpUmylp+yV914TIm0 j0zNPxFO+0zMA0VB4PNoCsAJT8fuDd8cgtoOlM1emc1DILWF8FWSzwkabxNsDYfvGXId4H v+nsmYw8k+RS8RBTGg41Fjwf/RXNjDfIu8oKELVbun+jwWxRyt0MVIoofH5uMbIl+Wa7va v4YN3RerTVgKyEiAwuOEbt1ioZMpANu5QY+NkS93OZs+E+Biv2Jbns1YvPWWsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704435724; 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=nEGSLhCfQZ626oBPW/8SnmQ9CjI96UWddoT+sEFNL4w=; b=GOsOBg9r7+MlMl0I6ZIoJYGKn7GQuTXJj4a9aeaNBYeZ4+RYTui0YwRVsaLoqOrqSxtpq1 NrRps3+vyKEobYGB01TSTtp71JwNOVz7tFpP42LyGxLfAD+3fbvMpwSfnA0lBn+bfgkblw e7BhFCQ1YxQom2WSgwMVniq2HLseDpP53OLOZVgN+tW2KexyVdMKyS3FM9QgtZ1lwxILXP xEbQgmyaCE3ZNQs9kjtrzdxiou1LKDWehkj6KSGaWPs+rb0Ow9GqfGXVNzXhk5gEkds0Hr 61h78cz8v1lh+oLgJeSCYH1+hPHYDw0nnEpLYzaPgaGM351RfrFYPS3Ul7SinQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704435724; a=rsa-sha256; cv=none; b=VClMTEAXuXzwvhlns2EiH4WeF0Tc20oNHATmfAQfGJ8xDBgmzdweTkCFPXkS3BWW71929W tRSH6hXUbHFPfK9wmNDxzDFNqu/ZnfS4IqRtoc0bL4O5Z9A+IbSQov5FrAgfJh+AhL+awv oo1v8Ork2NQbOz0sYxUI3AHG4SfX2ia4tZ3IwmbfpWl1f/bSMJQothpJFuFdEdcsPSH3sU RlKk5QQjQkFdqubFO9n5nLt2qEDoZT3FYT8fMtYKBoaEzewYigetPEoOCvvrVW6Kg1ZI9g q0fUIB/BSuLJqMf0+85dTrz95gi751UyRwmPFT72gaP5R2kp6SYIX0c742xw1A== 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 4T5tf43XXdzmkr; Fri, 5 Jan 2024 06:22:04 +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 4056M4JN028966; Fri, 5 Jan 2024 06:22:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4056M4w4028963; Fri, 5 Jan 2024 06:22:04 GMT (envelope-from git) Date: Fri, 5 Jan 2024 06:22:04 GMT Message-Id: <202401050622.4056M4w4028963@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: c067be72e835 - main - bhyveload: limit rights on the dirfds we create 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c067be72e835e469518ec985b6cc4e475c378944 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=c067be72e835e469518ec985b6cc4e475c378944 commit c067be72e835e469518ec985b6cc4e475c378944 Author: Kyle Evans AuthorDate: 2024-01-05 06:21:14 +0000 Commit: Kyle Evans CommitDate: 2024-01-05 06:21:14 +0000 bhyveload: limit rights on the dirfds we create In neither case do we need write access to the directories we're working with; userboot doesn't support fo_write on the host device, and the bootfd is only ever needed for loader loading. This improves on 8bf0882e18 ("bhyveload: enter capability mode [...]") so that arbitrary code in the loader can't open writable fds to either of the directories we need to maintain access to. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43315 --- usr.sbin/bhyveload/bhyveload.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c index d4f930e8cc76..f75ef27dd958 100644 --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -734,12 +734,17 @@ usage(void) static void hostbase_open(const char *base) { + cap_rights_t rights; if (hostbase_fd != -1) close(hostbase_fd); hostbase_fd = open(base, O_DIRECTORY | O_PATH); if (hostbase_fd == -1) err(EX_OSERR, "open"); + + if (caph_rights_limit(hostbase_fd, cap_rights_init(&rights, CAP_FSTATAT, + CAP_LOOKUP, CAP_READ)) < 0) + err(EX_OSERR, "caph_rights_limit"); } static void @@ -860,11 +865,24 @@ main(int argc, char** argv) * guest requesting a different one. */ if (explicit_loader_fd == -1) { + cap_rights_t rights; + bootfd = open("/boot", O_DIRECTORY | O_PATH); if (bootfd == -1) { perror("open"); exit(1); } + + /* + * bootfd will be used to do a lookup of our loader and do an + * fdlopen(3) on the loader; thus, we need mmap(2) in addition + * to the more usual lookup rights. + */ + if (caph_rights_limit(bootfd, cap_rights_init(&rights, + CAP_FSTATAT, CAP_LOOKUP, CAP_MMAP_RX, CAP_READ)) < 0) { + perror("caph_rights_limit"); + exit(1); + } } vcpu = vm_vcpu_open(ctx, BSP);