linux/drivers
Jason Gunthorpe 305d568b72 RDMA/cma: Ensure rdma_addr_cancel() happens before issuing more requests
The FSM can run in a circle allowing rdma_resolve_ip() to be called twice
on the same id_priv. While this cannot happen without going through the
work, it violates the invariant that the same address resolution
background request cannot be active twice.

       CPU 1                                  CPU 2

rdma_resolve_addr():
  RDMA_CM_IDLE -> RDMA_CM_ADDR_QUERY
  rdma_resolve_ip(addr_handler)  #1

			 process_one_req(): for #1
                          addr_handler():
                            RDMA_CM_ADDR_QUERY -> RDMA_CM_ADDR_BOUND
                            mutex_unlock(&id_priv->handler_mutex);
                            [.. handler still running ..]

rdma_resolve_addr():
  RDMA_CM_ADDR_BOUND -> RDMA_CM_ADDR_QUERY
  rdma_resolve_ip(addr_handler)
    !! two requests are now on the req_list

rdma_destroy_id():
 destroy_id_handler_unlock():
  _destroy_id():
   cma_cancel_operation():
    rdma_addr_cancel()

                          // process_one_req() self removes it
		          spin_lock_bh(&lock);
                           cancel_delayed_work(&req->work);
	                   if (!list_empty(&req->list)) == true

      ! rdma_addr_cancel() returns after process_on_req #1 is done

   kfree(id_priv)

			 process_one_req(): for #2
                          addr_handler():
	                    mutex_lock(&id_priv->handler_mutex);
                            !! Use after free on id_priv

rdma_addr_cancel() expects there to be one req on the list and only
cancels the first one. The self-removal behavior of the work only happens
after the handler has returned. This yields a situations where the
req_list can have two reqs for the same "handle" but rdma_addr_cancel()
only cancels the first one.

The second req remains active beyond rdma_destroy_id() and will
use-after-free id_priv once it inevitably triggers.

Fix this by remembering if the id_priv has called rdma_resolve_ip() and
always cancel before calling it again. This ensures the req_list never
gets more than one item in it and doesn't cost anything in the normal flow
that never uses this strange error path.

Link: https://lore.kernel.org/r/0-v1-3bc675b8006d+22-syz_cancel_uaf_jgg@nvidia.com
Cc: stable@vger.kernel.org
Fixes: e51060f08a ("IB: IP address based RDMA connection manager")
Reported-by: syzbot+dc3dfba010d7671e05f5@syzkaller.appspotmail.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2021-09-23 17:03:09 -03:00
..
accessibility
acpi Additional ACPI updates for 5.15-rc1 2021-09-10 13:29:04 -07:00
amba
android
ata libata: Add ATA_HORKAGE_NO_NCQ_ON_ATI for Samsung 860 and 870 SSD. 2021-09-03 08:06:02 -06:00
atm
auxdisplay
base Merge branches 'pm-cpufreq', 'pm-sleep' and 'pm-em' 2021-09-10 20:26:08 +02:00
bcma Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
block virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
bluetooth
bus ARM: SoC drivers for 5.15 2021-09-01 15:25:28 -07:00
cdrom
char IPMI: A couple of very minor fixes for style and rate limiting 2021-09-12 11:44:58 -07:00
clk One patch to fix an unused variable warning in a Qualcomm clk driver. 2021-09-11 10:05:56 -07:00
clocksource - converted Pistachio platform to use MIPS generic kernel 2021-09-03 11:11:54 -07:00
comedi
connector
counter
cpufreq Merge branches 'pm-cpufreq', 'pm-sleep' and 'pm-em' 2021-09-10 20:26:08 +02:00
cpuidle - Core Frameworks 2021-09-07 12:38:59 -07:00
crypto pci-v5.15-changes 2021-09-07 19:13:42 -07:00
cxl cxl for v5.15 2021-09-09 11:48:27 -07:00
dax libnvdimm for v5.15 2021-09-09 11:39:57 -07:00
dca
devfreq devfreq: use HZ macros 2021-09-08 11:50:26 -07:00
dio
dma dmaengine updates for v5.15-rc1 2021-09-09 11:07:47 -07:00
dma-buf dma-buf: DMABUF_SYSFS_STATS should depend on DMA_SHARED_BUFFER 2021-09-07 12:42:21 +05:30
edac Updates to the interrupt core and driver subsystems: 2021-08-30 14:38:37 -07:00
eisa
extcon
firewire FireWire (IEEE 1394) subsystem updates: 2021-09-11 09:47:33 -07:00
firmware - Add the tegra3 thermal sensor and fix the compilation testing on 2021-09-11 09:20:57 -07:00
fpga Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
fsi
gnss
gpio gpio updates for v5.15 2021-09-07 12:27:27 -07:00
gpu drm fixes for 5.15-rc1 2021-09-10 11:22:23 -07:00
greybus
hid Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid 2021-09-02 14:30:46 -07:00
hsi
hv hyperv-next for 5.15 2021-09-01 18:25:20 -07:00
hwmon Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
hwspinlock
hwtracing Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
i2c platform-drivers-x86 for v5.15-1 2021-09-02 13:49:39 -07:00
i3c
idle
iio Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
infiniband RDMA/cma: Ensure rdma_addr_cancel() happens before issuing more requests 2021-09-23 17:03:09 -03:00
input Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2021-09-11 09:08:28 -07:00
interconnect interconnect changes for 5.15 2021-08-24 15:33:04 +02:00
iommu virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
ipack TTY / Serial patches for 5.15-rc1 2021-09-01 09:51:16 -07:00
irqchip Merge branch irq/qcom-pdc-nowake-cleanup into irq/irqchip-next 2021-08-23 09:50:46 +01:00
isdn Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
leds
macintosh Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
mailbox mailbox: cmdq: add multi-gce clocks support for mt8195 2021-08-31 22:57:45 -05:00
mcb
md libnvdimm for v5.15 2021-09-09 11:39:57 -07:00
media Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
memory
memstick Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
message
mfd - Core Frameworks 2021-09-07 12:38:59 -07:00
misc Misc driver fix for 5.15-rc1 2021-09-12 11:56:00 -07:00
mmc Merge branch 'akpm' (patches from Andrew) 2021-09-03 10:08:28 -07:00
most
mtd Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
mux
net pci-v5.15-changes 2021-09-07 19:13:42 -07:00
nfc nfc: st95hf: remove unused header includes 2021-08-26 09:13:36 +01:00
ntb Bug fixes and clean-ups for Linux v5.15 2021-09-07 13:05:02 -07:00
nubus
nvdimm cxl for v5.15 2021-09-09 11:48:27 -07:00
nvme nvme: add error handling support for add_disk() 2021-09-06 10:08:09 +02:00
nvmem
of of: property: Disable fw_devlink DT support for X86 2021-09-10 11:21:49 -05:00
opp Merge branches 'pm-pci', 'pm-sleep', 'pm-domains' and 'powercap' 2021-08-30 19:25:42 +02:00
parisc parisc: Move pci_dev_is_behind_card_dino to where it is used 2021-09-09 12:44:31 +02:00
parport parisc architecture updates for kernel 5.15: 2021-09-02 13:16:00 -07:00
pci More ACPI updates for 5.15-rc1 2021-09-08 16:33:21 -07:00
pcmcia
perf
phy Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
pinctrl Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
platform chrome platform changes for 5.15 2021-09-08 16:43:46 -07:00
pnp
power power supply and reset changes for the v5.15 series 2021-08-30 11:47:32 -07:00
powercap powercap: Add Power Limit4 support for Alder Lake SoC 2021-08-25 20:12:16 +02:00
pps
ps3
ptp ptp: ocp: Simplify Kconfig. 2021-08-26 12:06:42 +01:00
pwm pwm: mtk-disp: Implement atomic API .get_state() 2021-09-02 22:27:46 +02:00
rapidio
ras
regulator Merge remote-tracking branch 'regulator/for-5.14' into regulator-linus 2021-08-25 16:05:24 +01:00
remoteproc
reset ARM: SoC drivers for 5.15 2021-09-01 15:25:28 -07:00
rpmsg
rtc rtc: rx8010: select REGMAP_I2C 2021-09-09 10:18:40 +02:00
s390 2nd batch of s390 updates for 5.15 merge window 2021-09-09 12:55:12 -07:00
sbus
scsi pci-v5.15-changes 2021-09-07 19:13:42 -07:00
sh
siox
slimbus Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
soc ARM: SoC drivers for 5.15 2021-09-01 15:25:28 -07:00
soundwire sound updates for 5.15-rc1 2021-09-01 10:29:29 -07:00
spi ARM: SoC drivers for 5.15 2021-09-01 15:25:28 -07:00
spmi
ssb
staging Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
target SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
tc
tee
thermal - Add the tegra3 thermal sensor and fix the compilation testing on 2021-09-11 09:20:57 -07:00
thunderbolt thunderbolt: test: split up test cases in tb_test_credit_alloc_all 2021-09-06 12:27:03 -07:00
tty parisc architecture updates for kernel 5.15: 2021-09-02 13:16:00 -07:00
uio
usb More USB changes for 5.15-rc1 2021-09-05 11:19:15 -07:00
vdpa virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
vfio VFIO update for v5.15-rc1 2021-09-02 13:41:33 -07:00
vhost virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
video drm fixes for 5.15-rc1 2021-09-10 11:22:23 -07:00
virt
virtio virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
visorbus
vlynq
vme
w1
watchdog
xen Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
zorro
Kconfig
Makefile