From nobody Fri Oct 10 17:16:34 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 4cjth24rM0z6Bcxv; Fri, 10 Oct 2025 17:16:34 +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 4cjth220MNz3gp6; Fri, 10 Oct 2025 17:16:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116594; 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=LO42BJ6MKiRAag5vUtjT7noMAsBONnitHSSMiQ/4GoE=; b=ioZ/hIpFPQmhUoOZG49UrFtrh4kiQTRQxSPqdtFZoLMlfTlPQxi+9/gPe83WuXNySS3mMj rwiVI7oUhZdOtlZi2W2FId930pzOjNOEByidfaZoZ5AniJWabz97EKWCWs22E956KG0WAd tvsGEgPBxJjvdpyeiSDXmtiA14OnJ/W7BU0mXuhovWm8bPIXLEAq2QR2batlmkvHEX5Z8R WetCulZcycsRVFrZfy/KwuhF0P+3kcjDNxuRXp3BjUpDxNiCdDy6lIR4NCJ62+oUVqixHY NK4vnW0lQWEZjeKgJXt5xECnczEhCSc/AvPSL8t65+bmwORYcb2Ht3Zezloc4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116594; 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=LO42BJ6MKiRAag5vUtjT7noMAsBONnitHSSMiQ/4GoE=; b=EFFr2zdLjGrsFlVc0mRzV7o0qoKnyPBboKeSXNf5cLdsXIG6uL0hwShBUaP6pO9h3yUa4r k3O1uI/A1uatziisTQAsDJgwUg1TzNgsgGL+Yn2Ajui5+lk1H722D9bnJCNMscMD4DTydN tfqJ8xg7y2yKqXku2KezoqUd4m1DvICXkW1DvL/tqWReTbL4As2hJ69Jg+lSzFFDzsuD8L lfA5yV0RuyzeFqpn64VAYmRlisqetG6+5cyC9EpYazbtTtm4Am+UC7QsjL9adruIH1JlQ2 9Hlo+itHL85WMehL7eg7VWMBI8uJ8rZyrSmqostX0++ezhEPOvKzeerkaPR7QA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760116594; a=rsa-sha256; cv=none; b=k/gJylmDqSjBxfLdoi1V202bypFRM5UNinWwyGmpYh+g0oWqWUBF2U0tNnuj1e2iJ6nTfi 2yrl+xSmkKP6dQJ0Vih0F9e0If+CKkf8/mppNZC8ug4FvEzqH+pLSKKS/K372LWznx/yn4 kkIJXlBb0iJSkjwFqpxgIPeSV4IQdnlxReW/+EptgrzIAUMigUE+j+BPAbliEptHwXcScP LZsrIwGpCHhSXszQ+LRUluk4gM9UDyIFtRIelLlEiX7MttZyQneK1f4MwKKxAgfIiMu0Ea 9zu6DC3piaCcnwHenGAIBqAvphNe0hRuXgd8Eid/dhLKpT68SZJZcJ7XtyrpIA== 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 4cjth211ktz1B8L; Fri, 10 Oct 2025 17:16:34 +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 59AHGY5v009632; Fri, 10 Oct 2025 17:16:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59AHGYWs009629; Fri, 10 Oct 2025 17:16:34 GMT (envelope-from git) Date: Fri, 10 Oct 2025 17:16:34 GMT Message-Id: <202510101716.59AHGYWs009629@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: b025aa9f5abc - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: b025aa9f5abc44a19a6437bea17fcc80a7747200 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=b025aa9f5abc44a19a6437bea17fcc80a7747200 commit b025aa9f5abc44a19a6437bea17fcc80a7747200 Author: Olivier Certner AuthorDate: 2025-09-27 09:56:33 +0000 Commit: Olivier Certner CommitDate: 2025-10-10 17:16:00 +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 0c4b2d74cdcd..1006d4eae916 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -1993,6 +1993,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 @@ -2004,7 +2008,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);