diff options
author | Oleg Nesterov <oleg@redhat.com> | 2009-09-23 18:56:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-24 10:21:01 -0400 |
commit | 964ee7df90d799e38fb1556c57cd5c45fc736436 (patch) | |
tree | 58ae7325f80394cb86409d5876c710376dde8e1a /fs/exec.c | |
parent | 61be228a06dc6e8662f30e89eda3c12083c1f379 (diff) |
exec: fix set_binfmt() vs sys_delete_module() race
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 <oleg@redhat.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -1395,18 +1395,14 @@ out_ret: | |||
1395 | return retval; | 1395 | return retval; |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | int set_binfmt(struct linux_binfmt *new) | 1398 | void set_binfmt(struct linux_binfmt *new) |
1399 | { | 1399 | { |
1400 | struct linux_binfmt *old = current->binfmt; | 1400 | if (current->binfmt) |
1401 | module_put(current->binfmt->module); | ||
1401 | 1402 | ||
1402 | if (new) { | ||
1403 | if (!try_module_get(new->module)) | ||
1404 | return -1; | ||
1405 | } | ||
1406 | current->binfmt = new; | 1403 | current->binfmt = new; |
1407 | if (old) | 1404 | if (new) |
1408 | module_put(old->module); | 1405 | __module_get(new->module); |
1409 | return 0; | ||
1410 | } | 1406 | } |
1411 | 1407 | ||
1412 | EXPORT_SYMBOL(set_binfmt); | 1408 | EXPORT_SYMBOL(set_binfmt); |