aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Certner <olce.freebsd@certner.fr>2023-09-25 08:48:49 +0000
committerMark Johnston <markj@FreeBSD.org>2023-11-02 13:30:02 +0000
commit92541c12bc25c59333d7f3b0721b6b16aaff3644 (patch)
treef6f95ef81b1f56ede3cfe45a6a76d20a49eb00e4
parent63bf943d4af17799cef21e2bb78dd28003ce1ce5 (diff)
downloadsrc-92541c12bc25c59333d7f3b0721b6b16aaff3644.tar.gz
src-92541c12bc25c59333d7f3b0721b6b16aaff3644.zip
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
-rw-r--r--sys/kern/init_main.c2
-rw-r--r--sys/kern/kern_fork.c2
-rw-r--r--sys/kern/kern_prot.c11
-rw-r--r--sys/sys/ucred.h1
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
@@ -2195,17 +2195,6 @@ cru2xt(struct thread *td, struct xucred *xcr)
}
/*
- * 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
* and for freeing old ones.
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);