From nobody Wed Oct 29 02:37:24 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 4cxBGr4tpHz6F8VY; Wed, 29 Oct 2025 02:37:24 +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 4cxBGr4J2Qz3K33; Wed, 29 Oct 2025 02:37:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761705444; 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=cZIsba1nC7gRFWut6KAHm9cW0JvAZ8ZdESKTp09KUaI=; b=DTZE53xMUINAxuf+myAtqo7PJP08GuVtGdbFRFa5kJelG5i9rauZ/l0wT2YNw7MPUszYd4 uYeZnvu8pCiqaVyVd4Q/keLswiKOyR4rw/TlwqvCHdGWQbVe98XPV5bJX7DHAfPfDYZhkT 0RLDznSqAlF7WzRsnXdxFKwgKkikwWov49bCc524x+nPZ2plRZOI9lEFxDIgaumCnMTBOA Gpjterr5NJBikotj4lWQMRp4BnAjVr2tcYMNUse77y7SLMQcLRkL+4145yRcjRMnb/ARKb VFsQKGwWo9ExWreGLmd8uUbSyC6dl3VjjzIOOJP+u5XkQenxHJfWXgUMlYmi3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761705444; 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=cZIsba1nC7gRFWut6KAHm9cW0JvAZ8ZdESKTp09KUaI=; b=vHSGXem1w+O36MGLsPYd2pIJhZMsp4mqqYyUCHDSBdRUiZi3fYNr1p3FkLr7J9aUgXwIyd 0plUfM3is17S/iAgdtjp0XP90WCDnuNv0iEVeHEbGtsUJRK1YnVK05G8RbnoKKOhQThpIf 0j2axtYJbPXSatwhsx7V++UbxxmZwCIEBL5ufwh3NB50P+iJSrTaQ3ewlG1PJGUU9ppXig gyTkTZwnCH/f/kAxv4coTC3uYr+YaF3YDGW1U5Wk5nly5eSDPjJhaNyF1NOCSVkMO5eELs JYzk8eUSuTS+GRqaUGdhwUxxJfFaXJJFlHQ/j/AzqzK7069ve+KJczexLWICWA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761705444; a=rsa-sha256; cv=none; b=xnZpkRDQzaDYuX2G/sviRDYEYNoAq71twvEgnJCY/LQX1veA/09oPTiLaDVg9qOYcDURQI pQWV0Tl2J4x0TVxJQEEW8eSBdfr3M5EY7zSoAp2VE1wfG86je/8G4ITX0RG2wTCQXoDWkR Sr7mdkmGLSoTtLXUNKBlzZsaLebh+g1yW3bkUzZFnAnjkYO3yeX4WLncBcwJRCw54y4mfK nuZG7WMmpDJnrKWyCEy3piyFF0/VZWyPMkXxPgwMmom/Nq6oRvAtGt237XikjumwEy6scy HOA+D/Z8cQUlhQfP8tM9WhCvSpWWMLSNtgFK0G63UZ3diY+VlNvbqYFBGmQo1g== 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 4cxBGr3ptvz2h8; Wed, 29 Oct 2025 02:37:24 +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 59T2bOfJ060113; Wed, 29 Oct 2025 02:37:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59T2bOKK060110; Wed, 29 Oct 2025 02:37:24 GMT (envelope-from git) Date: Wed, 29 Oct 2025 02:37:24 GMT Message-Id: <202510290237.59T2bOKK060110@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: 98edcbcce0a4 - main - libutil: defer setting the MAC label until after the login class 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 98edcbcce0a4650084bd86e704cfa38bf590250c Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=98edcbcce0a4650084bd86e704cfa38bf590250c commit 98edcbcce0a4650084bd86e704cfa38bf590250c Author: Kyle Evans AuthorDate: 2025-10-29 02:37:21 +0000 Commit: Kyle Evans CommitDate: 2025-10-29 02:37:21 +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 MFC after: 3 days Co-authored-by: Kevin Barry Differential Revision: https://reviews.freebsd.org/D53362 --- 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 */