aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorPhillip Lougher <phillip@lougher.demon.co.uk>2011-05-23 23:33:34 -0400
committerPhillip Lougher <phillip@lougher.demon.co.uk>2011-05-25 13:21:33 -0400
commit1cac63cc9b2ff0d16ab2d16232b1a6ee8676a47b (patch)
tree31ee36dac4a1b351c153058ffa0799a959ba0272 /fs
parentac51a0a7139aa93bf1176b701c86fa3d2bdf6106 (diff)
Squashfs: add sanity checks to fragment reading at mount time
Fsfuzzer generates corrupted filesystems which throw a warn_on in kmalloc. One of these is due to a corrupted superblock fragments field. Fix this by checking that the number of bytes to be read (and allocated) does not extend into the next filesystem structure. Also add a couple of other sanity checks of the mount-time fragment table structures. Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/squashfs/fragment.c24
-rw-r--r--fs/squashfs/squashfs.h2
-rw-r--r--fs/squashfs/super.c3
3 files changed, 25 insertions, 4 deletions
diff --git a/fs/squashfs/fragment.c b/fs/squashfs/fragment.c
index 567093db5870..bfd707569ab7 100644
--- a/fs/squashfs/fragment.c
+++ b/fs/squashfs/fragment.c
@@ -71,9 +71,29 @@ int squashfs_frag_lookup(struct super_block *sb, unsigned int fragment,
71 * Read the uncompressed fragment lookup table indexes off disk into memory 71 * Read the uncompressed fragment lookup table indexes off disk into memory
72 */ 72 */
73__le64 *squashfs_read_fragment_index_table(struct super_block *sb, 73__le64 *squashfs_read_fragment_index_table(struct super_block *sb,
74 u64 fragment_table_start, unsigned int fragments) 74 u64 fragment_table_start, u64 next_table, unsigned int fragments)
75{ 75{
76 unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments); 76 unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments);
77 __le64 *table;
77 78
78 return squashfs_read_table(sb, fragment_table_start, length); 79 /*
80 * Sanity check, length bytes should not extend into the next table -
81 * this check also traps instances where fragment_table_start is
82 * incorrectly larger than the next table start
83 */
84 if (fragment_table_start + length > next_table)
85 return ERR_PTR(-EINVAL);
86
87 table = squashfs_read_table(sb, fragment_table_start, length);
88
89 /*
90 * table[0] points to the first fragment table metadata block, this
91 * should be less than fragment_table_start
92 */
93 if (!IS_ERR(table) && table[0] >= fragment_table_start) {
94 kfree(table);
95 return ERR_PTR(-EINVAL);
96 }
97
98 return table;
79} 99}
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 3b705f137ebb..647b81b477d4 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -57,7 +57,7 @@ extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64, u64,
57/* fragment.c */ 57/* fragment.c */
58extern int squashfs_frag_lookup(struct super_block *, unsigned int, u64 *); 58extern int squashfs_frag_lookup(struct super_block *, unsigned int, u64 *);
59extern __le64 *squashfs_read_fragment_index_table(struct super_block *, 59extern __le64 *squashfs_read_fragment_index_table(struct super_block *,
60 u64, unsigned int); 60 u64, u64, unsigned int);
61 61
62/* id.c */ 62/* id.c */
63extern int squashfs_get_id(struct super_block *, unsigned int, unsigned int *); 63extern int squashfs_get_id(struct super_block *, unsigned int, unsigned int *);
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 80a7119870a6..efa8118260d4 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -261,6 +261,7 @@ allocate_id_index_table:
261 msblk->inode_lookup_table = NULL; 261 msblk->inode_lookup_table = NULL;
262 goto failed_mount; 262 goto failed_mount;
263 } 263 }
264 next_table = msblk->inode_lookup_table[0];
264 265
265 sb->s_export_op = &squashfs_export_ops; 266 sb->s_export_op = &squashfs_export_ops;
266 267
@@ -278,7 +279,7 @@ handle_fragments:
278 279
279 /* Allocate and read fragment index table */ 280 /* Allocate and read fragment index table */
280 msblk->fragment_index = squashfs_read_fragment_index_table(sb, 281 msblk->fragment_index = squashfs_read_fragment_index_table(sb,
281 le64_to_cpu(sblk->fragment_table_start), fragments); 282 le64_to_cpu(sblk->fragment_table_start), next_table, fragments);
282 if (IS_ERR(msblk->fragment_index)) { 283 if (IS_ERR(msblk->fragment_index)) {
283 ERROR("unable to read fragment index table\n"); 284 ERROR("unable to read fragment index table\n");
284 err = PTR_ERR(msblk->fragment_index); 285 err = PTR_ERR(msblk->fragment_index);