exec: binfmt_misc: fix race between load_misc_binary() and kill_node()
[sfrench/cifs-2.6.git] / fs / binfmt_misc.c
index babfe7bd56f066b0d699dd22520a1b74ef3f6125..f5f8c2541790494a2db9812aafe3df243c8952ac 100644 (file)
@@ -138,20 +138,23 @@ static int load_misc_binary(struct linux_binprm *bprm)
 
        retval = -ENOEXEC;
        if (!enabled)
-               goto ret;
+               return retval;
 
        /* to keep locking time low, we copy the interpreter string */
        read_lock(&entries_lock);
        fmt = check_file(bprm);
-       if (fmt)
+       if (fmt) {
+               dget(fmt->dentry);
                strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
+       }
        read_unlock(&entries_lock);
        if (!fmt)
-               goto ret;
+               return retval;
 
        /* Need to be able to load the file after exec */
+       retval = -ENOENT;
        if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
-               return -ENOENT;
+               goto ret;
 
        if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) {
                retval = remove_arg_zero(bprm);
@@ -238,6 +241,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
                goto error;
 
 ret:
+       dput(fmt->dentry);
        return retval;
 error:
        if (fd_binary > 0)