Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 346461
b: refs/heads/master
c: d740269
h: refs/heads/master
i:
  346459: 9c43069
v: v3
  • Loading branch information
Kees Cook authored and Linus Torvalds committed Dec 18, 2012
1 parent b2339b7 commit 066a0b1
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8d238027b87e654be552eabdf492042a34c5c300
refs/heads/master: d740269867021faf4ce38a449353d2b986c34a67
1 change: 0 additions & 1 deletion trunk/fs/binfmt_em86.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static int load_em86(struct linux_binprm *bprm)
return -ENOEXEC;
}

bprm->recursion_depth++; /* Well, the bang-shell is implicit... */
allow_write_access(bprm->file);
fput(bprm->file);
bprm->file = NULL;
Expand Down
6 changes: 0 additions & 6 deletions trunk/fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
if (!enabled)
goto _ret;

retval = -ENOEXEC;
if (bprm->recursion_depth > BINPRM_MAX_RECURSION)
goto _ret;

/* to keep locking time low, we copy the interpreter string */
read_lock(&entries_lock);
fmt = check_file(bprm);
Expand Down Expand Up @@ -197,8 +193,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
if (retval < 0)
goto _error;

bprm->recursion_depth++;

retval = search_binary_handler(bprm);
if (retval < 0)
goto _error;
Expand Down
4 changes: 1 addition & 3 deletions trunk/fs/binfmt_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ static int load_script(struct linux_binprm *bprm)
char interp[BINPRM_BUF_SIZE];
int retval;

if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') ||
(bprm->recursion_depth > BINPRM_MAX_RECURSION))
if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!'))
return -ENOEXEC;
/*
* This section does the #! interpretation.
* Sorta complicated, but hopefully it will work. -TYT
*/

bprm->recursion_depth++;
allow_write_access(bprm->file);
fput(bprm->file);
bprm->file = NULL;
Expand Down
10 changes: 5 additions & 5 deletions trunk/fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,10 @@ int search_binary_handler(struct linux_binprm *bprm)
struct linux_binfmt *fmt;
pid_t old_pid, old_vpid;

/* This allows 4 levels of binfmt rewrites before failing hard. */
if (depth > 5)
return -ELOOP;

retval = security_bprm_check(bprm);
if (retval)
return retval;
Expand All @@ -1380,12 +1384,8 @@ int search_binary_handler(struct linux_binprm *bprm)
if (!try_module_get(fmt->module))
continue;
read_unlock(&binfmt_lock);
bprm->recursion_depth = depth + 1;
retval = fn(bprm);
/*
* Restore the depth counter to its starting value
* in this call, so we don't have to rely on every
* load_binary function to restore it on return.
*/
bprm->recursion_depth = depth;
if (retval >= 0) {
if (depth == 0) {
Expand Down
2 changes: 0 additions & 2 deletions trunk/include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct linux_binprm {
#define BINPRM_FLAGS_EXECFD_BIT 1
#define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)

#define BINPRM_MAX_RECURSION 4

/* Function parameter for binfmt->coredump */
struct coredump_params {
siginfo_t *siginfo;
Expand Down

0 comments on commit 066a0b1

Please sign in to comment.