Skip to content

Commit

Permalink
Merge tag 'squashfs-updates' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/pkl/squashfs-next

Pull squashfs updates from Phillip Lougher:
 "Add an extra mount time sanity check, plus some code cleanups and bug
  fixes."

* tag 'squashfs-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-next:
  Squashfs: add mount time sanity check for block_size and block_log match
  Squashfs: fix f_pos check in get_dir_index_using_offset
  Squashfs: get rid of obsolete definitions in header file
  Squashfs: remove redundant length initialisation in squashfs_lookup
  Squashfs: remove redundant length initialisation in squashfs_readdir
  Squashfs: update comment removing reference to zlib only
  Squashfs: use define instead of constant
  • Loading branch information
torvalds committed Mar 29, 2012
2 parents 532bfc8 + 4b0180a commit 8563f87
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
3 changes: 2 additions & 1 deletion fs/squashfs/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ static struct buffer_head *get_block_length(struct super_block *sb,
* filesystem), otherwise the length is obtained from the first two bytes of
* the metadata block. A bit in the length field indicates if the block
* is stored uncompressed in the filesystem (usually because compression
* generated a larger block - this does occasionally happen with zlib).
* generated a larger block - this does occasionally happen with compression
* algorithms).
*/
int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
int length, u64 *next_index, int srclength, int pages)
Expand Down
7 changes: 3 additions & 4 deletions fs/squashfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int get_dir_index_using_offset(struct super_block *sb,
* is offset by 3 because we invent "." and ".." entries which are
* not actually stored in the directory.
*/
if (f_pos < 3)
if (f_pos <= 3)
return f_pos;
f_pos -= 3;

Expand Down Expand Up @@ -105,7 +105,7 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
struct inode *inode = file->f_dentry->d_inode;
struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
u64 block = squashfs_i(inode)->start + msblk->directory_table;
int offset = squashfs_i(inode)->offset, length = 0, dir_count, size,
int offset = squashfs_i(inode)->offset, length, dir_count, size,
type, err;
unsigned int inode_number;
struct squashfs_dir_header dirh;
Expand Down Expand Up @@ -173,8 +173,7 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)

dir_count = le32_to_cpu(dirh.count) + 1;

/* dir_count should never be larger than 256 */
if (dir_count > 256)
if (dir_count > SQUASHFS_DIR_COUNT)
goto failed_read;

while (dir_count--) {
Expand Down
5 changes: 2 additions & 3 deletions fs/squashfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,
struct squashfs_dir_entry *dire;
u64 block = squashfs_i(dir)->start + msblk->directory_table;
int offset = squashfs_i(dir)->offset;
int err, length = 0, dir_count, size;
int err, length, dir_count, size;

TRACE("Entered squashfs_lookup [%llx:%x]\n", block, offset);

Expand Down Expand Up @@ -177,8 +177,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,

dir_count = le32_to_cpu(dirh.count) + 1;

/* dir_count should never be larger than 256 */
if (dir_count > 256)
if (dir_count > SQUASHFS_DIR_COUNT)
goto data_error;

while (dir_count--) {
Expand Down
19 changes: 3 additions & 16 deletions fs/squashfs/squashfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@

/* size of metadata (inode and directory) blocks */
#define SQUASHFS_METADATA_SIZE 8192
#define SQUASHFS_METADATA_LOG 13

/* default size of data blocks */
#define SQUASHFS_FILE_SIZE 131072
#define SQUASHFS_FILE_LOG 17

/* default size of block device I/O */
#ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
Expand All @@ -46,12 +41,12 @@
#define SQUASHFS_FILE_MAX_SIZE 1048576
#define SQUASHFS_FILE_MAX_LOG 20

/* Max number of uids and gids */
#define SQUASHFS_IDS 65536

/* Max length of filename (not 255) */
#define SQUASHFS_NAME_LEN 256

/* Max value for directory header count*/
#define SQUASHFS_DIR_COUNT 256

#define SQUASHFS_INVALID_FRAG (0xffffffffU)
#define SQUASHFS_INVALID_XATTR (0xffffffffU)
#define SQUASHFS_INVALID_BLK (-1LL)
Expand Down Expand Up @@ -142,9 +137,6 @@
#define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
<< 16) + (B)))

/* Translate between VFS mode and squashfs mode */
#define SQUASHFS_MODE(A) ((A) & 0xfff)

/* fragment and fragment table defines */
#define SQUASHFS_FRAGMENT_BYTES(A) \
((A) * sizeof(struct squashfs_fragment_entry))
Expand Down Expand Up @@ -215,11 +207,6 @@
/* cached data constants for filesystem */
#define SQUASHFS_CACHED_BLKS 8

#define SQUASHFS_MAX_FILE_SIZE_LOG 64

#define SQUASHFS_MAX_FILE_SIZE (1LL << \
(SQUASHFS_MAX_FILE_SIZE_LOG - 2))

/* meta index cache */
#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
#define SQUASHFS_META_ENTRIES 127
Expand Down
5 changes: 5 additions & 0 deletions fs/squashfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
goto failed_mount;
}

/* Check block log for sanity */
msblk->block_log = le16_to_cpu(sblk->block_log);
if (msblk->block_log > SQUASHFS_FILE_MAX_LOG)
goto failed_mount;

/* Check that block_size and block_log match */
if (msblk->block_size != (1 << msblk->block_log))
goto failed_mount;

/* Check the root inode for sanity */
root_inode = le64_to_cpu(sblk->root_inode);
if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE)
Expand Down

0 comments on commit 8563f87

Please sign in to comment.