Thread (24 messages) 24 messages, 5 authors, 2016-05-17

Re: [PATCH 1/2] Btrfs: add more valid checks for superblock

From: Qu Wenruo <hidden>
Date: 2016-05-03 01:03:03


Liu Bo wrote on 2016/05/02 11:15 -0700:
quoted hunk ↗ jump to hunk
This adds valid checks for super_total_bytes, super_bytes_used and
super_stripesize.

Reported-by: Vegard Nossum <redacted>
Reported-by: Quentin Casasnovas <redacted>
Signed-off-by: Liu Bo <redacted>
---
 fs/btrfs/disk-io.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4e47849..988d03f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4120,6 +4120,20 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
 	 * Hint to catch really bogus numbers, bitflips or so, more exact checks are
 	 * done later
 	 */
+	if (btrfs_super_total_bytes(sb) == 0) {
+		printk(KERN_ERR "BTRFS: total bytes is zero\n");
+		ret = -EINVAL;
+	}
Would it be better if using "6 * nodesize"?

I'd like to use a precious low limit on total bytes, but we don't have 
such value, so 6 nodesize would be good.

Thanks,
Qu
+	if (btrfs_super_bytes_used(sb) < 6 * btrfs_super_nodesize(sb)) {
+		printk(KERN_ERR "BTRFS: bytes_used is too small %llu\n",
+		       btrfs_super_bytes_used(sb));
+		ret = -EINVAL;
+	}
+	if (btrfs_super_stripesize(sb) != 4096) {
+		printk(KERN_ERR "BTRFS: invalid stripesize %u\n",
+		       btrfs_super_stripesize(sb));
+		ret = -EINVAL;
+	}
 	if (btrfs_super_num_devices(sb) > (1UL << 31))
 		printk(KERN_WARNING "BTRFS: suspicious number of devices: %llu\n",
 				btrfs_super_num_devices(sb));
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help