Commit 92eaa565 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

exec: kill ->load_binary != NULL check in search_binary_handler()

search_binary_handler() checks ->load_binary != NULL for no reason, this
method should be always defined.  Turn this check into WARN_ON() and move
it into __register_binfmt().

Also, kill the function pointer.  The current code looks confusing, as if
->load_binary can go away after read_unlock(&binfmt_lock).  But we rely on
module_get(fmt->module), this fmt can't be changed or unregistered,
otherwise this code is buggy anyway.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Zach Levis <zml@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 52f14282
...@@ -74,6 +74,8 @@ static DEFINE_RWLOCK(binfmt_lock); ...@@ -74,6 +74,8 @@ static DEFINE_RWLOCK(binfmt_lock);
void __register_binfmt(struct linux_binfmt * fmt, int insert) void __register_binfmt(struct linux_binfmt * fmt, int insert)
{ {
BUG_ON(!fmt); BUG_ON(!fmt);
if (WARN_ON(!fmt->load_binary))
return;
write_lock(&binfmt_lock); write_lock(&binfmt_lock);
insert ? list_add(&fmt->lh, &formats) : insert ? list_add(&fmt->lh, &formats) :
list_add_tail(&fmt->lh, &formats); list_add_tail(&fmt->lh, &formats);
...@@ -1389,14 +1391,11 @@ int search_binary_handler(struct linux_binprm *bprm) ...@@ -1389,14 +1391,11 @@ int search_binary_handler(struct linux_binprm *bprm)
for (try=0; try<2; try++) { for (try=0; try<2; try++) {
read_lock(&binfmt_lock); read_lock(&binfmt_lock);
list_for_each_entry(fmt, &formats, lh) { list_for_each_entry(fmt, &formats, lh) {
int (*fn)(struct linux_binprm *) = fmt->load_binary;
if (!fn)
continue;
if (!try_module_get(fmt->module)) if (!try_module_get(fmt->module))
continue; continue;
read_unlock(&binfmt_lock); read_unlock(&binfmt_lock);
bprm->recursion_depth++; bprm->recursion_depth++;
retval = fn(bprm); retval = fmt->load_binary(bprm);
bprm->recursion_depth--; bprm->recursion_depth--;
if (retval >= 0) { if (retval >= 0) {
put_binfmt(fmt); put_binfmt(fmt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment