Date: Fri, 19 Dec 2025 09:19:20 +0000 From: Olivier Certner <olce@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 269e6a4bc065 - stable/14 - proc_set_cred(): Allow 'newcred' to have multiple references Message-ID: <69451898.3d6dc.79fc1cbb@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=269e6a4bc0656994ea895c88135a2b0d162e8d13 commit 269e6a4bc0656994ea895c88135a2b0d162e8d13 Author: Olivier Certner <olce@FreeBSD.org> AuthorDate: 2025-11-06 22:25:57 +0000 Commit: Olivier Certner <olce@FreeBSD.org> CommitDate: 2025-12-19 09:16:47 +0000 proc_set_cred(): Allow 'newcred' to have multiple references This is an extension needed by next commit, where some additional reference is kept on the credentials to be set on a process in order to keep these credentials alive even after the process lock is released (an intervening reset of process credentials could release the reference that the process holds). Only 'cr_users' is incremented, as the reference (counted in 'cr_ref') comes from the caller, who passes it to the process. Reviewed by: kib, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53636 (cherry picked from commit 5d46d11772c3280fd1c8ae09f20ce6c57f631c30) --- sys/kern/kern_prot.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 044b8091310f..c7c60d8bb747 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -2678,10 +2678,6 @@ _proc_set_cred(struct proc *p, struct ucred *newcred, bool enforce_proc_lim) MPASS(oldcred != NULL); PROC_LOCK_ASSERT(p, MA_OWNED); - KASSERT(newcred->cr_users == 0, ("%s: users %d not 0 on cred %p", - __func__, newcred->cr_users, newcred)); - KASSERT(newcred->cr_ref == 1, ("%s: ref %ld not 1 on cred %p", - __func__, newcred->cr_ref, newcred)); if (newcred->cr_ruidinfo != oldcred->cr_ruidinfo) { /* @@ -2707,8 +2703,10 @@ _proc_set_cred(struct proc *p, struct ucred *newcred, bool enforce_proc_lim) __func__, oldcred->cr_users, oldcred)); oldcred->cr_users--; mtx_unlock(&oldcred->cr_mtx); + mtx_lock(&newcred->cr_mtx); + newcred->cr_users++; + mtx_unlock(&newcred->cr_mtx); p->p_ucred = newcred; - newcred->cr_users = 1; PROC_UPDATE_COW(p); if (newcred->cr_ruidinfo != oldcred->cr_ruidinfo) (void)chgproccnt(oldcred->cr_ruidinfo, -1, 0);help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69451898.3d6dc.79fc1cbb>
