mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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:
@@ -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)
|
static struct file *open_file_as_root(const char *filename, int flags, umode_t mode)
|
||||||
{
|
{
|
||||||
struct path root __free(path_put) = {};
|
struct path root __free(path_put) = {};
|
||||||
struct file *fp;
|
|
||||||
const struct cred *old_cred;
|
|
||||||
|
|
||||||
task_lock(&init_task);
|
task_lock(&init_task);
|
||||||
get_fs_root(init_task.fs, &root);
|
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);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
cred->fsuid = GLOBAL_ROOT_UID;
|
cred->fsuid = GLOBAL_ROOT_UID;
|
||||||
old_cred = override_creds(cred);
|
|
||||||
|
|
||||||
fp = file_open_root(&root, filename, flags, mode);
|
scoped_with_creds(cred)
|
||||||
|
return file_open_root(&root, filename, flags, mode);
|
||||||
revert_creds(old_cred);
|
|
||||||
|
|
||||||
return fp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sev_read_init_ex_file(void)
|
static int sev_read_init_ex_file(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user