Skip to content

Commit ebd09ab

Browse files
duanegAl Viro
authored andcommitted
vfs: ensure page symlinks are NUL-terminated
On-disk data corruption could cause a page link to have its i_size set to PAGE_SIZE (or a multiple thereof) and its contents all non-NUL. NUL-terminate the link name to ensure this doesn't cause further problems for the kernel. Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Duane Griffin <duaneg@dghda.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 0351468 commit ebd09ab

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎fs/namei.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,13 +2786,16 @@ int vfs_follow_link(struct nameidata *nd, const char *link)
27862786
/* get the link contents into pagecache */
27872787
static char *page_getlink(struct dentry * dentry, struct page **ppage)
27882788
{
2789-
struct page * page;
2789+
char *kaddr;
2790+
struct page *page;
27902791
struct address_space *mapping = dentry->d_inode->i_mapping;
27912792
page = read_mapping_page(mapping, 0, NULL);
27922793
if (IS_ERR(page))
27932794
return (char*)page;
27942795
*ppage = page;
2795-
return kmap(page);
2796+
kaddr = kmap(page);
2797+
nd_terminate_link(kaddr, dentry->d_inode->i_size, PAGE_SIZE - 1);
2798+
return kaddr;
27962799
}
27972800

27982801
int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)

0 commit comments

Comments
 (0)