From nobody Thu Nov 02 13:40:01 2023 X-Original-To: dev-commits-src-main@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 4SLlNy20FKz50Ldj; Thu, 2 Nov 2023 13:40:02 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SLlNy1SyJz4Npq; Thu, 2 Nov 2023 13:40:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932402; 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=+3ZiSKxLi9D+w+eZQE/bffTZXg1Aav+uLdSYx5cRwOQ=; b=WFL1nx0iPcJgbWvM5Of+8mxftmT9mMNN+RPC+8GzSfAdRZlW1hdMIfAgGyU5YyYRB51M9b RMr5MuCQKVIbDhZRlRiGLDwCDrKb0GSUC165Zay2kmtB/4LWJ1khmeods2JFUoMWUXWef8 KPTygnIRnVujkvcBcYAsyuFTJu8hK6y/IsPMKP7/ozDrnNCLZwNtDNHYy/0seTM/ipthPm eUYhBvcOU8SQ9sLrPFUatV2G4x6gGA9kVR8VYwSlYFqba9RRi8DM92L1Y1OnkrTwUBNdoE MfaD0OYr/V4me/BpoJG4v6Li2qm+6cW6YJCEtoI47a5+m+UNzBUrbxl+TS813Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932402; 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=+3ZiSKxLi9D+w+eZQE/bffTZXg1Aav+uLdSYx5cRwOQ=; b=j0MlCpZNjpye71KowBYnFuHfljS7taOPT9nv04mcrejjr5vO8lwI8QvAH7uvcGqZdsQJkp utXnEnRnzMpMOrSPZnRpb2gUMApD1GH6D6T1RknA/SVNKtlzpstDHC+OgImSwEV1plnIUU tKxxIl6XrELUph1uc7R7BuUo01QElmsA4g7sgOaY7FXSxaAoAbJSihY+xTmS/o6foPs28L Gjra7Sj32sVYsmcUOVj1bxeIIc543QPVuzjVfpp6IqndsZchUgguExssrEI4waEykZifi9 9w1eMGgOQsrWFf1s3WfccDBiL49ylgwOh6yKSuOP8ZxUkrrENK2AfN7qA2BW6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698932402; a=rsa-sha256; cv=none; b=uwBR+jWC9042TjwLvLxyWyb62+O+9exZxsiMONDNTrMs+bYbVestF2j2JVb9SZNmnL4lAR x+fz7VcV3eHY/gOxbcHjhdxO/zNmBSOxTgZGbxle5O7HCdqPGSqrn1p5paBb4psSh3ipsw XoR2KAnPaQEJd2wm4glqeQMkZQzw7S8mpNm1eC3H10L+/Y3Id1tC2Vzi67qPM2UHIHeCa0 sdDvLPN6ofJkQT3MBo89jWXF48C/BPTMJuDwZ8x+BFCw7GFhA/hkhpTZrrhERtgpZp0saz 7Vbl9NO5egqiTCVR1hL074KKW1tJRQiT6IsUwVDGIF2rmXOhAk2ExAB/71Hzrw== 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 4SLlNy0Q3gzXCC; Thu, 2 Nov 2023 13:40:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3A2De1RN027087; Thu, 2 Nov 2023 13:40:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A2De12X027081; Thu, 2 Nov 2023 13:40:01 GMT (envelope-from git) Date: Thu, 2 Nov 2023 13:40:01 GMT Message-Id: <202311021340.3A2De12X027081@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 92541c12bc25 - main - Open-code proc_set_cred_init() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 92541c12bc25c59333d7f3b0721b6b16aaff3644 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=92541c12bc25c59333d7f3b0721b6b16aaff3644 commit 92541c12bc25c59333d7f3b0721b6b16aaff3644 Author: Olivier Certner AuthorDate: 2023-09-25 08:48:49 +0000 Commit: Mark Johnston 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);