sev-dev: use prepare credential guard

Use the prepare credential guard for allocating a new set of
credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-3-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner
2025-11-03 15:57:29 +01:00
parent 4c5941ca11
commit 89c545e29e

View File

@@ -261,22 +261,22 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t m
{
struct path root __free(path_put) = {};
struct file *fp;
struct cred *cred;
const struct cred *old_cred;
task_lock(&init_task);
get_fs_root(init_task.fs, &root);
task_unlock(&init_task);
cred = prepare_creds();
CLASS(prepare_creds, cred)();
if (!cred)
return ERR_PTR(-ENOMEM);
cred->fsuid = GLOBAL_ROOT_UID;
old_cred = override_creds(cred);
fp = file_open_root(&root, filename, flags, mode);
put_cred(revert_creds(old_cred));
revert_creds(old_cred);
return fp;
}