vfs: ensure page symlinks are NUL-terminated

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Wednesday, December 31, 2008 - 5:59 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=ebd09a...
Commit:     ebd09abbd9699f328165aee50a070403fbf55a37
Parent:     035146851cfa2fe24c1d9dc7637bb009ad06b2f7
Author:     Duane Griffin <duaneg@dghda.com>
AuthorDate: Fri Dec 19 20:47:12 2008 +0000
Committer:  Al Viro <viro@zeniv.linux.org.uk>
CommitDate: Wed Dec 31 18:07:39 2008 -0500

    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>
---
 fs/namei.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index ab441af..9ed5e28 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2786,13 +2786,16 @@ int vfs_follow_link(struct nameidata *nd, const char *link)
 /* get the link contents into pagecache */
 static char *page_getlink(struct dentry * dentry, struct page **ppage)
 {
-	struct page * page;
+	char *kaddr;
+	struct page *page;
 	struct address_space *mapping = dentry->d_inode->i_mapping;
 	page = read_mapping_page(mapping, 0, NULL);
 	if (IS_ERR(page))
 		return (char*)page;
 	*ppage = page;
-	return kmap(page);
+	kaddr = kmap(page);
+	nd_terminate_link(kaddr, dentry->d_inode->i_size, PAGE_SIZE - 1);
+	return kaddr;
 }
 
 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
vfs: ensure page symlinks are NUL-terminated, Linux Kernel Mailing ..., (Wed Dec 31, 5:59 pm)