Commit 89c0fd014d34d409a7b196667c2b9a4813b6c968
1 parent
6cda9fa257
Exists in
master
and in
7 other branches
nilfs2: reject filesystem with unsupported block size
This inserts sanity check that refuses to mount a filesystem with unsupported block size. Previously, kernel code of nilfs was looking only limitation of devices though mkfs.nilfs2 limits the range of block sizes; there was no check that prevents rec_len overflow with larger block sizes. With this change, block sizes larger than 64KB or smaller than 1KB will get rejected explicitly by kernel. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Showing 2 changed files with 14 additions and 1 deletions Side-by-side Diff
fs/nilfs2/the_nilfs.c
... | ... | @@ -671,7 +671,7 @@ |
671 | 671 | goto out; |
672 | 672 | } |
673 | 673 | |
674 | - blocksize = sb_min_blocksize(sb, BLOCK_SIZE); | |
674 | + blocksize = sb_min_blocksize(sb, NILFS_MIN_BLOCK_SIZE); | |
675 | 675 | if (!blocksize) { |
676 | 676 | printk(KERN_ERR "NILFS: unable to set blocksize\n"); |
677 | 677 | err = -EINVAL; |
... | ... | @@ -690,6 +690,13 @@ |
690 | 690 | goto failed_sbh; |
691 | 691 | |
692 | 692 | blocksize = BLOCK_SIZE << le32_to_cpu(sbp->s_log_block_size); |
693 | + if (blocksize < NILFS_MIN_BLOCK_SIZE || | |
694 | + blocksize > NILFS_MAX_BLOCK_SIZE) { | |
695 | + printk(KERN_ERR "NILFS: couldn't mount because of unsupported " | |
696 | + "filesystem blocksize %d\n", blocksize); | |
697 | + err = -EINVAL; | |
698 | + goto failed_sbh; | |
699 | + } | |
693 | 700 | if (sb->s_blocksize != blocksize) { |
694 | 701 | int hw_blocksize = bdev_logical_block_size(sb->s_bdev); |
695 | 702 |
include/linux/nilfs2_fs.h
... | ... | @@ -287,6 +287,12 @@ |
287 | 287 | #define NILFS_NAME_LEN 255 |
288 | 288 | |
289 | 289 | /* |
290 | + * Block size limitations | |
291 | + */ | |
292 | +#define NILFS_MIN_BLOCK_SIZE 1024 | |
293 | +#define NILFS_MAX_BLOCK_SIZE 65536 | |
294 | + | |
295 | +/* | |
290 | 296 | * The new version of the directory entry. Since V0 structures are |
291 | 297 | * stored in intel byte order, and the name_len field could never be |
292 | 298 | * bigger than 255 chars, it's safe to reclaim the extra byte for the |