nilfs2: clamp ns_r_segments_percentage to [1, 99]
authorHaogang Chen <[email protected]>
Sat, 17 Mar 2012 00:08:38 +0000 (17:08 -0700)
committerLinus Torvalds <[email protected]>
Sat, 17 Mar 2012 00:14:44 +0000 (17:14 -0700)
ns_r_segments_percentage is read from the disk.  Bogus or malicious
value could cause integer overflow and malfunction due to meaningless
disk usage calculation.  This patch reports error when mounting such
bogus volumes.

Signed-off-by: Haogang Chen <[email protected]>
Signed-off-by: Ryusuke Konishi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/nilfs2/the_nilfs.c

index d32714094375b72695bcacdfcf7cdd866be2ff05..8a759016c2e3e0b5438aec0cfd6120f85fa8ba27 100644 (file)
@@ -409,6 +409,12 @@ static int nilfs_store_disk_layout(struct the_nilfs *nilfs,
        nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block);
        nilfs->ns_r_segments_percentage =
                le32_to_cpu(sbp->s_r_segments_percentage);
+       if (nilfs->ns_r_segments_percentage < 1 ||
+           nilfs->ns_r_segments_percentage > 99) {
+               printk(KERN_ERR "NILFS: invalid reserved segments percentage.\n");
+               return -EINVAL;
+       }
+
        nilfs_set_nsegments(nilfs, le64_to_cpu(sbp->s_nsegments));
        nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed);
        return 0;