• Arnd Bergmann's avatar
    scsi: fnic: fix invalid stack access · 42ec15ce
    Arnd Bergmann authored
    gcc -O3 warns that some local variables are not properly initialized:
    
    drivers/scsi/fnic/vnic_dev.c: In function 'fnic_dev_hang_notify':
    drivers/scsi/fnic/vnic_dev.c:511:16: error: 'a0' is used uninitialized in this function [-Werror=uninitialized]
      vdev->args[0] = *a0;
      ~~~~~~~~~~~~~~^~~~~
    drivers/scsi/fnic/vnic_dev.c:691:6: note: 'a0' was declared here
      u64 a0, a1;
          ^~
    drivers/scsi/fnic/vnic_dev.c:512:16: error: 'a1' is used uninitialized in this function [-Werror=uninitialized]
      vdev->args[1] = *a1;
      ~~~~~~~~~~~~~~^~~~~
    drivers/scsi/fnic/vnic_dev.c:691:10: note: 'a1' was declared here
      u64 a0, a1;
              ^~
    drivers/scsi/fnic/vnic_dev.c: In function 'fnic_dev_mac_addr':
    drivers/scsi/fnic/vnic_dev.c:512:16: error: 'a1' is used uninitialized in this function [-Werror=uninitialized]
      vdev->args[1] = *a1;
      ~~~~~~~~~~~~~~^~~~~
    drivers/scsi/fnic/vnic_dev.c:698:10: note: 'a1' was declared here
      u64 a0, a1;
              ^~
    
    Apparently the code relies on the local variables occupying adjacent memory
    locations in the same order, but this is of course not guaranteed.
    
    Use an array of two u64 variables where needed to make it work correctly.
    
    I suspect there is also an endianness bug here, but have not digged in deep
    enough to be sure.
    
    Fixes: 5df6d737 ("[SCSI] fnic: Add new Cisco PCI-Express FCoE HBA")
    Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200107201602.4096790-1-arnd@arndb.deSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    42ec15ce
vnic_dev.c 20.7 KB