Skip to content

Commit ff2044c

Browse files
committed
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>
1 parent 6e1d1c1 commit ff2044c

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

fs/binfmt_misc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,18 +782,15 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
782782
return PTR_ERR(e);
783783

784784
if (e->flags & MISC_FMT_OPEN_FILE) {
785-
const struct cred *old_cred;
786-
787785
/*
788786
* Now that we support unprivileged binfmt_misc mounts make
789787
* sure we use the credentials that the register @file was
790788
* opened with to also open the interpreter. Before that this
791789
* didn't matter much as only a privileged process could open
792790
* the register file.
793791
*/
794-
old_cred = override_creds(file->f_cred);
795-
f = open_exec(e->interpreter);
796-
revert_creds(old_cred);
792+
scoped_with_creds(file->f_cred)
793+
f = open_exec(e->interpreter);
797794
if (IS_ERR(f)) {
798795
pr_notice("register: failed to install interpreter file %s\n",
799796
e->interpreter);

0 commit comments

Comments
 (0)