@@ -190,6 +190,13 @@ static inline void revert_creds_light(const struct cred *revert_cred)
rcu_assign_pointer(current->cred, revert_cred);
}
+DEFINE_LOCK_GUARD_1(__cred, struct cred,
+ _T->lock = (struct cred *)override_creds_light(_T->lock),
+ revert_creds_light(_T->lock));
+
+#define cred_guard(_cred) guard(__cred)(((struct cred *)_cred))
+#define cred_scoped_guard(_cred) scoped_guard(__cred, ((struct cred *)_cred))
+
/**
* get_new_cred_many - Get references on a new set of credentials
* @cred: The new credentials to reference
These helpers will make it less error prone to use override_creds_light()/revert_creds_light(). They make sure that they are paired. As they use the _light() version of the credentials override/revert operations, they should only be used when there are guarantees that the lifetime of the credentials in question is not modified during the critical section. Suggested-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com> --- include/linux/cred.h | 7 +++++++ 1 file changed, 7 insertions(+)