git: 4078a7051ab1 - stable/13 - Open-code proc_set_cred_init()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 17 Jan 2025 12:26:52 UTC
The branch stable/13 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=4078a7051ab146d146e88720fac85ca164af2d4a
commit 4078a7051ab146d146e88720fac85ca164af2d4a
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2023-09-25 08:48:49 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-01-17 12:24:43 +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
(cherry picked from commit 92541c12bc25c59333d7f3b0721b6b16aaff3644)
---
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 66db882ba4f3..f827000d9200 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -558,7 +558,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 114eeeb2a943..413453f9bf8f 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1049,7 +1049,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 482472025fdd..2dc5ecd00175 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -2275,17 +2275,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 876919f56fb1..f5e2757f7417 100644
--- a/sys/sys/ucred.h
+++ b/sys/sys/ucred.h
@@ -158,7 +158,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);