hostfs: fix memory handling in follow_link()
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 25 Mar 2021 18:12:34 +0000 (14:12 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Apr 2021 06:42:06 +0000 (08:42 +0200)
commite5a3449ce16a24bc53c9f41cf36418abe6c27a72
tree7a2292ce83b892d81547799d265739ba285ad630
parent3cc4db1213a44aa5d7838dfb22ce78281da1f7cc
hostfs: fix memory handling in follow_link()

[ Upstream commit 7f6c411c9b50cfab41cc798e003eff27608c7016 ]

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: 52b209f7b848 ("get rid of hostfs_read_inode()")
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/hostfs/hostfs_kern.c