ext2: enlarge blocksize and fix rec_lenoverflow
PATCH 2/2 ext2: enlarge blocksize and fix rec_lenoverflow
[2/2] ext2: fix rec_len overflow
- prevent rec_len from overflow with 64KB blocksize
Signed-off-by Takashi Sato [email protected]
---
fs/ext2/dir.c +12 -3
@@ -459,14 +459,23 @@ int ext2_add_link (struct dentry *dentry kaddr =page_address (page); dir_end = kaddr +ext2_last_byte (dir, n); de = (ext2_dirent *)kaddr; - kaddr +=PAGE_CACHE_SIZE - reclen; +if (chunk_size <EXT2_DIR_MAX_REC_LEN ) + kaddr +=PAGE_CACHE_SIZE - reclen; +else + kaddr +=EXT2_DIR_MAX_REC_LEN - reclen;while ((char *)de <= kaddr) {if ((char *)de == dir_end) {/* We hit i_size */ name_len =0 ; - rec_len = chunk_size; - de->rec_len =cpu_to_le16 (chunk_size); de->inode =0 ; +if (chunk_size <EXT2_DIR_MAX_REC_LEN ) { + rec_len = chunk_size; + de->rec_len =cpu_to_le16 (chunk_size); + }else { + rec_len =EXT2_DIR_MAX_REC_LEN ; + de->rec_len = +cpu_to_le16 (EXT2_DIR_MAX_REC_LEN ); + } goto got_it; }if (de->rec_len ==0 ) {
include/linux/ext2_fs.h +3 -2
@@ -90,8 +90,8 @@ static inline struct ext2_sb_info *EXT2_* Macro-instructions used to manage several block sizes */ #define EXT2_MIN_BLOCK_SIZE 1024 -#define EXT2_MAX_BLOCK_SIZE 4096 -#define EXT2_MIN_BLOCK_LOG_SIZE 10 +#define EXT2_MAX_BLOCK_SIZE 65536 +#define EXT2_MIN_BLOCK_LOG_SIZE 10#ifdef __KERNEL__# define EXT2_BLOCK_SIZE (s) ((s)->s_blocksize)#else
@@ -553,5 +553,6 @@ enum {#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)#define EXT2_DIR_REC_LEN (name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ ~EXT2_DIR_ROUND) +#define EXT2_DIR_MAX_REC_LEN 65532#endif /* _LINUX_EXT2_FS_H */
Cheers sho