• Linus Torvalds's avatar
    Fix invalid access errors in blk_lookup_devt · d5791d13
    Linus Torvalds authored
    Commit 30f2f0eb ("block: do_mounts -
    accept root=<non-existant partition>") extended blk_lookup_devt() to be
    able to look up partitions that had not yet been registered, but in the
    process made the assumption that the '&block_class.devices' list only
    contains disk devices and that you can do 'dev_to_disk(dev)' on them.
    That isn't actually true.  The block_class device list also contains the
    partitions we've discovered so far, and you can't just do a
    'dev_to_disk()' on those.
    So make sure to only work on devices that block/genhd.c has registered
    itself, something we can test by checking the 'dev->type' member.  This
    makes the loop in blk_lookup_devt() match the other such loops in this
    [ We may want to do an alternate version that knows to handle _either_
      whole-disk devices or partitions, but for now this is the minimal fix
      for a series of crashes reported by Mariusz Kozlowski in
      and Ingo in
    Reported-by: default avatarMariusz Kozlowski <m.kozlowski@tuxland.pl>
    Reported-by: default avatarIngo Molnar <mingo@elte.hu>
    Cc: Neil Brown <neilb@suse.de>
    Cc: Joao Luis Meloni Assirati <assirati@nonada.if.usp.br>
    Acked-by: default avatarKay Sievers <kay.sievers@vrfy.org>
    Cc: Greg Kroah-Hartman <gregkh@suse.de>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
genhd.c 18.3 KB