mirror of https://github.com/torvalds/linux.git
binfmt_misc: use credential guards
Use credential guards for scoped credential override with automatic restoration on scope exit. Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-8-a3e156839e7f@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
6e1d1c1fa7
commit
ff2044cd27
|
|
@ -782,8 +782,6 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
|
||||||
return PTR_ERR(e);
|
return PTR_ERR(e);
|
||||||
|
|
||||||
if (e->flags & MISC_FMT_OPEN_FILE) {
|
if (e->flags & MISC_FMT_OPEN_FILE) {
|
||||||
const struct cred *old_cred;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now that we support unprivileged binfmt_misc mounts make
|
* Now that we support unprivileged binfmt_misc mounts make
|
||||||
* sure we use the credentials that the register @file was
|
* sure we use the credentials that the register @file was
|
||||||
|
|
@ -791,9 +789,8 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
|
||||||
* didn't matter much as only a privileged process could open
|
* didn't matter much as only a privileged process could open
|
||||||
* the register file.
|
* the register file.
|
||||||
*/
|
*/
|
||||||
old_cred = override_creds(file->f_cred);
|
scoped_with_creds(file->f_cred)
|
||||||
f = open_exec(e->interpreter);
|
f = open_exec(e->interpreter);
|
||||||
revert_creds(old_cred);
|
|
||||||
if (IS_ERR(f)) {
|
if (IS_ERR(f)) {
|
||||||
pr_notice("register: failed to install interpreter file %s\n",
|
pr_notice("register: failed to install interpreter file %s\n",
|
||||||
e->interpreter);
|
e->interpreter);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue