Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 157195
b: refs/heads/master
c: a2a8474
h: refs/heads/master
i:
  157193: 0f7ce9b
  157191: e30994a
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Sep 5, 2009
1 parent c99312c commit 48ac2c0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 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: dd5d241ea955006122d76af88af87de73fec25b4
refs/heads/master: a2a8474c3fff88d8dd52d05cb450563fb26fd26c
17 changes: 4 additions & 13 deletions trunk/fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,20 +1485,15 @@ int compat_do_execve(char * filename,
if (!bprm)
goto out_files;

retval = -ERESTARTNOINTR;
if (mutex_lock_interruptible(&current->cred_guard_mutex))
retval = prepare_bprm_creds(bprm);
if (retval)
goto out_free;
current->in_execve = 1;

retval = -ENOMEM;
bprm->cred = prepare_exec_creds();
if (!bprm->cred)
goto out_unlock;

retval = check_unsafe_exec(bprm);
if (retval < 0)
goto out_unlock;
goto out_free;
clear_in_exec = retval;
current->in_execve = 1;

file = open_exec(filename);
retval = PTR_ERR(file);
Expand Down Expand Up @@ -1547,7 +1542,6 @@ int compat_do_execve(char * filename,
/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
mutex_unlock(&current->cred_guard_mutex);
acct_update_integrals(current);
free_bprm(bprm);
if (displaced)
Expand All @@ -1567,10 +1561,7 @@ int compat_do_execve(char * filename,
out_unmark:
if (clear_in_exec)
current->fs->in_exec = 0;

out_unlock:
current->in_execve = 0;
mutex_unlock(&current->cred_guard_mutex);

out_free:
free_bprm(bprm);
Expand Down
63 changes: 38 additions & 25 deletions trunk/fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,35 @@ int flush_old_exec(struct linux_binprm * bprm)

EXPORT_SYMBOL(flush_old_exec);

/*
* Prepare credentials and lock ->cred_guard_mutex.
* install_exec_creds() commits the new creds and drops the lock.
* Or, if exec fails before, free_bprm() should release ->cred and
* and unlock.
*/
int prepare_bprm_creds(struct linux_binprm *bprm)
{
if (mutex_lock_interruptible(&current->cred_guard_mutex))
return -ERESTARTNOINTR;

bprm->cred = prepare_exec_creds();
if (likely(bprm->cred))
return 0;

mutex_unlock(&current->cred_guard_mutex);
return -ENOMEM;
}

void free_bprm(struct linux_binprm *bprm)
{
free_arg_pages(bprm);
if (bprm->cred) {
mutex_unlock(&current->cred_guard_mutex);
abort_creds(bprm->cred);
}
kfree(bprm);
}

/*
* install the new credentials for this executable
*/
Expand All @@ -1024,12 +1053,13 @@ void install_exec_creds(struct linux_binprm *bprm)

commit_creds(bprm->cred);
bprm->cred = NULL;

/* cred_guard_mutex must be held at least to this point to prevent
/*
* cred_guard_mutex must be held at least to this point to prevent
* ptrace_attach() from altering our determination of the task's
* credentials; any time after this it may be unlocked */

* credentials; any time after this it may be unlocked.
*/
security_bprm_committed_creds(bprm);
mutex_unlock(&current->cred_guard_mutex);
}
EXPORT_SYMBOL(install_exec_creds);

Expand Down Expand Up @@ -1246,14 +1276,6 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)

EXPORT_SYMBOL(search_binary_handler);

void free_bprm(struct linux_binprm *bprm)
{
free_arg_pages(bprm);
if (bprm->cred)
abort_creds(bprm->cred);
kfree(bprm);
}

/*
* sys_execve() executes a new program.
*/
Expand All @@ -1277,20 +1299,15 @@ int do_execve(char * filename,
if (!bprm)
goto out_files;

retval = -ERESTARTNOINTR;
if (mutex_lock_interruptible(&current->cred_guard_mutex))
retval = prepare_bprm_creds(bprm);
if (retval)
goto out_free;
current->in_execve = 1;

retval = -ENOMEM;
bprm->cred = prepare_exec_creds();
if (!bprm->cred)
goto out_unlock;

retval = check_unsafe_exec(bprm);
if (retval < 0)
goto out_unlock;
goto out_free;
clear_in_exec = retval;
current->in_execve = 1;

file = open_exec(filename);
retval = PTR_ERR(file);
Expand Down Expand Up @@ -1340,7 +1357,6 @@ int do_execve(char * filename,
/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
mutex_unlock(&current->cred_guard_mutex);
acct_update_integrals(current);
free_bprm(bprm);
if (displaced)
Expand All @@ -1360,10 +1376,7 @@ int do_execve(char * filename,
out_unmark:
if (clear_in_exec)
current->fs->in_exec = 0;

out_unlock:
current->in_execve = 0;
mutex_unlock(&current->cred_guard_mutex);

out_free:
free_bprm(bprm);
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ extern int setup_arg_pages(struct linux_binprm * bprm,
int executable_stack);
extern int bprm_mm_init(struct linux_binprm *bprm);
extern int copy_strings_kernel(int argc,char ** argv,struct linux_binprm *bprm);
extern int prepare_bprm_creds(struct linux_binprm *bprm);
extern void install_exec_creds(struct linux_binprm *bprm);
extern void do_coredump(long signr, int exit_code, struct pt_regs *regs);
extern int set_binfmt(struct linux_binfmt *new);
Expand Down

0 comments on commit 48ac2c0

Please sign in to comment.