1. 09 Nov, 2015 37 commits
  2. 03 Nov, 2015 3 commits
    • Calvin Owens's avatar
      sg: Fix double-free when drives detach during SG_IO · f3951a37
      Calvin Owens authored
      In sg_common_write(), we free the block request and return -ENODEV if
      the device is detached in the middle of the SG_IO ioctl().
      
      Unfortunately, sg_finish_rem_req() also tries to free srp->rq, so we
      end up freeing rq->cmd in the already free rq object, and then free
      the object itself out from under the current user.
      
      This ends up corrupting random memory via the list_head on the rq
      object. The most common crash trace I saw is this:
      
        ------------[ cut here ]------------
        kernel BUG at block/blk-core.c:1420!
        Call Trace:
        [<ffffffff81281eab>] blk_put_request+0x5b/0x80
        [<ffffffffa0069e5b>] sg_finish_rem_req+0x6b/0x120 [sg]
        [<ffffffffa006bcb9>] sg_common_write.isra.14+0x459/0x5a0 [sg]
        [<ffffffff8125b328>] ? selinux_file_alloc_security+0x48/0x70
        [<ffffffffa006bf95>] sg_new_write.isra.17+0x195/0x2d0 [sg]
        [<ffffffffa006cef4>] sg_ioctl+0x644/0xdb0 [sg]
        [<ffffffff81170f80>] do_vfs_ioctl+0x90/0x520
        [<ffffffff81258967>] ? file_has_perm+0x97/0xb0
        [<ffffffff811714a1>] SyS_ioctl+0x91/0xb0
        [<ffffffff81602afb>] tracesys+0xdd/0xe2
          RIP [<ffffffff81281e04>] __blk_put_request+0x154/0x1a0
      
      The solution is straightforward: just set srp->rq to NULL in the
      failure branch so that sg_finish_rem_req() doesn't attempt to re-free
      it.
      
      Additionally, since sg_rq_end_io() will never be called on the object
      when this happens, we need to free memory backing ->cmd if it isn't
      embedded in the object itself.
      
      KASAN was extremely helpful in finding the root cause of this bug.
      Signed-off-by: default avatarCalvin Owens <calvinowens@fb.com>
      Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      f3951a37
    • Benjamin Rood's avatar
      pm80xx: avoid a panic if MSI(X) interrupts are disabled · c913df3f
      Benjamin Rood authored
      If MSI(X) interrupts are disabled via the kernel command line
      (pci=nomsi), the pm8001 driver will kernel panic because it does not
      detect that MSI interrupts are disabled and will soldier on and attempt to
      configure MSI interrupts anyways.  This leads to a kernel panic, most
      likely because a required data structure is not available down the
      line.  Using the pci_msi_enabled() function in order to detect if MSI
      interrupts are enabled before configuring them resolves this issue and
      avoids a kernel panic when the module is loaded.  Additionally, the
      irq_vector structure must be initialized when legacy interrupts are
      being used otherwise legacy interrupts will simply not function and
      result in another panic.
      Signed-off-by: default avatarBenjamin Rood <brood@attotech.com>
      Reviewed-by: default avatarJack Wang <jinpu.wang@profitbricks.com>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      c913df3f
    • Benjamin Rood's avatar
      pm80xx: wait a minimum of 500ms before issuing commands to SPCv · b650a880
      Benjamin Rood authored
      The documentation for the 8070 and 8072 SPCv chip explicitly states that
      a minimum of 500ms must elapse before issuing commands, otherwise the
      SPCv may not process them and the firmware may get into an unrecoverable
      state requiring a reboot.  While the Linux guys will probably think this
      is 'racy', it is called out in the chip documentation and inserting this
      delay makes power management function properly.
      Signed-off-by: default avatarBenjamin Rood <brood@attotech.com>
      Reviewed-by: default avatarJack Wang <jinpu.wang@profitbricks.com>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      b650a880