Merge tag 'at91-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/nferre/linux...
[cascardo/linux.git] / fs / exec.c
index a2b42a9..7302b75 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1372,18 +1372,23 @@ int search_binary_handler(struct linux_binprm *bprm)
                read_unlock(&binfmt_lock);
                bprm->recursion_depth++;
                retval = fmt->load_binary(bprm);
+               read_lock(&binfmt_lock);
+               put_binfmt(fmt);
                bprm->recursion_depth--;
-               if (retval >= 0 || retval != -ENOEXEC ||
-                   bprm->mm == NULL || bprm->file == NULL) {
-                       put_binfmt(fmt);
+               if (retval < 0 && !bprm->mm) {
+                       /* we got to flush_old_exec() and failed after it */
+                       read_unlock(&binfmt_lock);
+                       force_sigsegv(SIGSEGV, current);
+                       return retval;
+               }
+               if (retval != -ENOEXEC || !bprm->file) {
+                       read_unlock(&binfmt_lock);
                        return retval;
                }
-               read_lock(&binfmt_lock);
-               put_binfmt(fmt);
        }
        read_unlock(&binfmt_lock);
 
-       if (need_retry && retval == -ENOEXEC) {
+       if (need_retry) {
                if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
                    printable(bprm->buf[2]) && printable(bprm->buf[3]))
                        return retval;