Skip to content

Commit bc9bc72

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus
* git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus: Squashfs: update email address Squashfs: add extra sanity checks at mount time Squashfs: add sanity checks to fragment reading at mount time Squashfs: add sanity checks to lookup table reading at mount time Squashfs: add sanity checks to id reading at mount time Squashfs: add sanity checks to xattr reading at mount time Squashfs: reverse order of filesystem table reading Squashfs: move table allocation into squashfs_read_table()
2 parents 968d803 + d7f2ff6 commit bc9bc72

23 files changed

Lines changed: 203 additions & 151 deletions

‎MAINTAINERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6001,7 +6001,7 @@ F: Documentation/filesystems/spufs.txt
60016001
F: arch/powerpc/platforms/cell/spufs/
60026002

60036003
SQUASHFS FILE SYSTEM
6004-
M: Phillip Lougher <phillip@lougher.demon.co.uk>
6004+
M: Phillip Lougher <phillip@squashfs.org.uk>
60056005
L: squashfs-devel@lists.sourceforge.net (subscribers-only)
60066006
W: http://squashfs.org.uk
60076007
S: Maintained

‎fs/squashfs/block.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License

‎fs/squashfs/cache.c‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License
@@ -393,19 +393,36 @@ struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *sb,
393393
/*
394394
* Read a filesystem table (uncompressed sequence of bytes) from disk
395395
*/
396-
int squashfs_read_table(struct super_block *sb, void *buffer, u64 block,
397-
int length)
396+
void *squashfs_read_table(struct super_block *sb, u64 block, int length)
398397
{
399398
int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
400399
int i, res;
401-
void **data = kcalloc(pages, sizeof(void *), GFP_KERNEL);
402-
if (data == NULL)
403-
return -ENOMEM;
400+
void *table, *buffer, **data;
401+
402+
table = buffer = kmalloc(length, GFP_KERNEL);
403+
if (table == NULL)
404+
return ERR_PTR(-ENOMEM);
405+
406+
data = kcalloc(pages, sizeof(void *), GFP_KERNEL);
407+
if (data == NULL) {
408+
res = -ENOMEM;
409+
goto failed;
410+
}
404411

405412
for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE)
406413
data[i] = buffer;
414+
407415
res = squashfs_read_data(sb, data, block, length |
408416
SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages);
417+
409418
kfree(data);
410-
return res;
419+
420+
if (res < 0)
421+
goto failed;
422+
423+
return table;
424+
425+
failed:
426+
kfree(table);
427+
return ERR_PTR(res);
411428
}

‎fs/squashfs/decompressor.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License

‎fs/squashfs/decompressor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Squashfs - a compressed read only filesystem for Linux
55
*
66
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
7-
* Phillip Lougher <phillip@lougher.demon.co.uk>
7+
* Phillip Lougher <phillip@squashfs.org.uk>
88
*
99
* This program is free software; you can redistribute it and/or
1010
* modify it under the terms of the GNU General Public License

‎fs/squashfs/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License

‎fs/squashfs/export.c‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License
@@ -121,30 +121,38 @@ static struct dentry *squashfs_get_parent(struct dentry *child)
121121
* Read uncompressed inode lookup table indexes off disk into memory
122122
*/
123123
__le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
124-
u64 lookup_table_start, unsigned int inodes)
124+
u64 lookup_table_start, u64 next_table, unsigned int inodes)
125125
{
126126
unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes);
127-
__le64 *inode_lookup_table;
128-
int err;
127+
__le64 *table;
129128

130129
TRACE("In read_inode_lookup_table, length %d\n", length);
131130

132-
/* Allocate inode lookup table indexes */
133-
inode_lookup_table = kmalloc(length, GFP_KERNEL);
134-
if (inode_lookup_table == NULL) {
135-
ERROR("Failed to allocate inode lookup table\n");
136-
return ERR_PTR(-ENOMEM);
137-
}
131+
/* Sanity check values */
132+
133+
/* there should always be at least one inode */
134+
if (inodes == 0)
135+
return ERR_PTR(-EINVAL);
136+
137+
/* length bytes should not extend into the next table - this check
138+
* also traps instances where lookup_table_start is incorrectly larger
139+
* than the next table start
140+
*/
141+
if (lookup_table_start + length > next_table)
142+
return ERR_PTR(-EINVAL);
143+
144+
table = squashfs_read_table(sb, lookup_table_start, length);
138145

139-
err = squashfs_read_table(sb, inode_lookup_table, lookup_table_start,
140-
length);
141-
if (err < 0) {
142-
ERROR("unable to read inode lookup table\n");
143-
kfree(inode_lookup_table);
144-
return ERR_PTR(err);
146+
/*
147+
* table[0] points to the first inode lookup table metadata block,
148+
* this should be less than lookup_table_start
149+
*/
150+
if (!IS_ERR(table) && table[0] >= lookup_table_start) {
151+
kfree(table);
152+
return ERR_PTR(-EINVAL);
145153
}
146154

147-
return inode_lookup_table;
155+
return table;
148156
}
149157

150158

‎fs/squashfs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License

‎fs/squashfs/fragment.c‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License
@@ -71,26 +71,29 @@ int squashfs_frag_lookup(struct super_block *sb, unsigned int fragment,
7171
* Read the uncompressed fragment lookup table indexes off disk into memory
7272
*/
7373
__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)
7575
{
7676
unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments);
77-
__le64 *fragment_index;
78-
int err;
77+
__le64 *table;
7978

80-
/* Allocate fragment lookup table indexes */
81-
fragment_index = kmalloc(length, GFP_KERNEL);
82-
if (fragment_index == NULL) {
83-
ERROR("Failed to allocate fragment index table\n");
84-
return ERR_PTR(-ENOMEM);
85-
}
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);
8688

87-
err = squashfs_read_table(sb, fragment_index, fragment_table_start,
88-
length);
89-
if (err < 0) {
90-
ERROR("unable to read fragment index table\n");
91-
kfree(fragment_index);
92-
return ERR_PTR(err);
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);
9396
}
9497

95-
return fragment_index;
98+
return table;
9699
}

‎fs/squashfs/id.c‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Squashfs - a compressed read only filesystem for Linux
33
*
44
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
5-
* Phillip Lougher <phillip@lougher.demon.co.uk>
5+
* Phillip Lougher <phillip@squashfs.org.uk>
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU General Public License
@@ -66,27 +66,37 @@ int squashfs_get_id(struct super_block *sb, unsigned int index,
6666
* Read uncompressed id lookup table indexes from disk into memory
6767
*/
6868
__le64 *squashfs_read_id_index_table(struct super_block *sb,
69-
u64 id_table_start, unsigned short no_ids)
69+
u64 id_table_start, u64 next_table, unsigned short no_ids)
7070
{
7171
unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids);
72-
__le64 *id_table;
73-
int err;
72+
__le64 *table;
7473

7574
TRACE("In read_id_index_table, length %d\n", length);
7675

77-
/* Allocate id lookup table indexes */
78-
id_table = kmalloc(length, GFP_KERNEL);
79-
if (id_table == NULL) {
80-
ERROR("Failed to allocate id index table\n");
81-
return ERR_PTR(-ENOMEM);
82-
}
76+
/* Sanity check values */
77+
78+
/* there should always be at least one id */
79+
if (no_ids == 0)
80+
return ERR_PTR(-EINVAL);
81+
82+
/*
83+
* length bytes should not extend into the next table - this check
84+
* also traps instances where id_table_start is incorrectly larger
85+
* than the next table start
86+
*/
87+
if (id_table_start + length > next_table)
88+
return ERR_PTR(-EINVAL);
89+
90+
table = squashfs_read_table(sb, id_table_start, length);
8391

84-
err = squashfs_read_table(sb, id_table, id_table_start, length);
85-
if (err < 0) {
86-
ERROR("unable to read id index table\n");
87-
kfree(id_table);
88-
return ERR_PTR(err);
92+
/*
93+
* table[0] points to the first id lookup table metadata block, this
94+
* should be less than id_table_start
95+
*/
96+
if (!IS_ERR(table) && table[0] >= id_table_start) {
97+
kfree(table);
98+
return ERR_PTR(-EINVAL);
8999
}
90100

91-
return id_table;
101+
return table;
92102
}

0 commit comments

Comments
 (0)