summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2014-12-19 12:21:47 +0100
committerLuis Henriques <luis.henriques@canonical.com>2015-01-15 10:44:53 +0000
commitec06d480b2d14d2037e8cd68a960c4959d04197c (patch)
tree32858f60df886a21ab2972edc85ea3654cd55b64 /fs
parent66c88eab4e8c6bb36afa48bf524870d957547f2e (diff)
downloadlinux-stable-ec06d480b2d14d2037e8cd68a960c4959d04197c.tar.gz
linux-stable-ec06d480b2d14d2037e8cd68a960c4959d04197c.tar.bz2
linux-stable-ec06d480b2d14d2037e8cd68a960c4959d04197c.zip
udf: Verify symlink size before loading it
commit a1d47b262952a45aae62bd49cfaf33dd76c11a2c 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: Carl Henrik Lunde <chlunde@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/udf/symlink.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
index ab94e6671849..2d0c3720e9af 100644
--- a/fs/udf/symlink.c
+++ b/fs/udf/symlink.c
@@ -99,11 +99,17 @@ static int udf_symlink_filler(struct file *file, struct page *page)
struct inode *inode = page->mapping->host;
struct buffer_head *bh = NULL;
unsigned char *symlink;
- int err = -EIO;
+ int err;
unsigned char *p = kmap(page);
struct udf_inode_info *iinfo;
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);
pos = udf_block_map(inode, 0);
@@ -113,8 +119,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
} else {
bh = sb_bread(inode->i_sb, pos);
- if (!bh)
- goto out;
+ if (!bh) {
+ err = -EIO;
+ goto out_unlock_inode;
+ }
symlink = bh->b_data;
}
@@ -130,9 +138,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
unlock_page(page);
return 0;
-out:
+out_unlock_inode:
up_read(&iinfo->i_data_sem);
SetPageError(page);
+out_unmap:
kunmap(page);
unlock_page(page);
return err;