From ee92f8084e6a103f5ab1deddfa19c1165041d75f Mon Sep 17 00:00:00 2001 From: Phapoom Saksri Date: Fri, 28 Feb 2025 02:41:43 +0700 Subject: [PATCH] forgor --- include/linux/cred.h | 11 +++++++++++ kernel/cred.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index a99c2d35b7be..316f4074d223 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -286,6 +286,17 @@ static inline const struct cred *get_cred(const struct cred *cred) return get_new_cred(nonconst_cred); } +static inline const struct cred *get_cred_rcu(const struct cred *cred) +{ + struct cred *nonconst_cred = (struct cred *) cred; + if (!cred) + return NULL; + if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) + return NULL; + validate_creds(cred); + return cred; +} + /** * put_cred - Release a reference to a set of credentials * @cred: The credentials to release diff --git a/kernel/cred.c b/kernel/cred.c index bd8813455823..95d14cdae814 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -303,7 +303,7 @@ const struct cred *get_task_cred(struct task_struct *task) do { cred = __task_cred((task)); BUG_ON(!cred); - } while (!atomic_inc_not_zero(&((struct cred *)cred)->usage)); + } while (!get_cred_rcu(cred)); #endif /*CONFIG_RKP_KDP*/ rcu_read_unlock(); return cred;