summaryrefslogtreecommitdiff
path: root/include/linux/cred.h
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@intel.com>2024-11-06 16:57:17 -0800
committerAmir Goldstein <amir73il@gmail.com>2024-11-11 10:45:04 +0100
commit49dffdfde462c7823de6ed882f71ce233aaeba63 (patch)
tree494b874da2804e7ec81ebd1433c1da5e6246c694 /include/linux/cred.h
parent48b50624aec454ce0fa8f78ef96e2f43bc0be495 (diff)
cred: Add a light version of override/revert_creds()
Add a light version of override/revert_creds(), this should only be used when the credentials in question will outlive the critical section and the critical section doesn't change the ->usage of the credentials. Suggested-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Diffstat (limited to 'include/linux/cred.h')
-rw-r--r--include/linux/cred.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 2976f534a7a3..e4a3155fe409 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -172,6 +172,24 @@ 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)
+{
+ const struct cred *old = current->cred;
+
+ rcu_assign_pointer(current->cred, override_cred);
+ return old;
+}
+
+static inline void revert_creds_light(const struct cred *revert_cred)
+{
+ rcu_assign_pointer(current->cred, revert_cred);
+}
+
/**
* get_new_cred_many - Get references on a new set of credentials
* @cred: The new credentials to reference