Skip to content

Commit

Permalink
let path_init() failures treated the same way as subsequent link_path…
Browse files Browse the repository at this point in the history
…_walk()

As it is, path_lookupat() and path_mounpoint() might end up leaking struct file
reference in some cases.

Spotted-by: Eric Biggers <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 12, 2014
1 parent 24dff96 commit 115cbfd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ static int path_lookupat(int dfd, const char *name,
err = path_init(dfd, name, flags | LOOKUP_PARENT, nd, &base);

if (unlikely(err))
return err;
goto out;

current->total_link_count = 0;
err = link_path_walk(name, nd);
Expand Down Expand Up @@ -1982,6 +1982,7 @@ static int path_lookupat(int dfd, const char *name,
}
}

out:
if (base)
fput(base);

Expand Down Expand Up @@ -2301,7 +2302,7 @@ path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags

err = path_init(dfd, name, flags | LOOKUP_PARENT, &nd, &base);
if (unlikely(err))
return err;
goto out;

current->total_link_count = 0;
err = link_path_walk(name, &nd);
Expand Down

0 comments on commit 115cbfd

Please sign in to comment.