From nobody Tue Jan 20 04:09:21 2026 X-Original-To: dev-commits-src-branches@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 4dwDNd371Yz6Nw3Q for ; Tue, 20 Jan 2026 04:09:21 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dwDNd0zLwz3V8s for ; Tue, 20 Jan 2026 04:09:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768882161; 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=d+h2RZXx54lKenO49a0hqmvfdBHZM+FVIW8C6vkY6SQ=; b=Ntzcfny7ONv/f6w8pYPtjCUBSLMQ9ImP/5/i+DxyTxMVr4HoO8GHBOso/qeGUWKoSsaHR2 VMwn/uXrzKpRujkhUz6VkQqLuj5YNo5ADV3lvboQ5gIsjaKAQe5co0AqIqWFv26AqfQCw8 F17J8oQuYltovWkTx1yTq7JqiYWeqJMgTNGvAw90V8dgYr9UQU5D0jdvP5uxf+cxo0MAQH FZ6ICwwWWpl/ziO6Ggv9Kvwkt9V/Q5KKpIsvLSZhzel75DFB4S5/bA7Ym1HMdyfPULFQr7 +FGSRWE52JQFT+akyFer5ULo0IdO8C3EH3Ye1jcKtFzWTQz163wOyo+48L/6zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768882161; 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=d+h2RZXx54lKenO49a0hqmvfdBHZM+FVIW8C6vkY6SQ=; b=yKkxFzXYcAc9KIz0mn2gUItIjdCVrk1tgIYrJgYDFHJZfonQpJd1jocPHhesMtN4JrcoL5 GtTDtBF/ExTf5brqTcC5Nq0gHyI17xwnERkl33xc7dWjhJcY3NOxBCO4aCNDtxDPp/m522 A6qXDU9xQfs2PmBsJMNvsfP/t52Bw2Ijd/S3zFiK6yrjYUZSe2V2w3gOMcdze/VyNopoNv Z4NGfm8JZFvN+pf0pXjEVzFYUI2ApgqIh0w8riurfL2qnP7OpGGsO0IFN55Eg4ghREHOAd fwKY6yBjFwfJPMGhS1yGkIZStojyhRx044r0vtobjaN+9wwJ2gWVf+r+Ftywuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768882161; a=rsa-sha256; cv=none; b=lP6oLbXIc7s+w+p0f4EEEpOI5qw7y41aEldIipf1N2rGw4dKhqO2ue8D1x0Bsr1hm0NHnz gqiV4tnt1vg2dpv6xWH1q7EMBRKXZiUiIXG/XJez4PzZk/jg6Bcts3P0Y2htHNul7IIVEZ BnKwE0ZxNBGz5HaMM83zWx5W5VkiWd/fSqZckgmGqbaUcH290nn6ZTXwBDbLu3Vqzuw845 jjQHZBcBlLRO46lGBU9j2fFTjarghT0f3ZHTrIUX8gFrfj9m/9apjHjK5Ww8IB5WZN6cXI nQ8pbsfyFcrHcdbggE9RbaKBPIssC37oE/dfR4pitHcej2UCmGCxmymuNbpeOw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dwDNd0C8mz11d1 for ; Tue, 20 Jan 2026 04:09:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3091d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 20 Jan 2026 04:09:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: d15be6d470d6 - stable/15 - libutil: defer setting the MAC label until after the login class List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/15 X-Git-Reftype: branch X-Git-Commit: d15be6d470d631dce2e0b5e07c4def8952a0f753 Auto-Submitted: auto-generated Date: Tue, 20 Jan 2026 04:09:21 +0000 Message-Id: <696efff1.3091d.79dcdd01@gitrepo.freebsd.org> The branch stable/15 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d15be6d470d631dce2e0b5e07c4def8952a0f753 commit d15be6d470d631dce2e0b5e07c4def8952a0f753 Author: Kyle Evans AuthorDate: 2025-10-29 02:37:21 +0000 Commit: Kyle Evans CommitDate: 2026-01-20 04:04:17 +0000 libutil: defer setting the MAC label until after the login class MAC policies, like mac_biba(4), may forbid changing the login class once a label has been applied. For setting up the initial login context, this isn't really expected and in-fact may break some class-based configuration. Defer setting the MAC label until after the login class is set, and remove the requirement that we have a pwd entry since the label is pulled from the login class -- we only use pwd for syslog in this path. Patch is largely by Kevin Barry, with some modifications and this commit message by kevans@. PR: 177698 Reviewed by: des, olce Co-authored-by: Kevin Barry (cherry picked from commit 98edcbcce0a4650084bd86e704cfa38bf590250c) --- lib/libutil/login_class.c | 55 ++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c index c3c1b0ddda27..9478b4dc98ca 100644 --- a/lib/libutil/login_class.c +++ b/lib/libutil/login_class.c @@ -543,7 +543,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in /* we need a passwd entry to set these */ if (pwd == NULL) - flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN | LOGIN_SETMAC); + flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN); /* Set the process priority */ if (flags & LOGIN_SETPRIORITY) @@ -564,6 +564,27 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in } } + /* Set the sessions login */ + if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) { + syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name); + login_close(llc); + return (-1); + } + + /* Inform the kernel about current login class */ + if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) { + error = setloginclass(lc->lc_class); + if (error != 0) { + syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class); +#ifdef notyet + login_close(llc); + return (-1); +#endif + } + } + + setlogincontext(lc, pwd, flags); + /* Set up the user's MAC label. */ if ((flags & LOGIN_SETMAC) && mac_is_present(NULL) == 1) { const char *label_string; @@ -572,8 +593,10 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in label_string = login_getcapstr(lc, "label", NULL, NULL); if (label_string != NULL) { if (mac_from_text(&label, label_string) == -1) { - syslog(LOG_ERR, "mac_from_text('%s') for %s: %m", - pwd->pw_name, label_string); + syslog(LOG_ERR, "mac_from_text('%s') for %s %s: %m", + label_string, pwd != NULL ? "user" : "class", + pwd != NULL ? pwd->pw_name : lc->lc_class); + login_close(llc); return (-1); } if (mac_set_proc(label) == -1) @@ -582,33 +605,15 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in error = 0; mac_free(label); if (error != 0) { - syslog(LOG_ERR, "mac_set_proc('%s') for %s: %s", - label_string, pwd->pw_name, strerror(error)); + syslog(LOG_ERR, "mac_set_proc('%s') for %s %s: %s", + label_string, pwd != NULL ? "user" : "class", + pwd != NULL ? pwd->pw_name : lc->lc_class, strerror(error)); + login_close(llc); return (-1); } } } - /* Set the sessions login */ - if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) { - syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name); - login_close(llc); - return (-1); - } - - /* Inform the kernel about current login class */ - if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) { - error = setloginclass(lc->lc_class); - if (error != 0) { - syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class); -#ifdef notyet - login_close(llc); - return (-1); -#endif - } - } - - setlogincontext(lc, pwd, flags); login_close(llc); /* This needs to be done after anything that needs root privs */