sev-dev: use override credential guards

Use override credential guards for scoped credential override with
automatic restoration on scope exit.

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

View File

@@ -260,8 +260,6 @@ static int sev_cmd_buffer_len(int cmd)
static struct file *open_file_as_root(const char *filename, int flags, umode_t mode)
{
struct path root __free(path_put) = {};
struct file *fp;
const struct cred *old_cred;
task_lock(&init_task);
get_fs_root(init_task.fs, &root);
@@ -272,13 +270,9 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t m
return ERR_PTR(-ENOMEM);
cred->fsuid = GLOBAL_ROOT_UID;
old_cred = override_creds(cred);
fp = file_open_root(&root, filename, flags, mode);
revert_creds(old_cred);
return fp;
scoped_with_creds(cred)
return file_open_root(&root, filename, flags, mode);
}
static int sev_read_init_ex_file(void)