This commit is contained in:
Phapoom Saksri 2025-02-28 02:41:43 +07:00
parent 7df5f247bc
commit ee92f8084e
2 changed files with 12 additions and 1 deletions

View file

@ -286,6 +286,17 @@ static inline const struct cred *get_cred(const struct cred *cred)
return get_new_cred(nonconst_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 * put_cred - Release a reference to a set of credentials
* @cred: The credentials to release * @cred: The credentials to release

View file

@ -303,7 +303,7 @@ const struct cred *get_task_cred(struct task_struct *task)
do { do {
cred = __task_cred((task)); cred = __task_cred((task));
BUG_ON(!cred); BUG_ON(!cred);
} while (!atomic_inc_not_zero(&((struct cred *)cred)->usage)); } while (!get_cred_rcu(cred));
#endif /*CONFIG_RKP_KDP*/ #endif /*CONFIG_RKP_KDP*/
rcu_read_unlock(); rcu_read_unlock();
return cred; return cred;