Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Nov 2023 13:40:01 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 92541c12bc25 - main - Open-code proc_set_cred_init()
Message-ID:  <202311021340.3A2De12X027081@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=92541c12bc25c59333d7f3b0721b6b16aaff3644

commit 92541c12bc25c59333d7f3b0721b6b16aaff3644
Author:     Olivier Certner <olce.freebsd@certner.fr>
AuthorDate: 2023-09-25 08:48:49 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-11-02 13:30:02 +0000

    Open-code proc_set_cred_init()
    
    This function is to be called only when initializing a new process (so,
    'proc0' and at fork), and not in any other circumstances.  Setting the
    process' 'p_ucred' field to the result of crcowget() on the original
    credentials is the only thing it does, hiding the fact that the process'
    'p_ucred' field is crushed by the call.  Moreover, most of the code it
    executes is already encapsulated in crcowget().
    
    To prevent misuse and improve code readability, just remove this
    function and replace it with a direct assignment to 'p_ucred'.
    
    Reviewed by:            markj (earlier version), kib
    MFC after:              1 week
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D42255
---
 sys/kern/init_main.c |  2 +-
 sys/kern/kern_fork.c |  2 +-
 sys/kern/kern_prot.c | 11 -----------
 sys/sys/ucred.h      |  1 -
 4 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index a8df9f84a29a..f39f5b8955ed 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -562,7 +562,7 @@ proc0_init(void *dummy __unused)
 	curthread->td_ucred = NULL;
 	newcred->cr_prison = &prison0;
 	newcred->cr_users++; /* avoid assertion failure */
-	proc_set_cred_init(p, newcred);
+	p->p_ucred = crcowget(newcred);
 	newcred->cr_users--;
 	crfree(newcred);
 #ifdef AUDIT
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index aaa46a64ef9f..3080bd11123d 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1056,7 +1056,7 @@ fork1(struct thread *td, struct fork_req *fr)
 	 * XXX: This is ugly; when we copy resource usage, we need to bump
 	 *      per-cred resource counters.
 	 */
-	proc_set_cred_init(newproc, td->td_ucred);
+	newproc->p_ucred = crcowget(td->td_ucred);
 
 	/*
 	 * Initialize resource accounting for the child process.
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 00eb2fccdeef..6d4d5ef47926 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -2194,17 +2194,6 @@ cru2xt(struct thread *td, struct xucred *xcr)
 	xcr->cr_pid = td->td_proc->p_pid;
 }
 
-/*
- * Set initial process credentials.
- * Callers are responsible for providing the reference for provided credentials.
- */
-void
-proc_set_cred_init(struct proc *p, struct ucred *newcred)
-{
-
-	p->p_ucred = crcowget(newcred);
-}
-
 /*
  * Change process credentials.
  * Callers are responsible for providing the reference for passed credentials
diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
index 7c9e46e47774..3f8a70ab9c90 100644
--- a/sys/sys/ucred.h
+++ b/sys/sys/ucred.h
@@ -146,7 +146,6 @@ void	crcopy(struct ucred *dest, struct ucred *src);
 struct ucred	*crcopysafe(struct proc *p, struct ucred *cr);
 struct ucred	*crdup(struct ucred *cr);
 void	crextend(struct ucred *cr, int n);
-void	proc_set_cred_init(struct proc *p, struct ucred *cr);
 void	proc_set_cred(struct proc *p, struct ucred *cr);
 void	proc_unset_cred(struct proc *p);
 void	crfree(struct ucred *cr);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202311021340.3A2De12X027081>