android_kernel_motorola_sm6375/drivers
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Duoming Zhou 46eb6b6125 BACKPORT: nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs
commit d270453a0d9ec10bb8a802a142fb1b3601a83098 upstream.

There are destructive operations such as nfcmrvl_fw_dnld_abort and
gpio_free in nfcmrvl_nci_unregister_dev. The resources such as firmware,
gpio and so on could be destructed while the upper layer functions such as
nfcmrvl_fw_dnld_start and nfcmrvl_nci_recv_frame is executing, which leads
to double-free, use-after-free and null-ptr-deref bugs.

There are three situations that could lead to double-free bugs.

The first situation is shown below:

   (Thread 1)                 |      (Thread 2)
nfcmrvl_fw_dnld_start         |
 ...                          |  nfcmrvl_nci_unregister_dev
 release_firmware()           |   nfcmrvl_fw_dnld_abort
  kfree(fw) //(1)             |    fw_dnld_over
                              |     release_firmware
  ...                         |      kfree(fw) //(2)
                              |     ...

The second situation is shown below:

   (Thread 1)                 |      (Thread 2)
nfcmrvl_fw_dnld_start         |
 ...                          |
 mod_timer                    |
 (wait a time)                |
 fw_dnld_timeout              |  nfcmrvl_nci_unregister_dev
   fw_dnld_over               |   nfcmrvl_fw_dnld_abort
    release_firmware          |    fw_dnld_over
     kfree(fw) //(1)          |     release_firmware
     ...                      |      kfree(fw) //(2)

The third situation is shown below:

       (Thread 1)               |       (Thread 2)
nfcmrvl_nci_recv_frame          |
 if(..->fw_download_in_progress)|
  nfcmrvl_fw_dnld_recv_frame    |
   queue_work                   |
                                |
fw_dnld_rx_work                 | nfcmrvl_nci_unregister_dev
 fw_dnld_over                   |  nfcmrvl_fw_dnld_abort
  release_firmware              |   fw_dnld_over
   kfree(fw) //(1)              |    release_firmware
                                |     kfree(fw) //(2)

The firmware struct is deallocated in position (1) and deallocated
in position (2) again.

The crash trace triggered by POC is like below:

BUG: KASAN: double-free or invalid-free in fw_dnld_over
Call Trace:
  kfree
  fw_dnld_over
  nfcmrvl_nci_unregister_dev
  nci_uart_tty_close
  tty_ldisc_kill
  tty_ldisc_hangup
  __tty_hangup.part.0
  tty_release
  ...

What's more, there are also use-after-free and null-ptr-deref bugs
in nfcmrvl_fw_dnld_start. If we deallocate firmware struct, gpio or
set null to the members of priv->fw_dnld in nfcmrvl_nci_unregister_dev,
then, we dereference firmware, gpio or the members of priv->fw_dnld in
nfcmrvl_fw_dnld_start, the UAF or NPD bugs will happen.

This patch reorders destructive operations after nci_unregister_device
in order to synchronize between cleanup routine and firmware download
routine.

The nci_unregister_device is well synchronized. If the device is
detaching, the firmware download routine will goto error. If firmware
download routine is executing, nci_unregister_device will wait until
firmware download routine is finished.

Bug: 234690530
Fixes: 3194c68701 ("NFC: nfcmrvl: add firmware download support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: I8cc1f6450c7fecf5f5994033931da1d23a522282
2022-06-30 11:46:05 +01:00
..
accessibility
acpi This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
amba This is the 5.4.158 stable release 2021-11-06 14:08:38 +01:00
android Merge branch 'android11-5.4' into 'android11-5.4-lts' 2022-02-11 16:21:49 +01:00
ata ata: pata_marvell: Check the 'bmdma_addr' beforing reading 2022-04-27 13:50:48 +02:00
atm atm: eni: Add check for dma_map_single 2022-03-23 09:12:07 +01:00
auxdisplay auxdisplay: ht16k33: Fix frame buffer device blanking 2021-11-17 09:48:45 +01:00
base This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
bcma
block Merge tag 'android11-5.4.191_r01' into android11-5.4 2022-05-24 14:46:57 +02:00
bluetooth This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
bus bus: ti-sysc: Use CLKDM_NOAUTO for dra7 dcan1 for errata i893 2021-10-13 10:08:19 +02:00
cdrom
char This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
clk This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
clocksource This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
connector
counter
cpufreq This is the 5.4.174 stable release 2022-01-31 15:14:13 +01:00
cpuidle This is the 5.4.160 stable release 2021-11-17 10:19:21 +01:00
crypto This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
dax dax: make sure inodes are flushed before destroy cache 2022-04-15 14:18:12 +02:00
dca
devfreq
dio
dma This is the 5.4.191 stable release 2022-04-27 14:24:26 +02:00
dma-buf This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
edac EDAC/synopsys: Read the error count from the correct register 2022-04-27 13:50:48 +02:00
eisa
extcon
firewire
firmware This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
fpga fpga: machxo2-spi: Fix missing error code in machxo2_write_complete() 2021-09-30 10:09:23 +02:00
fsi
gnss
gpio gpiolib: acpi: use correct format characters 2022-04-20 09:19:35 +02:00
gpu This is the 5.4.191 stable release 2022-04-27 14:24:26 +02:00
greybus greybus: svc: fix an error handling bug in gb_svc_hello() 2022-04-15 14:17:58 +02:00
hid This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
hsi HSI: core: Fix return freed object in hsi_new_client 2022-01-27 09:19:41 +01:00
hv Drivers: hv: vmbus: Prevent load re-ordering when reading ring buffer 2022-04-20 09:19:36 +02:00
hwmon This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
hwspinlock
hwtracing coresight: Fix TRCCONFIGR.QE sysfs interface 2022-04-15 14:17:57 +02:00
i2c This is the 5.4.190 stable release 2022-04-21 14:13:50 +02:00
i3c
ide
idle
iio iio: adc: Add check for devm_request_threaded_irq 2022-04-15 14:18:18 +02:00
infiniband This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
input Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads" 2022-04-15 14:18:00 +02:00
interconnect
iommu This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
ipack ipack: ipoctal: fix module reference leak 2021-10-06 15:42:36 +02:00
irqchip This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
isdn mISDN: change function names to avoid conflicts 2022-01-11 15:23:33 +01:00
leds
lightnvm
macintosh
mailbox mailbox: tegra-hsp: Flush whole channel 2022-04-15 14:18:01 +02:00
mcb mcb: fix error handling in mcb_alloc_bus() 2021-09-30 10:09:22 +02:00
md Merge tag 'android11-5.4.191_r01' into android11-5.4 2022-05-24 14:46:57 +02:00
media This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
memory memory: atmel-ebi: Fix missing of_node_put in atmel_ebi_probe 2022-04-20 09:19:34 +02:00
memstick memstick: jmb38x_ms: use appropriate free function in jmb38x_ms_alloc_host() 2021-11-17 09:48:37 +01:00
message
mfd This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
misc This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
mmc This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
mtd This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
mux
net BACKPORT: can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path 2022-05-17 16:04:38 +00:00
nfc BACKPORT: nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs 2022-06-30 11:46:05 +01:00
ntb NTB: perf: Fix an error code in perf_setup_inbuf() 2021-09-22 12:26:44 +02:00
nubus
nvdimm libnvdimm/pmem: Fix crash triggered when I/O in-flight during unbind 2021-10-06 15:42:38 +02:00
nvme nvme-rdma: fix possible use-after-free in transport error_recovery work 2022-02-23 11:59:56 +01:00
nvmem This is the 5.4.155 stable release 2021-10-20 12:35:49 +02:00
of This is the 5.4.174 stable release 2022-01-31 15:14:13 +01:00
opp This is the 5.4.160 stable release 2021-11-17 10:19:21 +01:00
oprofile
parisc parisc: Fix CPU affinity for Lasi, WAX and Dino chips 2022-04-15 14:18:36 +02:00
parport parport: remove non-zero check on count 2021-09-22 12:26:36 +02:00
pci Revert "PCI: Reduce warnings on possible RW1C corruption" 2022-04-19 16:30:08 +02:00
pcmcia pcmcia: fix setting of kthread task states 2022-01-27 09:19:37 +01:00
perf arm_pmu: Validate single/group leader events 2022-04-27 13:50:50 +02:00
phy This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
pinctrl This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
platform This is the 5.4.191 stable release 2022-04-27 14:24:26 +02:00
pnp
power This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
powercap
pps
ps3
ptp ptp: replace snprintf with sysfs_emit 2022-04-15 14:18:32 +02:00
pwm This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
rapidio
ras
regulator This is the 5.4.190 stable release 2022-04-21 14:13:50 +02:00
remoteproc This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
reset This is the 5.4.191 stable release 2022-04-27 14:24:26 +02:00
rpmsg This is the 5.4.176 stable release 2022-02-01 17:48:27 +01:00
rtc This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
s390 scsi: zfcp: Fix failed recovery on gone remote port with non-NPIV FCP devices 2022-02-01 17:24:33 +01:00
sbus
scsi Merge tag 'android11-5.4.191_r01' into android11-5.4 2022-05-24 14:46:57 +02:00
sfi
sh maple: fix wrong return value of maple_bus_init(). 2021-11-26 10:47:17 +01:00
siox
slimbus
soc This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
soundwire
spi This is the 5.4.191 stable release 2022-04-27 14:24:26 +02:00
spmi
ssb
staging BACKPORT: staging: ion: Prevent incorrect reference counting behavour 2022-05-10 10:33:28 +00:00
target scsi: target: tcmu: Fix possible page UAF 2022-04-20 09:19:36 +02:00
tc
tee optee: use driver internal tee_context for some rpc 2022-03-02 11:41:04 +01:00
thermal This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
thunderbolt
tty This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
uio
usb Merge branch 'android11-5.4' into 'android11-5.4-lts' 2022-04-21 17:58:22 +02:00
vfio This is the 5.4.148 stable release 2021-09-25 14:41:58 +02:00
vhost This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
video This is the 5.4.189 stable release 2022-04-19 16:29:31 +02:00
virt
virtio This is the 5.4.185 stable release 2022-03-16 14:40:31 +01:00
visorbus
vlynq
vme
w1 w1: w1_therm: fixes w1_seq for ds28ea00 sensors 2022-04-15 14:18:35 +02:00
watchdog ar7: fix kernel builds for compiler test 2021-11-17 09:48:46 +01:00
xen xen/gnttab: fix gnttab_end_foreign_access() without page specified 2022-03-11 11:22:39 +01:00
zorro
Kconfig
Makefile
OWNERS