kernel_samsung_a53x/drivers
Carlos Llamas 5bf69dbb38 binder: fix use-after-free in shinker's callback
commit 3f489c2067c5824528212b0fc18b28d51332d906 upstream.

The mmap read lock is used during the shrinker's callback, which means
that using alloc->vma pointer isn't safe as it can race with munmap().
As of commit dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in
munmap") the mmap lock is downgraded after the vma has been isolated.

I was able to reproduce this issue by manually adding some delays and
triggering page reclaiming through the shrinker's debug sysfs. The
following KASAN report confirms the UAF:

  ==================================================================
  BUG: KASAN: slab-use-after-free in zap_page_range_single+0x470/0x4b8
  Read of size 8 at addr ffff356ed50e50f0 by task bash/478

  CPU: 1 PID: 478 Comm: bash Not tainted 6.6.0-rc5-00055-g1c8b86a3799f-dirty 
  Hardware name: linux,dummy-virt (DT)
  Call trace:
   zap_page_range_single+0x470/0x4b8
   binder_alloc_free_page+0x608/0xadc
   __list_lru_walk_one+0x130/0x3b0
   list_lru_walk_node+0xc4/0x22c
   binder_shrink_scan+0x108/0x1dc
   shrinker_debugfs_scan_write+0x2b4/0x500
   full_proxy_write+0xd4/0x140
   vfs_write+0x1ac/0x758
   ksys_write+0xf0/0x1dc
   __arm64_sys_write+0x6c/0x9c

  Allocated by task 492:
   kmem_cache_alloc+0x130/0x368
   vm_area_alloc+0x2c/0x190
   mmap_region+0x258/0x18bc
   do_mmap+0x694/0xa60
   vm_mmap_pgoff+0x170/0x29c
   ksys_mmap_pgoff+0x290/0x3a0
   __arm64_sys_mmap+0xcc/0x144

  Freed by task 491:
   kmem_cache_free+0x17c/0x3c8
   vm_area_free_rcu_cb+0x74/0x98
   rcu_core+0xa38/0x26d4
   rcu_core_si+0x10/0x1c
   __do_softirq+0x2fc/0xd24

  Last potentially related work creation:
   __call_rcu_common.constprop.0+0x6c/0xba0
   call_rcu+0x10/0x1c
   vm_area_free+0x18/0x24
   remove_vma+0xe4/0x118
   do_vmi_align_munmap.isra.0+0x718/0xb5c
   do_vmi_munmap+0xdc/0x1fc
   __vm_munmap+0x10c/0x278
   __arm64_sys_munmap+0x58/0x7c

Fix this issue by performing instead a vma_lookup() which will fail to
find the vma that was isolated before the mmap lock downgrade. Note that
this option has better performance than upgrading to a mmap write lock
which would increase contention. Plus, mmap_write_trylock() has been
recently removed anyway.

Fixes: dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap")
Cc: stable@vger.kernel.org
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Minchan Kim <minchan@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20231201172212.1813387-3-cmllamas@google.com
[cmllamas: use find_vma() instead of vma_lookup() as commit ce6d42f2e4a2
 is missing in v5.10. This only works because we check the vma against
 our cached alloc->vma pointer.]
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-18 12:12:44 +01:00
..
accessibility
acpi ACPI: extlog: Clear Extended Error Log status when RAS_CEC handled the error 2024-11-18 12:12:25 +01:00
amba
android binder: fix use-after-free in shinker's callback 2024-11-18 12:12:44 +01:00
ata ata: pata_isapnp: Add missing error check for devm_ioport_map() 2024-11-18 12:10:54 +01:00
atm atm: solos-pci: Fix potential deadlock on &tx_queue_lock 2024-11-18 12:11:48 +01:00
auxdisplay
base devcoredump: Send uevent once devcd is ready 2024-11-18 12:11:48 +01:00
battery
bcma
block
bluetooth Bluetooth: btmtkuart: fix recv_buf() return value 2024-11-18 12:12:38 +01:00
bts
bus bus: ti-sysc: Flush posted write only after srst_udelay 2024-11-18 12:12:01 +01:00
cdrom
char
clk clk: fixed-rate: add devm_clk_hw_register_fixed_rate 2024-11-18 12:12:43 +01:00
clocksource clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware 2024-11-18 11:43:12 +01:00
connector
counter
cpufreq cpufreq: scmi: process the result of devm_of_clk_add_hw_provider() 2024-11-18 12:12:24 +01:00
cpuidle
crypto crypto: sahara - do not resize req->src when doing hash operations 2024-11-18 12:12:27 +01:00
dax
dca
devfreq
dio
dma dmaengine: stm32-mdma: correct desc prep when channel running 2024-11-18 11:43:25 +01:00
dma-buf
edac EDAC/thunderx: Fix possible out-of-bounds string access 2024-11-18 12:12:19 +01:00
eisa
extcon
fingerprint
firewire firewire: ohci: suppress unexpected system reboot in AMD Ryzen machines and ASM108x/VT630x PCIe cards 2024-11-18 12:12:08 +01:00
firmware firmware: meson_sm: populate platform devices from sm device tree data 2024-11-18 12:12:28 +01:00
fpga
fsi
gnss
gpio gpiolib: sysfs: Fix error handling on failed export 2024-11-18 12:11:45 +01:00
gpu gpu/drm/radeon: fix two memleaks in radeon_vm_init 2024-11-18 12:12:41 +01:00
greybus
gud
hid HID: hid-asus: add const to read-only outgoing usb buffer 2024-11-18 12:11:57 +01:00
hsi
hv
hwmon hwmon: (acpi_power_meter) Fix 4.29 MW bug 2024-11-18 12:11:41 +01:00
hwspinlock
hwtracing coresight: etm4x: Fix width of CCITMIN field 2024-11-18 12:12:19 +01:00
i2c i2c: rk3x: fix potential spinlock recursion on poll 2024-11-18 12:12:17 +01:00
i3c i3c: master: cdns: Fix reading status register 2024-11-18 11:43:26 +01:00
ide
idle
ifconn
iio iio: adc: ti_am335x_adc: Fix return value check of tiadc_request_dma() 2024-11-18 12:12:00 +01:00
infiniband IB/iser: Prevent invalidating wrong MR 2024-11-18 12:12:43 +01:00
input Input: xpad - add Razer Wolverine V2 support 2024-11-18 12:12:17 +01:00
interconnect interconnect: Treat xlate() returning NULL node as an error 2024-11-18 12:12:00 +01:00
iommu iommu/vt-d: Add MTL to quirk list to skip TE disabling 2024-11-18 12:11:09 +01:00
ipack
irqchip
isdn
kperfmon
kq/mesh
leds leds: trigger: ledtrig-cpu:: Fix 'output may be truncated' issue for 'cpu' 2024-11-18 11:43:05 +01:00
lightnvm
macintosh
mailbox
mcb mcb: fix error handling for different scenarios when parsing 2024-11-18 11:43:25 +01:00
md dm-integrity: don't modify bio's immutable bio_vec in integrity_metadata() 2024-11-18 12:12:03 +01:00
media media: dvb-frontends: m88ds3103: Fix a memory leak in an error handling path of m88ds3103_probe() 2024-11-18 12:12:41 +01:00
memory
memstick
message
mfd mfd: dln2: Fix double put in dln2_probe 2024-11-18 11:43:04 +01:00
misc misc: mei: client.c: fix problem of return '-EOVERFLOW' in mei_cl_write 2024-11-18 12:11:45 +01:00
mmc mmc: sdhci_omap: Fix TI SoC dependencies 2024-11-18 12:12:43 +01:00
most
mtd mtd: Fix gluebi NULL pointer dereference caused by ftl notifier 2024-11-18 12:12:25 +01:00
muic
mux
net wifi: rtlwifi: rtl8192se: using calculate_bit_shift() 2024-11-18 12:12:38 +01:00
nfc
ntb
nubus
nvdimm
nvme nvme: introduce helper function to get ctrl state 2024-11-18 12:12:15 +01:00
nvmem
of of: unittest: Fix of_count_phandle_with_args() expected value message 2024-11-18 12:12:43 +01:00
opp
oprofile
parisc
parport parport: parport_serial: Add Brainboxes device IDs and geometry 2024-11-18 12:12:19 +01:00
pci PCI: Add ACS quirk for more Zhaoxin Root Ports 2024-11-18 12:12:19 +01:00
pcmcia pcmcia: ds: fix possible name leak in error path in pcmcia_device_add() 2024-11-18 11:43:06 +01:00
perf
phy
pinctrl pinctrl: lochnagar: Don't build on MIPS 2024-11-18 12:12:11 +01:00
platform platform/x86: intel_telemetry: Fix kernel doc descriptions 2024-11-18 12:11:56 +01:00
pnp
power
powercap
pps
ps3
ptp ptp: annotate data-race around q->head and q->tail 2024-11-18 11:43:19 +01:00
pwm pwm: stm32: Fix enable count for clk in .probe() 2024-11-18 12:12:43 +01:00
rapidio
ras
regulator
remoteproc
reset reset: hisilicon: hi6220: fix Wvoid-pointer-to-enum-cast warning 2024-11-18 12:12:16 +01:00
rpmsg
rtc rtc: pcf85363: fix wrong mask/val parameters in regmap_update_bits call 2024-11-18 11:43:06 +01:00
s390 s390/scm: fix virtual vs physical address confusion 2024-11-18 12:12:16 +01:00
samsung
sbus
scsi scsi: hisi_sas: Replace with standard error code return value 2024-11-18 12:12:36 +01:00
sensorhub
sensors
sfi
sh
siox
slimbus
soc
soundwire soundwire: stream: fix NULL pointer dereference for multi_link 2024-11-18 12:11:57 +01:00
spi spi: sh-msiof: Enforce fixed DTDL for R-Car H3 2024-11-18 12:12:25 +01:00
spmi
spu_verify
ssb
staging media: rkisp1: Disable runtime PM in probe error path 2024-11-18 12:12:40 +01:00
sti
target
tc
tee tee: optee: Fix supplicant based device enumeration 2024-11-18 12:11:39 +01:00
thermal
thunderbolt
tty tty: n_gsm: add sanity check for gsm->receive in gsm_receive_buf() 2024-11-18 12:11:58 +01:00
uh
uio uio: Fix use-after-free in uio_open 2024-11-18 12:12:19 +01:00
usb usb: fotg210-hcd: delete an incorrect bounds test 2024-11-18 12:12:02 +01:00
vdpa
vfio
vhost
vibrator
video fbdev: stifb: Make the STI next font pointer a 32-bit signed offset 2024-11-18 12:11:12 +01:00
virt
virtio
vision
vision3
visorbus
vlynq
vme
w1
watchdog watchdog: rti_wdt: Drop runtime pm reference count when watchdog is unused 2024-11-18 12:12:42 +01:00
xen swiotlb-xen: provide the "max_mapping_size" method 2024-11-18 12:10:57 +01:00
zorro
Kconfig
Kconfig.variant1
Makefile
Makefile.variant1