All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch added to 3.12-stable] ext4: validate s_first_meta_bg at mount time
@ 2017-03-06  9:09 Jiri Slaby
  2017-03-06  9:09 ` [patch added to 3.12-stable] ext4: fix fencepost in s_first_meta_bg validation Jiri Slaby
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: Jiri Slaby @ 2017-03-06  9:09 UTC (permalink / raw)
  To: stable; +Cc: Eryu Guan, Theodore Ts'o, Jiri Slaby

From: Eryu Guan <guaneryu@gmail.com>

This patch has been added to the 3.12 stable tree. If you have any
objections, please let us know.

===============

commit 3a4b77cd47bb837b8557595ec7425f281f2ca1fe upstream.

Ralf Spenneberg reported that he hit a kernel crash when mounting a
modified ext4 image. And it turns out that kernel crashed when
calculating fs overhead (ext4_calculate_overhead()), this is because
the image has very large s_first_meta_bg (debug code shows it's
842150400), and ext4 overruns the memory in count_overhead() when
setting bitmap buffer, which is PAGE_SIZE.

ext4_calculate_overhead():
  buf = get_zeroed_page(GFP_NOFS);  <=== PAGE_SIZE buffer
  blks = count_overhead(sb, i, buf);

count_overhead():
  for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) { <=== j = 842150400
          ext4_set_bit(EXT4_B2C(sbi, s++), buf);   <=== buffer overrun
          count++;
  }

This can be reproduced easily for me by this script:

  #!/bin/bash
  rm -f fs.img
  mkdir -p /mnt/ext4
  fallocate -l 16M fs.img
  mke2fs -t ext4 -O bigalloc,meta_bg,^resize_inode -F fs.img
  debugfs -w -R "ssv first_meta_bg 842150400" fs.img
  mount -o loop fs.img /mnt/ext4

Fix it by validating s_first_meta_bg first at mount time, and
refusing to mount if its value exceeds the largest possible meta_bg
number.

[js] use EXT4_HAS_INCOMPAT_FEATURE instead of new
     ext4_has_feature_meta_bg

Reported-by: Ralf Spenneberg <ralf@os-t.de>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 fs/ext4/super.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 6362896f5875..a263fa90edfa 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3852,6 +3852,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 			(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
 	db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
 		   EXT4_DESC_PER_BLOCK(sb);
+	if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG)) {
+		if (le32_to_cpu(es->s_first_meta_bg) >= db_count) {
+			ext4_msg(sb, KERN_WARNING,
+				 "first meta block group too large: %u "
+				 "(group descriptor block count %u)",
+				 le32_to_cpu(es->s_first_meta_bg), db_count);
+			goto failed_mount;
+		}
+	}
 	sbi->s_group_desc = ext4_kvmalloc(db_count *
 					  sizeof(struct buffer_head *),
 					  GFP_KERNEL);
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2017-03-06 10:22 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06  9:09 [patch added to 3.12-stable] ext4: validate s_first_meta_bg at mount time Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] ext4: fix fencepost in s_first_meta_bg validation Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] ocfs2: do not write error flag to user structure we cannot copy from/to Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] 6lowpan: release device on error path Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] mfd: pm8921: Potential NULL dereference in pm8921_remove() Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] Staging: vt6655-6: potential NULL dereference in hostap_disable_hostapd() Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] drm/nv50/disp: min/max are reversed in nv50_crtc_gamma_set() Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] cpufreq: fix garbage kobjects on errors during suspend/resume Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] cpufreq: remove sysfs files for CPUs which failed to come back after resume Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] cpufreq: Clean up after a failing light-weight initialization Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] cpufreq: preserve user_policy across suspend/resume Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] ipv6: fix the use of pcpu_tstats in ip6_tunnel Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] net: 6lowpan: fix lowpan_header_create non-compression memcpy call Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] ipv6: simplify detection of first operational link-local address on interface Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] net: sctp: rework multihoming retransmission path selection to rfc4960 Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] vti4: Don't count header length twice Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] PCI: mvebu: Use max_t() instead of max(resource_size_t,) Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] PCI: mvebu: split PCIe BARs into multiple MBus windows when needed Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] gianfar: Check if phydev present on ethtool -A Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] net: filter: x86: fix JIT address randomization Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] net: filter: s390: " Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] USB: cdc-acm: fix double usb_autopm_put_interface() in acm_port_activate() Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] USB: cdc-acm: fix open and suspend race Jiri Slaby
2017-03-06  9:09 ` [patch added to 3.12-stable] USB: cdc-acm: fix failed open not being detected Jiri Slaby

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.