• Dan Carpenter's avatar
    scsi: mptfusion: Fix double fetch bug in ioctl · 28d76df1
    Dan Carpenter authored
    Tom Hatskevich reported that we look up "iocp" then, in the called
    functions we do a second copy_from_user() and look it up again.
    The problem that could cause is:
    
    drivers/message/fusion/mptctl.c
       674          /* All of these commands require an interrupt or
       675           * are unknown/illegal.
       676           */
       677          if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
                                                   ^^^^
    We take this lock.
    
       678                  return ret;
       679
       680          if (cmd == MPTFWDOWNLOAD)
       681                  ret = mptctl_fw_download(arg);
                                                     ^^^
    Then the user memory changes and we look up "iocp" again but a different
    one so now we are holding the incorrect lock and have a race condition.
    
       682          else if (cmd == MPTCOMMAND)
       683                  ret = mptctl_mpt_command(arg);
    
    The security impact of this bug is not as bad as it could have been
    because these operations are all privileged and root already has
    enormous destructive power.  But it's still worth fixing.
    
    This patch passes the "iocp" pointer to the functions to avoid the
    second lookup.  That deletes 100 lines of code from the driver so
    it's a nice clean up as well.
    
    Link: https://lore.kernel.org/r/20200114123414.GA7957@kadamReported-by: default avatarTom Hatskevich <tom2001tom.23@gmail.com>
    Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    28d76df1
mptctl.c 82.9 KB