From nobody Thu Oct 2 16:58:27 2025 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 4ccyfr0bKZz69YJN; Thu, 02 Oct 2025 16:58:28 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ccyfq4MQbz3nS3; Thu, 02 Oct 2025 16:58:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759424307; 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=nLKPSq5AuuoaWcLdzKtYFYPrEWWu3HohWcjt/848a8k=; b=YAPdtRI/FIcR0gh5E0ha+KtNDLNwwFKJk/vpi2hwvxC1vzojfFMoxD7cq58EfTKVQJQ8f4 u/DgJMKiUXWYtgWxHSvbK3uQnaWYqOSfl0yGEpDtAE/Q/bQW7nE69EX814eLgWgHNXv9D2 TmmaWhh/tuhIAAnKaqqk54OjRwLZ258FYNP3rVQa6VyLdE4FVV/B+ci72qadys7Ble1aMi l8sIdCWy6K/FYiNXepa2CHLK+Mt8D6Fw/gfiADgs7vLdRM2/X2DWvD0LKEu+Gr5fO24aa9 m+xX6h0pdtfiaGEvzz6Jo9cNhhjoF/p61avS1BR1qsKtKdLxy9a33Be/24pgug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759424307; 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=nLKPSq5AuuoaWcLdzKtYFYPrEWWu3HohWcjt/848a8k=; b=cDR7JsWDUG6oeGUorFtmT7gqaYmXTut8CajeMvZKB7o60TusJaDaMRiam7xdTaX0j8CWgM tr7YO2cQxFuBL9+YMDNUY6AyQdjE1/Bg7L5ZS9t4eTz7cAaOKEEM/P2P7yWOaOKAaUBOWO YTTpXd2iZgy4Pc0xWw6477fe7Flonn9l/O/8UUrpNR+9u/5AkUsQY4UCIAmyMBqO5gAQMN arNH2gR8T6cbo5H/W7OgpIjzRDBDQSi/iHqs9PF/oSIBFA76gHgagSydwNvd1SWsx3T+a+ SWP9G0HLDlk5iJ4UMAUH3HFTKllwiz0argqsBiWcAKWbxXtXtUsGGAldGeoUhA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759424307; a=rsa-sha256; cv=none; b=ZMZN+foZfDggJgaKkQhwF7q2fil4KTcsGJVJo5cI6fX2PiSBONV1ZNxikbscT/YsvuJ3kU txitY38oK3IVo/kXFXNFKOJrMx66/yPvp3bPN0nc4MhKsfllXZHeqJKCiBBUjWbYtig5xM FOYVsFy97ShHuS9ylM+MrB33UA1fCcrqi4qHkvOEboGvLqKGD0Vv+jxBmdvmtANVEjLMPw tl6CvDzeViGkgeSmBShAwC8ibVhF+pKPeRmy2LtExkNa4WZ3FhTQhchG5HYSn+6Lu3zgYR Fz1BYK62UV0whAZpRlLlmE+Dg/tQK0COMojVQdHDhj5LfeKnFF5/73xsEuIvtQ== 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 4ccyfq3xG7z28s; Thu, 02 Oct 2025 16:58:27 +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 592GwR6S028219; Thu, 2 Oct 2025 16:58:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 592GwRdL028217; Thu, 2 Oct 2025 16:58:27 GMT (envelope-from git) Date: Thu, 2 Oct 2025 16:58:27 GMT Message-Id: <202510021658.592GwRdL028217@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 89958992b618 - stable/15 - MAC/do: Check executable path from the current jail's root 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 89958992b6189eaecbb3d036fce90fcecb005cb2 Auto-Submitted: auto-generated The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=89958992b6189eaecbb3d036fce90fcecb005cb2 commit 89958992b6189eaecbb3d036fce90fcecb005cb2 Author: Olivier Certner AuthorDate: 2025-09-27 09:56:33 +0000 Commit: Olivier Certner CommitDate: 2025-10-02 16:57:19 +0000 MAC/do: Check executable path from the current jail's root Contrary to my initial belief, vn_fullpath() does return a vnode's path from the current chroot, and not from the global root (which would have been a bug also, but without security consequences). This enables a "confused deputy"-like scenario where a chroot(2) can change which executable can be authorized by MAC/do, which is even more problematic for unprivileged chroot(2). This was found by re-examining the code following two close events: 1. Shawn Webb sent a mail to freebsd-hackers@ on 08/05 saying that in HardenedBSD they had added a check on P2_NO_NEW_PRIVS (in mac_do_priv_grant()), which I responded to on 08/20 saying that P2_NO_NEW_PRIVS was not necessary for mac_do(4), with a correct reasoning but based on the wrong above-mentioned assumption about vn_fullpath(). 2. I reviewed some code by Kushagra Srivastava (GSoC 2025 student working on mac_do(4)/mdo(1)) adding the ability to specify which executables can spawn processes that mac_do(4) may decide to authorize (others are simply ignored), which currently is hardcoded to '/usr/bin/mdo'. MFC after: 3 days Event: EuroBSDCon 2025 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52758 (cherry picked from commit 9f269a0a771aff4f0a735211907a52c52fc0661b) --- sys/security/mac_do/mac_do.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index 6f3e63d06198..2bcff7bba973 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -1992,6 +1992,10 @@ check_proc(void) /* * Only grant privileges if requested by the right executable. * + * As MAC/do configuration is per-jail, in order to avoid confused + * deputy situations in chroots (privileged or unprivileged), make sure + * to check the path from the current jail's root. + * * XXXOC: We may want to base this check on a tunable path and/or * a specific MAC label. Going even further, e.g., envisioning to * completely replace the path check with the latter, we would need to @@ -2003,7 +2007,7 @@ check_proc(void) * setting a MAC label per file (perhaps via additions to mtree(1)). So * this probably isn't going to happen overnight, if ever. */ - if (vn_fullpath(curproc->p_textvp, &path, &to_free) != 0) + if (vn_fullpath_jail(curproc->p_textvp, &path, &to_free) != 0) return (EPERM); error = strcmp(path, "/usr/bin/mdo") == 0 ? 0 : EPERM; free(to_free, M_TEMP);