1
0
Fork 0
remarkable-linux/drivers
Bill Kuzeja b18daa09fe scsi: qla2xxx: Fix small memory leak in qla2x00_probe_one on probe failure
commit 6d6340672b upstream.

The code that fixes the crashes in the following commit introduced a small
memory leak:

commit 6a2cf8d366 ("scsi: qla2xxx: Fix crashes in qla2x00_probe_one on probe failure")

Fixing this requires a bit of reworking, which I've explained. Also provide
some code cleanup.

There is a small window in qla2x00_probe_one where if qla2x00_alloc_queues
fails, we end up never freeing req and rsp and leak 0xc0 and 0xc8 bytes
respectively (the sizes of req and rsp).

I originally put in checks to test for this condition which were based on
the incorrect assumption that if ha->rsp_q_map and ha->req_q_map were
allocated, then rsp and req were allocated as well. This is incorrect.
There is a window between these allocations:

       ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
                goto probe_hw_failed;

[if successful, both rsp and req allocated]

       base_vha = qla2x00_create_host(sht, ha);
                goto probe_hw_failed;

       ret = qla2x00_request_irqs(ha, rsp);
                goto probe_failed;

       if (qla2x00_alloc_queues(ha, req, rsp)) {
                goto probe_failed;

[if successful, now ha->rsp_q_map and ha->req_q_map allocated]

To simplify this, we should just set req and rsp to NULL after we free
them. Sounds simple enough? The problem is that req and rsp are pointers
defined in the qla2x00_probe_one and they are not always passed by reference
to the routines that free them.

Here are paths which can free req and rsp:

PATH 1:
qla2x00_probe_one
   ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
   [req and rsp are passed by reference, but if this fails, we currently
    do not NULL out req and rsp. Easily fixed]

PATH 2:
qla2x00_probe_one
   failing in qla2x00_request_irqs or qla2x00_alloc_queues
      probe_failed:
         qla2x00_free_device(base_vha);
            qla2x00_free_req_que(ha, req)
            qla2x00_free_rsp_que(ha, rsp)

PATH 3:
qla2x00_probe_one:
   failing in qla2x00_mem_alloc or qla2x00_create_host
      probe_hw_failed:
         qla2x00_free_req_que(ha, req)
         qla2x00_free_rsp_que(ha, rsp)

PATH 1: This should currently work, but it doesn't because rsp and rsp are
not set to NULL in qla2x00_mem_alloc. Easily remedied.

PATH 2: req and rsp aren't passed in at all to qla2x00_free_device but are
derived from ha->req_q_map[0] and ha->rsp_q_map[0]. These are only set up if
qla2x00_alloc_queues succeeds.

In qla2x00_free_queues, we are protected from crashing if these don't exist
because req_qid_map and rsp_qid_map are only set on their allocation. We are
guarded in this way:

        for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
                if (!test_bit(cnt, ha->req_qid_map))
                        continue;

PATH 3: This works. We haven't freed req or rsp yet (or they were never
allocated if qla2x00_mem_alloc failed), so we'll attempt to free them here.

To summarize, there are a few small changes to make this work correctly and
(and for some cleanup):

1) (For PATH 1) Set *rsp and *req to NULL in case of failure in
qla2x00_mem_alloc so these are correctly set to NULL back in
qla2x00_probe_one

2) After jumping to probe_failed: and calling qla2x00_free_device,
explicitly set rsp and req to NULL so further calls with these pointers do
not crash, i.e. the free queue calls in the probe_hw_failed section we fall
through to.

3) Fix return code check in the call to qla2x00_alloc_queues. We currently
drop the return code on the floor. The probe fails but the caller of the
probe doesn't have an error code, so it attaches to pci. This can result in
a crash on module shutdown.

4) Remove unnecessary NULL checks in qla2x00_free_req_que,
qla2x00_free_rsp_que, and the egregious NULL checks before kfrees and vfrees
in qla2x00_mem_free.

I tested this out running a scenario where the card breaks at various times
during initialization. I made sure I forced every error exit path in
qla2x00_probe_one.

Cc: <stable@vger.kernel.org> # v4.16
Fixes: 6a2cf8d366 ("scsi: qla2xxx: Fix crashes in qla2x00_probe_one on probe failure")
Signed-off-by: Bill Kuzeja <william.kuzeja@stratus.com>
Acked-by: Himanshu Madhani <himanshu.madhani@cavium.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-19 08:56:18 +02:00
..
accessibility License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
acpi ACPI: EC: Fix debugfs_create_*() usage 2018-04-12 12:32:15 +02:00
amba License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
android binder: replace "%p" with "%pK" 2018-02-25 11:07:52 +01:00
ata libata: Modify quirks for MX100 to limit NCQ_TRIM quirk to MU01 version 2018-03-28 18:24:37 +02:00
atm atm: horizon: Fix irq release error 2017-12-14 09:53:13 +01:00
auxdisplay auxdisplay: img-ascii-lcd: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE 2018-02-07 11:12:20 -08:00
base Revert "base: arch_topology: fix section mismatch build warnings" 2018-04-08 14:26:32 +02:00
bcma License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
block loop: Fix lost writes caused by missing flag 2018-03-15 10:54:32 +01:00
bluetooth Bluetooth: Add a new 04ca:3015 QCA_ROME device 2018-04-12 12:32:11 +02:00
bus sunxi-rsb: Include OF based modalias in device uevent 2018-01-10 09:31:19 +01:00
cdrom License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
char tpm: return a TPM_RC_COMMAND_CODE response if command is not implemented 2018-04-12 12:32:16 +02:00
clk clk: sunxi-ng: a83t: Add M divider to TCON1 clock 2018-04-12 12:32:14 +02:00
clocksource clocksource/drivers/stm32: Fix kernel panic with multiple timers 2018-02-16 20:23:09 +01:00
connector
cpufreq powernv-cpufreq: Add helper to extract pstate from PMSR 2018-04-12 12:32:15 +02:00
cpuidle cpuidle: fix broadcast control when broadcast can not be entered 2017-12-25 14:26:30 +01:00
crypto crypto: ccp - return an actual key size from RSA max_size callback 2018-04-08 14:26:32 +02:00
dax dev/dax: fix uninitialized variable build warning 2017-12-20 10:10:34 +01:00
dca
devfreq PM / devfreq: Fix potential NULL pointer dereference in governor_store 2018-04-12 12:32:13 +02:00
dio License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dma dmaengine: ti-dma-crossbar: Fix event mapping for TPCC_EVT_MUX_60_63 2018-03-24 11:01:28 +01:00
dma-buf dma-buf/fence: Fix lock inversion within dma-fence-array 2018-03-19 08:42:47 +01:00
edac EDAC, mv64x60: Fix an error handling path 2018-04-12 12:32:19 +02:00
eisa License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
extcon extcon: int3496: process id-pin first so that we start with the right status 2018-02-28 10:19:39 +01:00
firewire License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
firmware firmware/psci: Expose SMCCC version through psci_ops 2018-02-16 20:22:56 +01:00
fmc License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
fpga fpga: region: release of_parse_phandle nodes after use 2018-02-07 11:12:26 -08:00
fsi
gpio gpio: thunderx: fix error return code in thunderx_gpio_probe() 2018-04-12 12:32:20 +02:00
gpu radeon: hide pointless #warning when compile testing 2018-04-19 08:56:17 +02:00
hid HID: elo: clear BTN_LEFT mapping 2018-03-19 08:42:47 +01:00
hsi License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hv Drivers: hv: vmbus: do not mark HV_PCIE as perf_device 2018-04-19 08:56:16 +02:00
hwmon hwmon: (ina2xx) Make calibration register value fixed 2018-04-12 12:32:13 +02:00
hwspinlock License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hwtracing coresight: Fix disabling of CoreSight TPIU 2018-03-24 11:01:26 +01:00
i2c i2c: i2c-stm32f7: fix no check on returned setup 2018-04-08 14:26:27 +02:00
ide ide: ide-atapi: fix compile error with defining macro DEBUG 2017-12-17 15:08:00 +01:00
idle Revert "x86/mm: Stop calling leave_mm() in idle code" 2017-11-04 15:01:50 +01:00
iio iio: imu: st_lsm6dsx: fix endianness in st_lsm6dsx_read_oneshot() 2018-03-28 18:24:49 +02:00
infiniband RDMA/cma: Fix rdma_cm path querying for RoCE 2018-04-12 12:32:20 +02:00
input Input: goodix - disable IRQs while suspended 2018-04-12 12:32:20 +02:00
iommu iommu/vt-d: clean up pr_irq if request_threaded_irq fails 2018-03-24 11:01:26 +01:00
ipack
irqchip irqchip/gic-v3: Fix the driver probe() fail due to disabled GICC entry 2018-04-12 12:32:14 +02:00
isdn License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
leds leds: pm8058: Silence pointer to integer size warning 2018-03-19 08:42:50 +01:00
lightnvm lightnvm: pblk: protect line bitmap while submitting meta io 2017-12-20 10:10:38 +01:00
macintosh License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mailbox mailbox: mailbox-test: don't rely on rx_buffer content to signal data ready 2017-12-14 09:53:12 +01:00
mcb License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
md bcache: segregate flash only volume write streams 2018-04-12 12:32:18 +02:00
media media: v4l: vsp1: Fix header display list status check in continuous mode 2018-04-19 08:56:16 +02:00
memory License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
memstick License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
message License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mfd mfd: twl6040: Fix child-node lookup 2017-12-29 17:53:46 +01:00
misc mei: remove dev_err message on an unsupported ioctl 2018-04-08 14:26:31 +02:00
mmc sdhci: Advertise 2.0v supply on SDIO host controller 2018-04-12 12:32:20 +02:00
mtd mtd: mtd_oobtest: Handle bitflips during reads 2018-04-12 12:32:20 +02:00
mux mux: core: fix double get_device() 2018-01-17 09:45:27 +01:00
net lan78xx: Correctly indicate invalid OTP 2018-04-19 08:56:16 +02:00
nfc License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ntb
nubus License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nvdimm libnvdimm, {btt, blk}: do integrity setup before add_disk() 2018-03-28 18:24:41 +02:00
nvme nvme_fcloop: fix abort race condition 2018-04-12 12:32:16 +02:00
nvmem License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
of of_mdio: avoid MDIO bus removal when a PHY is missing 2018-03-03 10:24:37 +01:00
oprofile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
parisc parisc: Hide Diva-built-in serial aux and graphics card 2017-12-29 17:53:47 +01:00
parport parport_pc: Add support for WCH CH382L PCI-E single parallel port card. 2018-04-08 14:26:31 +02:00
pci PCI: hv: Serialize the present and eject work items 2018-04-19 08:56:17 +02:00
pcmcia License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
perf License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
phy phy: qcom-ufs: add MODULE_LICENSE tag 2018-04-08 14:26:30 +02:00
pinctrl pinctrl: baytrail: Enable glitch filter for GPIOs used as interrupts 2018-04-12 12:32:16 +02:00
platform platform/chrome: Use proper protocol transfer function 2018-03-24 11:01:23 +01:00
pnp License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
power power: supply: axp288_charger: Properly stop work on probe-error / remove 2018-04-12 12:32:17 +02:00
powercap
pps drivers/pps: use surrounding "if PPS" to remove numerous dependency checks 2017-09-08 18:26:51 -07:00
ps3
ptp License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pwm pwm: stmpe: Fix wrong register offset for hwpwm=2 case 2018-03-19 08:42:51 +01:00
rapidio drivers/rapidio/devices/rio_mport_cdev.c: fix resource leak in error handling path in 'rio_dma_transfer()' 2017-12-14 09:53:08 +01:00
ras License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
regulator regulator: stm32-vrefbuf: fix check on ready flag 2018-03-15 10:54:28 +01:00
remoteproc License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
reset License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rpmsg rpmsg: glink: Initialize the "intent_req_comp" completion variable 2017-12-20 10:10:29 +01:00
rtc clk: divider: fix incorrect usage of container_of 2018-04-12 12:32:13 +02:00
s390 s390/qeth: on channel error, reject further cmd requests 2018-03-31 18:10:43 +02:00
sbus License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi scsi: qla2xxx: Fix small memory leak in qla2x00_probe_one on probe failure 2018-04-19 08:56:18 +02:00
sfi
sh License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sn
soc soc/fsl/qbman: fix issue in qman_delete_cgr_safe() 2018-03-31 18:10:42 +02:00
spi spi: sh-msiof: Fix timeout failures for TX-only DMA transfers 2018-04-12 12:32:14 +02:00
spmi
ssb License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
staging staging: lustre: disable preempt while sampling processor id. 2018-04-12 12:32:17 +02:00
target tcmu: release blocks for partially setup cmds 2018-04-12 12:32:21 +02:00
tc
tee optee: fix invalid of_node_put() in optee_driver_init() 2017-12-25 14:26:24 +01:00
thermal thermal: int3400_thermal: fix error handling in int3400_thermal_probe() 2018-04-12 12:32:21 +02:00
thunderbolt thunderbolt: tb: fix use after free in tb_activate_pcie_devices 2017-12-20 10:10:24 +01:00
tty tty: n_gsm: Allow ADM response in addition to UA for control dlci 2018-04-12 12:32:19 +02:00
uio uio_hv_generic: check that host supports monitor page 2018-04-12 12:32:19 +02:00
usb USB: serial: cp210x: add ELDAT Easywave RX09 id 2018-04-08 14:26:30 +02:00
uwb License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vfio vfio: disable filesystem-dax page pinning 2018-03-08 22:41:06 -08:00
vhost vhost: Fix vhost_copy_to_user() 2018-04-19 08:56:16 +02:00
video backlight: tdo24m: Fix the SPI CS between transfers 2018-04-12 12:32:16 +02:00
virt
virtio virtio_ring: fix num_free handling in error case 2018-03-15 10:54:32 +01:00
vlynq
vme License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
w1 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
watchdog watchdog: dw_wdt: add stop watchdog operation 2018-04-12 12:32:13 +02:00
xen xen/gntdev: Fix partial gntdev_mmap() cleanup 2018-03-03 10:24:37 +01:00
zorro License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Kconfig License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Makefile usb: build drivers/usb/common/ when USB_SUPPORT is set 2018-02-25 11:07:53 +01:00