OpenCloudOS-Kernel/drivers
M. Vefa Bicakci 0991028cd4 xen/gntdev: Prevent leaking grants
Prior to this commit, if a grant mapping operation failed partially,
some of the entries in the map_ops array would be invalid, whereas all
of the entries in the kmap_ops array would be valid. This in turn would
cause the following logic in gntdev_map_grant_pages to become invalid:

  for (i = 0; i < map->count; i++) {
    if (map->map_ops[i].status == GNTST_okay) {
      map->unmap_ops[i].handle = map->map_ops[i].handle;
      if (!use_ptemod)
        alloced++;
    }
    if (use_ptemod) {
      if (map->kmap_ops[i].status == GNTST_okay) {
        if (map->map_ops[i].status == GNTST_okay)
          alloced++;
        map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
      }
    }
  }
  ...
  atomic_add(alloced, &map->live_grants);

Assume that use_ptemod is true (i.e., the domain mapping the granted
pages is a paravirtualized domain). In the code excerpt above, note that
the "alloced" variable is only incremented when both kmap_ops[i].status
and map_ops[i].status are set to GNTST_okay (i.e., both mapping
operations are successful).  However, as also noted above, there are
cases where a grant mapping operation fails partially, breaking the
assumption of the code excerpt above.

The aforementioned causes map->live_grants to be incorrectly set. In
some cases, all of the map_ops mappings fail, but all of the kmap_ops
mappings succeed, meaning that live_grants may remain zero. This in turn
makes it impossible to unmap the successfully grant-mapped pages pointed
to by kmap_ops, because unmap_grant_pages has the following snippet of
code at its beginning:

  if (atomic_read(&map->live_grants) == 0)
    return; /* Nothing to do */

In other cases where only some of the map_ops mappings fail but all
kmap_ops mappings succeed, live_grants is made positive, but when the
user requests unmapping the grant-mapped pages, __unmap_grant_pages_done
will then make map->live_grants negative, because the latter function
does not check if all of the pages that were requested to be unmapped
were actually unmapped, and the same function unconditionally subtracts
"data->count" (i.e., a value that can be greater than map->live_grants)
from map->live_grants. The side effects of a negative live_grants value
have not been studied.

The net effect of all of this is that grant references are leaked in one
of the above conditions. In Qubes OS v4.1 (which uses Xen's grant
mechanism extensively for X11 GUI isolation), this issue manifests
itself with warning messages like the following to be printed out by the
Linux kernel in the VM that had granted pages (that contain X11 GUI
window data) to dom0: "g.e. 0x1234 still pending", especially after the
user rapidly resizes GUI VM windows (causing some grant-mapping
operations to partially or completely fail, due to the fact that the VM
unshares some of the pages as part of the window resizing, making the
pages impossible to grant-map from dom0).

The fix for this issue involves counting all successful map_ops and
kmap_ops mappings separately, and then adding the sum to live_grants.
During unmapping, only the number of successfully unmapped grants is
subtracted from live_grants. The code is also modified to check for
negative live_grants values after the subtraction and warn the user.

Link: https://github.com/QubesOS/qubes-issues/issues/7631
Fixes: dbe97cff7d ("xen/gntdev: Avoid blocking in unmap_grant_pages()")
Cc: stable@vger.kernel.org
Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>
Acked-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/20221002222006.2077-2-m.v.b@runbox.com
Signed-off-by: Juergen Gross <jgross@suse.com>
2022-10-06 10:40:16 +02:00
..
accessibility TTY / Serial driver changes for 6.0-rc1 2022-08-08 11:31:40 -07:00
acpi * A performance fix for recent large AMD systems that avoids an ancient 2022-09-26 14:53:38 -07:00
amba ARM: 9229/1: amba: Fix use-after-free in amba_read_periphid() 2022-08-30 11:12:52 +01:00
android Char/Misc driver fixes for 6.0-rc4 2022-09-02 10:50:08 -07:00
ata ata: libata-sata: Fix device queue depth control 2022-09-28 20:47:31 +09:00
atm atm: idt77252: fix use-after-free bugs caused by tst_timer 2022-08-08 20:51:59 -07:00
auxdisplay
base Revert "driver core: Set fw_devlink.strict=1 by default" 2022-09-15 12:44:56 +02:00
bcma
block virtio-blk: Fix WARN_ON_ONCE in virtio_queue_rq() 2022-09-27 18:30:49 -04:00
bluetooth SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
bus bus: mhi: host: Fix up null pointer access in mhi_irq_handler 2022-08-29 22:33:46 +05:30
cdrom
char /dev/null: add IORING_OP_URING_CMD support 2022-08-26 11:19:44 -04:00
clk clk: imx93: drop of_match_ptr 2022-09-28 18:37:36 -07:00
clocksource RISC-V: Add Sstc extension support 2022-08-11 14:41:52 -07:00
comedi pci-v5.20-changes 2022-08-04 19:30:35 -07:00
connector
counter counter: 104-quad-8: Fix skipped IRQ lines during events configuration 2022-09-22 14:26:37 +02:00
cpufreq cpufreq: check only freq_table in __resolve_freq() 2022-08-23 20:00:52 +02:00
cpuidle More power management updates for 5.20-rc1 2022-08-08 14:29:00 -07:00
crypto virtio-crypto: fix memory-leak 2022-09-27 18:30:48 -04:00
cxl cxl/hdm: Fix skip allocations vs multiple pmem allocations 2022-08-05 16:11:38 -07:00
dax devdax: Fix soft-reservation memory description 2022-09-24 18:05:53 -07:00
dca
devfreq More power management updates for 5.20-rc1 2022-08-08 14:29:00 -07:00
dio
dma dmaengine: zynqmp_dma: Typecast with enum to fix the coverity warning 2022-09-05 11:54:50 +05:30
dma-buf dma-buf/dma-resv: check if the new fence is really later 2022-08-25 13:10:30 +02:00
edac powerpc updates for 6.0 2022-08-06 16:38:17 -07:00
eisa
extcon extcon: Add EXTCON_DISP_CVBS and EXTCON_DISP_EDP 2022-07-15 11:37:41 +09:00
firewire firewire: net: Make use of get_unaligned_be48(), put_unaligned_be48() 2022-07-28 22:21:54 -07:00
firmware MMC core: 2022-09-28 11:36:31 -07:00
fpga fpga: m10bmc-sec: Fix possible memory leak of flash_buf 2022-09-19 12:58:19 +08:00
fsi
gnss
gpio gpio: mvebu: Fix check for pwm support on non-A8K platforms 2022-09-26 09:20:09 +02:00
gpu Merge tag 'amd-drm-fixes-6.0-2022-09-30-1' of https://gitlab.freedesktop.org/agd5f/linux into drm-fixes 2022-09-30 23:10:55 +02:00
greybus
hid for-linus-2022083101 2022-08-31 09:54:14 -07:00
hsi
hte
hv Drivers: hv: Never allocate anything besides framebuffer from framebuffer memory region 2022-09-05 17:02:15 +00:00
hwmon hwmon: (asus-ec-sensors) autoload module via DMI data 2022-09-09 10:45:08 -07:00
hwspinlock hwspinlock: qcom: Add support for mmio usage to sfpb-mutex 2022-07-16 21:47:44 -05:00
hwtracing asm-generic: updates for 6.0 2022-08-05 10:07:23 -07:00
i2c i2c: davinci: fix PM disable depth imbalance in davinci_i2c_probe 2022-10-02 00:46:42 +02:00
i3c
idle Power management updates for 5.20-rc1 2022-08-02 11:17:00 -07:00
iio iio: light: cm32181: make cm32181_pm_ops static 2022-08-21 18:24:16 +01:00
infiniband RDMA/irdma: Report RNR NAK generation in device caps 2022-09-07 11:22:18 +03:00
input Input updates for v6.0-rc7 2022-09-29 08:22:53 -07:00
interconnect Merge branch 'icc-rpm' into icc-next 2022-07-15 17:56:31 +03:00
iommu iommu/vt-d: Check correct capability for sagaw determination 2022-09-21 10:22:54 +02:00
ipack
irqchip irqchip/loongson-pch-lpc: Add dependence on LoongArch 2022-09-16 09:25:51 +01:00
isdn
leds LED updates for 5.20: new driver for bcm63138, is31fl319x updates, 2022-08-08 11:36:21 -07:00
macintosh macintosh/adb: fix oob read in do_adb_query() function 2022-07-20 22:06:30 +10:00
mailbox - mtk: use rx_callback instead of cmdq_task_cb. 2022-08-08 10:19:40 -07:00
mcb
md block-6.0-2022-08-26 2022-08-26 11:05:54 -07:00
media media fixes for v6.0-rc8 2022-10-01 09:27:18 -07:00
memory More power management updates for 5.20-rc1 2022-08-08 14:29:00 -07:00
memstick MMC core: 2022-08-04 19:41:09 -07:00
message
mfd - Core Frameworks 2022-08-06 10:25:16 -07:00
misc misc: fastrpc: increase maximum session count 2022-09-01 16:13:07 +02:00
mmc mmc: hsq: Fix data stomping during mmc recovery 2022-09-27 12:38:29 +02:00
most
mtd MTD core changes: 2022-08-05 14:13:45 -07:00
mux
net Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue 2022-09-28 19:04:43 -07:00
nfc nfc: pn533: Fix use-after-free bugs caused by pn532_cmd_timeout 2022-08-22 14:51:30 +01:00
ntb NTB: epf: Allow more flexibility in the memory BAR map method 2022-08-09 17:54:03 -04:00
nubus
nvdimm Merge branch 'for-6.0/dax' into libnvdimm-fixes 2022-09-24 18:14:12 -07:00
nvme block-6.0-2022-09-29 2022-09-30 09:33:33 -07:00
nvmem SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
of of: fdt: fix off-by-one error in unflatten_dt_nodes() 2022-08-16 11:29:57 -06:00
opp OPP: Fix an un-initialized variable usage 2022-08-16 10:48:08 +05:30
parisc parisc: remove obsolete manual allocation aligning in iosapic 2022-09-15 07:33:26 +02:00
parport
pci xen-pcifront: Handle missed Connected state 2022-10-04 17:47:03 +02:00
pcmcia
peci peci: cpu: Fix use-after-free in adev_release() 2022-08-15 20:31:35 +02:00
perf arm64 fixes for -rc7 2022-09-23 15:28:51 -07:00
phy phy: marvell: phy-mvebu-a3700-comphy: Remove broken reset support 2022-08-30 10:32:33 +05:30
pinctrl pinctrl: ocelot: Fix interrupt controller 2022-09-14 15:00:16 +02:00
platform platform-drivers-x86 for v6.0-2 2022-09-02 10:35:51 -07:00
pnp PCI: Remove pci_get_legacy_ide_irq() and asm-generic/pci.h 2022-07-22 17:23:45 -05:00
power power supply and reset changes for the v6.0 series 2022-08-12 09:37:33 -07:00
powercap Power management updates for 5.20-rc1 2022-08-02 11:17:00 -07:00
pps
ps3
ptp SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
pwm SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
rapidio
ras
regulator regulator: Fixes for v6.0 2022-09-08 12:56:20 -04:00
remoteproc virtio: Revert "virtio: find_vqs() add arg sizes" 2022-08-16 01:40:24 -04:00
reset reset: npcm: fix iprst2 and iprst4 setting 2022-09-22 17:48:35 +02:00
rpmsg rpmsg: convert sysfs snprintf to sysfs_emit 2022-07-16 23:08:47 -05:00
rtc rtc: spear: set range max 2022-08-09 00:56:41 +02:00
s390 s390 updates for v6.0-rc7 2022-09-24 17:35:42 -07:00
sbus
scsi ATA fixes for 6.0-rc7 2022-09-29 05:40:59 -07:00
sh
siox
slimbus
soc sunxi SRAM controller fixes for 2022-09-23 14:29:00 +02:00
soundwire soundwire: qcom: fix device status array range 2022-09-01 14:26:44 +05:30
spi spi: Fixes for v6.0 2022-09-08 13:13:47 -04:00
spmi
ssb
staging media fixes for v6.0-rc8 2022-10-01 09:27:18 -07:00
target SCSI misc on 20220813 2022-08-13 13:41:48 -07:00
tc
tee tee: fix compiler warning in tee_shm_register() 2022-08-25 11:40:06 +02:00
thermal Merge branch 'thermal-core' 2022-08-27 15:07:58 +02:00
thunderbolt thunderbolt: Fix for v6.0 final 2022-09-27 10:47:36 +02:00
tty serial: sifive: enable clocks for UART when probed 2022-09-22 16:38:18 +02:00
ufs scsi: ufs: core: Reduce the power mode change timeout 2022-08-19 21:34:36 -04:00
uio
usb uas: ignore UAS for Thinkplus chips 2022-09-27 10:50:29 +02:00
vdpa vdpa/mlx5: Fix MQ to support non power of two num queues 2022-09-27 18:32:45 -04:00
vfio VFIO fix for v6.0-rc5 2022-09-09 07:44:33 -04:00
vhost virtio: fatures, fixes 2022-08-12 09:50:34 -07:00
video hyperv-fixes for v6.0-rc6 2022-09-12 18:33:55 -04:00
virt kunit: fix Kconfig for build-in tests USB4 and Nitro Enclaves 2022-09-01 13:00:48 -06:00
virtio virtio: kerneldocs fixes and enhancements 2022-08-16 01:40:24 -04:00
vlynq
w1
watchdog linux-watchdog 5.20-rc1 tag 2022-08-08 15:04:04 -07:00
xen xen/gntdev: Prevent leaking grants 2022-10-06 10:40:16 +02:00
zorro
Kconfig
Makefile Staging driver patches for 6.0-rc1 2022-08-04 12:01:42 -07:00