Commit 7f6c411c authored by Al Viro's avatar Al Viro

hostfs: fix memory handling in follow_link()

1) argument should not be freed in any case - the caller already has
it as ->s_fs_info (and uses it a lot afterwards)
2) allocate readlink buffer with kmalloc() - the caller has no way
to tell if it's got that (on absolute symlink) or a result of
kasprintf().  Sure, for SLAB and SLUB kfree() works on results of
kmem_cache_alloc(), but that's not documented anywhere, might change
in the future *and* is already not true for SLOB.

Fixes: 52b209f7 ("get rid of hostfs_read_inode()")
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a38fd874
...@@ -144,7 +144,7 @@ static char *follow_link(char *link) ...@@ -144,7 +144,7 @@ static char *follow_link(char *link)
char *name, *resolved, *end; char *name, *resolved, *end;
int n; int n;
name = __getname(); name = kmalloc(PATH_MAX, GFP_KERNEL);
if (!name) { if (!name) {
n = -ENOMEM; n = -ENOMEM;
goto out_free; goto out_free;
...@@ -173,12 +173,11 @@ static char *follow_link(char *link) ...@@ -173,12 +173,11 @@ static char *follow_link(char *link)
goto out_free; goto out_free;
} }
__putname(name); kfree(name);
kfree(link);
return resolved; return resolved;
out_free: out_free:
__putname(name); kfree(name);
return ERR_PTR(n); return ERR_PTR(n);
} }
......
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