Skip to content

Commit

Permalink
exec: fix set_binfmt() vs sys_delete_module() race
Browse files Browse the repository at this point in the history
sys_delete_module() can set MODULE_STATE_GOING after
search_binary_handler() does try_module_get().  In this case
set_binfmt()->try_module_get() fails but since none of the callers
check the returned error, the task will run with the wrong old
->binfmt.

The proper fix should change all ->load_binary() methods, but we can
rely on fact that the caller must hold a reference to binfmt->module
and use __module_get() which never fails.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Rusty Russell <[email protected]>
Cc: Hiroshi Shimamoto <[email protected]>
Cc: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Sep 24, 2009
1 parent 61be228 commit 964ee7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,18 +1395,14 @@ int do_execve(char * filename,
return retval;
}

int set_binfmt(struct linux_binfmt *new)
void set_binfmt(struct linux_binfmt *new)
{
struct linux_binfmt *old = current->binfmt;
if (current->binfmt)
module_put(current->binfmt->module);

if (new) {
if (!try_module_get(new->module))
return -1;
}
current->binfmt = new;
if (old)
module_put(old->module);
return 0;
if (new)
__module_get(new->module);
}

EXPORT_SYMBOL(set_binfmt);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ 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);
extern void set_binfmt(struct linux_binfmt *new);
extern void free_bprm(struct linux_binprm *);

#endif /* __KERNEL__ */
Expand Down

0 comments on commit 964ee7d

Please sign in to comment.