From nobody Mon Jan 22 17:30:02 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 4TJcfz04rlz57r3T; Mon, 22 Jan 2024 17:30:03 +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 4TJcfy4V9Kz4fRB; Mon, 22 Jan 2024 17:30:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944602; 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=srUAzh/SHgKzRakG2hGAi8oiDPGi9S9okXiS+HdzYm4=; b=AoKLuU0YLiJ6LYf1FRQsyZ1WEhe0IwIt7z4w6dqJLH6IakxuiwVYFMl009pc0Sz0PE9JiT rpJTVUv8qx5xAx26rl+Gk0ui1xlxddYc5qtQrniMOEJBazbozmEkNAuaCbqPNX4884BalG YHDEdIG8eU2lCTTHnuIfwNMb8Wx6eDwVxRBHkU1Z354yS5YVtnt/n/fKRbrdoUzrKduICH 7+XKYTLWEWEX/uS6mM3j45YJr/TZeGtn5IMml7F/8SMRmq4TjEXhltv3+1MdX0Z8J8L9pL r1Q0y9F78pqKcd3IKm0Sy8wQ03VUfZQg4ni/qmaSUgAqO9SDkV/sYjuNJTu4sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944602; 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=srUAzh/SHgKzRakG2hGAi8oiDPGi9S9okXiS+HdzYm4=; b=YlanAAVlO3qnCzalGmrcts7kLs+3yPGWcn8GWwdYRZZK/nHwa2YRHNI2mlB0f+TD8Rabt/ x1GxwkpiB/ybgzWyFXsfDmh9Fqld8B8Uuh6uOzDDVLHG3zcBS3UJqLyO1TnaZlq6VlJjrM uM3DLHu3U7OjQ5W6CZycPAgt5M4n0GfoixxE2EmNtnWUP9Ddysr/pL3gUcTyPMFtIFPuEf UdEKP+en0BZvC6u55jmiQ0S7myHwGNgtNlKOk1kfPcULhtelVSysD3riipTDGF9JROVoEM uhJtLATZgh0I3U4DDiyty/vFwtoPPWJpmfDAMYFeZL6pbphZ2m+dmSjGBVdTwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705944602; a=rsa-sha256; cv=none; b=JHyp5GZCiDw9hGhGCYJa/0+4vuNZwEt3MbR8FT5JZdg4tUqw+UxbOI/TofvspLEkJDZ7MF mAis0AnhHgNLxt07kf76jNQaI4nCKhslOmYYGhv2BZQsgo8p6rqxTKlxQGEIN1Vrt50CzK DJJk6/LZKqI8z7vJr5B6Opmlz20ebgHFLjMtR2SvFyhltQ01quWU/sChikJhyz8Nk/7cg5 lghffe+p0I7ZJP4XJAGT5wGhQYPD89u3ZrYCxhyZoKi0NUdy9cug+0a+cW1l/za+6OO1Ck djVqWnFGlSHhWR5wZLQBB1toGIeIcq1Xrj7Mn9C/WKHoEIwOl+PUtLyho7FR9w== 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 4TJcfy3W6Lz19kQ; Mon, 22 Jan 2024 17:30:02 +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 40MHU2gU008238; Mon, 22 Jan 2024 17:30:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40MHU271008234; Mon, 22 Jan 2024 17:30:02 GMT (envelope-from git) Date: Mon, 22 Jan 2024 17:30:02 GMT Message-Id: <202401221730.40MHU271008234@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 4bd568bd759b - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 4bd568bd759bfd632425ee13e5e4e83b6a935525 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=4bd568bd759bfd632425ee13e5e4e83b6a935525 commit 4bd568bd759bfd632425ee13e5e4e83b6a935525 Author: Kyle Evans AuthorDate: 2024-01-05 06:21:14 +0000 Commit: Kyle Evans CommitDate: 2024-01-22 17:18:52 +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 (cherry picked from commit c067be72e835e469518ec985b6cc4e475c378944) (cherry picked from commit f9b17005bf8f1a30e2a74a3e66c92e34aa87f9bf) --- 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..16131dacecaa 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);