diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-03-15 22:09:55 +0000 |
---|---|---|
committer | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-03-16 01:04:18 +0000 |
commit | 44cff8a9ee8a974f9e931df910688e7fc1f0b0f9 (patch) | |
tree | 4bb7011f0f5be9047d601c889a8bf02da096cefd /fs/squashfs/dir.c | |
parent | 003a3194d36dc22c29cacda4d0c6fede2753c9d0 (diff) |
Squashfs: handle corruption of directory structure
Handle the rare case where a directory metadata block is uncompressed and
corrupted, leading to a kernel oops in directory scanning (memcpy).
Normally corruption is detected at the decompression stage and dealt with
then, however, this will not happen if:
- metadata isn't compressed (users can optionally request no metadata
compression), or
- the compressed metadata block was larger than the original, in which
case the uncompressed version was used, or
- the data was corrupt after decompression
This patch fixes this by adding some sanity checks against known maximum
values.
Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Diffstat (limited to 'fs/squashfs/dir.c')
-rw-r--r-- | fs/squashfs/dir.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c index 0dc340aa2be..3f79cd1d0c1 100644 --- a/fs/squashfs/dir.c +++ b/fs/squashfs/dir.c @@ -172,6 +172,11 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir) length += sizeof(dirh); dir_count = le32_to_cpu(dirh.count) + 1; + + /* dir_count should never be larger than 256 */ + if (dir_count > 256) + goto failed_read; + while (dir_count--) { /* * Read directory entry. @@ -183,6 +188,10 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir) size = le16_to_cpu(dire->size) + 1; + /* size should never be larger than SQUASHFS_NAME_LEN */ + if (size > SQUASHFS_NAME_LEN) + goto failed_read; + err = squashfs_read_metadata(inode->i_sb, dire->name, &block, &offset, size); if (err < 0) |