summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-11-26 10:52:49 +0100
committerChristian Brauner <brauner@kernel.org>2024-12-02 11:25:15 +0100
commit252120f79a3010256e543a5cafdb46738345536b (patch)
treea1d0d7d15440f142534fe3f3b3722b72ded01804 /include/linux
parent40384c840ea1944d7c5a392e8975ed088ecf0b37 (diff)
parent6efbb80490a545cfd9f87ebd9225879d8cdbed93 (diff)
Merge patch series "cred: rework {override,revert}_creds()"
Christian Brauner <brauner@kernel.org> says: For the v6.13 cycle we switched overlayfs to a variant of override_creds() that doesn't take an extra reference. To this end I suggested introducing {override,revert}_creds_light() which overlayfs could use. This seems to work rather well. This series follow Linus advice and unifies the separate helpers and simply makes {override,revert}_creds() do what {override,revert}_creds_light() currently does. Caller's that really need the extra reference count can take it manually. * patches from https://lore.kernel.org/r/20241125-work-cred-v2-0-68b9d38bb5b2@kernel.org: (29 commits) cred: remove unused get_new_cred() nfsd: avoid pointless cred reference count bump cachefiles: avoid pointless cred reference count bump dns_resolver: avoid pointless cred reference count bump trace: avoid pointless cred reference count bump cgroup: avoid pointless cred reference count bump acct: avoid pointless reference count bump io_uring: avoid pointless cred reference count bump smb: avoid pointless cred reference count bump cifs: avoid pointless cred reference count bump cifs: avoid pointless cred reference count bump ovl: avoid pointless cred reference count bump open: avoid pointless cred reference count bump nfsfh: avoid pointless cred reference count bump nfs/nfs4recover: avoid pointless cred reference count bump nfs/nfs4idmap: avoid pointless reference count bump nfs/localio: avoid pointless cred reference count bumps coredump: avoid pointless cred reference count bump binfmt_misc: avoid pointless cred reference count bump aio: avoid pointless cred reference count bump ... Link: https://lore.kernel.org/r/20241125-work-cred-v2-0-68b9d38bb5b2@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/cred.h26
1 files changed, 5 insertions, 21 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h
index e4a3155fe409..360f5fd3854b 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -155,8 +155,6 @@ extern struct cred *prepare_creds(void);
extern struct cred *prepare_exec_creds(void);
extern int commit_creds(struct cred *);
extern void abort_creds(struct cred *);
-extern const struct cred *override_creds(const struct cred *);
-extern void revert_creds(const struct cred *);
extern struct cred *prepare_kernel_cred(struct task_struct *);
extern int set_security_override(struct cred *, u32);
extern int set_security_override_from_ctx(struct cred *, const char *);
@@ -172,12 +170,7 @@ static inline bool cap_ambient_invariant_ok(const struct cred *cred)
cred->cap_inheritable));
}
-/*
- * Override creds without bumping reference count. Caller must ensure
- * reference remains valid or has taken reference. Almost always not the
- * interface you want. Use override_creds()/revert_creds() instead.
- */
-static inline const struct cred *override_creds_light(const struct cred *override_cred)
+static inline const struct cred *override_creds(const struct cred *override_cred)
{
const struct cred *old = current->cred;
@@ -185,9 +178,12 @@ static inline const struct cred *override_creds_light(const struct cred *overrid
return old;
}
-static inline void revert_creds_light(const struct cred *revert_cred)
+static inline const struct cred *revert_creds(const struct cred *revert_cred)
{
+ const struct cred *override_cred = current->cred;
+
rcu_assign_pointer(current->cred, revert_cred);
+ return override_cred;
}
/**
@@ -205,18 +201,6 @@ static inline struct cred *get_new_cred_many(struct cred *cred, int nr)
}
/**
- * get_new_cred - Get a reference on a new set of credentials
- * @cred: The new credentials to reference
- *
- * Get a reference on the specified set of new credentials. The caller must
- * release the reference.
- */
-static inline struct cred *get_new_cred(struct cred *cred)
-{
- return get_new_cred_many(cred, 1);
-}
-
-/**
* get_cred_many - Get references on a set of credentials
* @cred: The credentials to reference
* @nr: Number of references to acquire