Skip to content

Commit 1b5d783

Browse files
author
Al Viro
committed
consolidate BINPRM_FLAGS_ENFORCE_NONDUMP handling
new helper: would_dump(bprm, file). Checks if we are allowed to read the file and if we are not - sets ENFORCE_NODUMP. Exported, used in places that previously open-coded the same logics. Signed-off-by: Al Viro <[email protected]>
1 parent 78f32a9 commit 1b5d783

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

fs/binfmt_elf.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
668668
* mm->dumpable = 0 regardless of the interpreter's
669669
* permissions.
670670
*/
671-
if (file_permission(interpreter, MAY_READ) < 0)
672-
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
671+
would_dump(bprm, interpreter);
673672

674673
retval = kernel_read(interpreter, 0, bprm->buf,
675674
BINPRM_BUF_SIZE);

fs/binfmt_elf_fdpic.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
245245
* mm->dumpable = 0 regardless of the interpreter's
246246
* permissions.
247247
*/
248-
if (file_permission(interpreter, MAY_READ) < 0)
249-
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
248+
would_dump(bprm, interpreter);
250249

251250
retval = kernel_read(interpreter, 0, bprm->buf,
252251
BINPRM_BUF_SIZE);

fs/binfmt_misc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
149149

150150
/* if the binary is not readable than enforce mm->dumpable=0
151151
regardless of the interpreter's permissions */
152-
if (file_permission(bprm->file, MAY_READ))
153-
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
152+
would_dump(bprm, bprm->file);
154153

155154
allow_write_access(bprm->file);
156155
bprm->file = NULL;

fs/exec.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,13 @@ int flush_old_exec(struct linux_binprm * bprm)
11051105
}
11061106
EXPORT_SYMBOL(flush_old_exec);
11071107

1108+
void would_dump(struct linux_binprm *bprm, struct file *file)
1109+
{
1110+
if (inode_permission(file->f_path.dentry->d_inode, MAY_READ) < 0)
1111+
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
1112+
}
1113+
EXPORT_SYMBOL(would_dump);
1114+
11081115
void setup_new_exec(struct linux_binprm * bprm)
11091116
{
11101117
int i, ch;
@@ -1144,9 +1151,10 @@ void setup_new_exec(struct linux_binprm * bprm)
11441151
if (bprm->cred->uid != current_euid() ||
11451152
bprm->cred->gid != current_egid()) {
11461153
current->pdeath_signal = 0;
1147-
} else if (file_permission(bprm->file, MAY_READ) ||
1148-
bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP) {
1149-
set_dumpable(current->mm, suid_dumpable);
1154+
} else {
1155+
would_dump(bprm, bprm->file);
1156+
if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP)
1157+
set_dumpable(current->mm, suid_dumpable);
11501158
}
11511159

11521160
/*

include/linux/binfmts.h

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extern int __must_check remove_arg_zero(struct linux_binprm *);
111111
extern int search_binary_handler(struct linux_binprm *, struct pt_regs *);
112112
extern int flush_old_exec(struct linux_binprm * bprm);
113113
extern void setup_new_exec(struct linux_binprm * bprm);
114+
extern void would_dump(struct linux_binprm *, struct file *);
114115

115116
extern int suid_dumpable;
116117
#define SUID_DUMP_DISABLE 0 /* No setuid dumping */

0 commit comments

Comments
 (0)