1. 09 Feb, 2017 2 commits
    • Eryu Guan's avatar
      ext4: validate s_first_meta_bg at mount time · 13e6ef99
      Eryu Guan authored
      commit 3a4b77cd 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.
      Reported-by: default avatarRalf Spenneberg <ralf@os-t.de>
      Signed-off-by: default avatarEryu Guan <guaneryu@gmail.com>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13e6ef99
    • Bjorn Helgaas's avatar
      PCI/ASPM: Handle PCI-to-PCIe bridges as roots of PCIe hierarchies · 610c2b7f
      Bjorn Helgaas authored
      commit 030305d6 upstream.
      
      In a struct pcie_link_state, link->root points to the pcie_link_state of
      the root of the PCIe hierarchy.  For the topmost link, this points to
      itself (link->root = link).  For others, we copy the pointer from the
      parent (link->root = link->parent->root).
      
      Previously we recognized that Root Ports originated PCIe hierarchies, but
      we treated PCI/PCI-X to PCIe Bridges as being in the middle of the
      hierarchy, and when we tried to copy the pointer from link->parent->root,
      there was no parent, and we dereferenced a NULL pointer:
      
        BUG: unable to handle kernel NULL pointer dereference at 0000000000000090
        IP: [<ffffffff9e424350>] pcie_aspm_init_link_state+0x170/0x820
      
      Recognize that PCI/PCI-X to PCIe Bridges originate PCIe hierarchies just
      like Root Ports do, so link->root for these devices should also point to
      itself.
      
      Fixes: 51ebfc92 ("PCI: Enumerate switches below PCI-to-PCIe bridges")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=193411
      Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1022181
      Tested-by: lists@ssl-mail.com
      Tested-by: default avatarJayachandran C. <jnair@caviumnetworks.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      610c2b7f
  2. 04 Feb, 2017 38 commits