Skip to content

Commit a1d47b2

Browse files
committed
udf: Verify symlink size before loading it
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. CC: stable@vger.kernel.org Reported-by: Carl Henrik Lunde <chlunde@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent e159332 commit a1d47b2

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎fs/udf/symlink.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ static int udf_symlink_filler(struct file *file, struct page *page)
8080
struct inode *inode = page->mapping->host;
8181
struct buffer_head *bh = NULL;
8282
unsigned char *symlink;
83-
int err = -EIO;
83+
int err;
8484
unsigned char *p = kmap(page);
8585
struct udf_inode_info *iinfo;
8686
uint32_t pos;
8787

88+
/* We don't support symlinks longer than one block */
89+
if (inode->i_size > inode->i_sb->s_blocksize) {
90+
err = -ENAMETOOLONG;
91+
goto out_unmap;
92+
}
93+
8894
iinfo = UDF_I(inode);
8995
pos = udf_block_map(inode, 0);
9096

@@ -94,8 +100,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
94100
} else {
95101
bh = sb_bread(inode->i_sb, pos);
96102

97-
if (!bh)
98-
goto out;
103+
if (!bh) {
104+
err = -EIO;
105+
goto out_unlock_inode;
106+
}
99107

100108
symlink = bh->b_data;
101109
}
@@ -109,9 +117,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
109117
unlock_page(page);
110118
return 0;
111119

112-
out:
120+
out_unlock_inode:
113121
up_read(&iinfo->i_data_sem);
114122
SetPageError(page);
123+
out_unmap:
115124
kunmap(page);
116125
unlock_page(page);
117126
return err;

0 commit comments

Comments
 (0)