Commit 2bf2e3b9 authored by Jan Kara's avatar Jan Kara Committed by Jiri Slaby

udf: Verify symlink size before loading it

commit a1d47b26 upstream.

UDF specification allows arbitrarily large symlinks. However we support
only symlinks at most one block large. Check the length of the symlink
so that we don't access memory beyond end of the symlink block.
Reported-by: default avatarCarl Henrik Lunde <chlunde@gmail.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 259c1c87
...@@ -80,11 +80,17 @@ static int udf_symlink_filler(struct file *file, struct page *page) ...@@ -80,11 +80,17 @@ static int udf_symlink_filler(struct file *file, struct page *page)
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
unsigned char *symlink; unsigned char *symlink;
int err = -EIO; int err;
unsigned char *p = kmap(page); unsigned char *p = kmap(page);
struct udf_inode_info *iinfo; struct udf_inode_info *iinfo;
uint32_t pos; uint32_t pos;
/* We don't support symlinks longer than one block */
if (inode->i_size > inode->i_sb->s_blocksize) {
err = -ENAMETOOLONG;
goto out_unmap;
}
iinfo = UDF_I(inode); iinfo = UDF_I(inode);
pos = udf_block_map(inode, 0); pos = udf_block_map(inode, 0);
...@@ -94,8 +100,10 @@ static int udf_symlink_filler(struct file *file, struct page *page) ...@@ -94,8 +100,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
} else { } else {
bh = sb_bread(inode->i_sb, pos); bh = sb_bread(inode->i_sb, pos);
if (!bh) if (!bh) {
goto out; err = -EIO;
goto out_unlock_inode;
}
symlink = bh->b_data; symlink = bh->b_data;
} }
...@@ -109,9 +117,10 @@ static int udf_symlink_filler(struct file *file, struct page *page) ...@@ -109,9 +117,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
unlock_page(page); unlock_page(page);
return 0; return 0;
out: out_unlock_inode:
up_read(&iinfo->i_data_sem); up_read(&iinfo->i_data_sem);
SetPageError(page); SetPageError(page);
out_unmap:
kunmap(page); kunmap(page);
unlock_page(page); unlock_page(page);
return err; return err;
......
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