android_kernel_motorola_sm6225/drivers/xen
Juergen Gross 3fdf2be908 xen/events: replace evtchn_rwlock with RCU
commit 87797fad6cce28ec9be3c13f031776ff4f104cfc upstream.

In unprivileged Xen guests event handling can cause a deadlock with
Xen console handling. The evtchn_rwlock and the hvc_lock are taken in
opposite sequence in __hvc_poll() and in Xen console IRQ handling.
Normally this is no problem, as the evtchn_rwlock is taken as a reader
in both paths, but as soon as an event channel is being closed, the
lock will be taken as a writer, which will cause read_lock() to block:

CPU0                     CPU1                CPU2
(IRQ handling)           (__hvc_poll())      (closing event channel)

read_lock(evtchn_rwlock)
                         spin_lock(hvc_lock)
                                             write_lock(evtchn_rwlock)
                                                 [blocks]
spin_lock(hvc_lock)
    [blocks]
                        read_lock(evtchn_rwlock)
                            [blocks due to writer waiting,
                             and not in_interrupt()]

This issue can be avoided by replacing evtchn_rwlock with RCU in
xen_free_irq(). Note that RCU is used only to delay freeing of the
irq_info memory. There is no RCU based dereferencing or replacement of
pointers involved.

In order to avoid potential races between removing the irq_info
reference and handling of interrupts, set the irq_info pointer to NULL
only when freeing its memory. The IRQ itself must be freed at that
time, too, as otherwise the same IRQ number could be allocated again
before handling of the old instance would have been finished.

This is XSA-441 / CVE-2023-34324.

Fixes: 54c9de89895e ("xen/events: add a new "late EOI" evtchn framework")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-10 21:45:02 +02:00
..
events xen/events: replace evtchn_rwlock with RCU 2023-10-10 21:45:02 +02:00
xen-pciback xen-pciback: Fix return in pm_ctrl_init() 2021-11-26 11:36:15 +01:00
xenbus xen/xenbus: fix return type in xenbus_file_read() 2022-08-25 11:15:39 +02:00
xenfs
acpi.c
arm-device.c
balloon.c xen/balloon: add late_initcall_sync() for initial ballooning done 2021-11-26 11:36:02 +01:00
biomerge.c
cpu_hotplug.c
dbgp.c
efi.c
evtchn.c
fallback.c
features.c x86/xen: Remove undefined behavior in setup_features() 2022-07-02 16:27:32 +02:00
gntalloc.c xen/gntalloc: don't use gnttab_query_foreign_access() 2022-03-11 10:15:13 +01:00
gntdev-common.h xen/gntdev: Avoid blocking in unmap_grant_pages() 2022-07-07 17:35:11 +02:00
gntdev-dmabuf.c
gntdev-dmabuf.h
gntdev.c xen/gntdev: Prevent leaking grants 2022-11-03 23:52:29 +09:00
grant-table.c xen/gnttab: fix gnttab_end_foreign_access() without page specified 2022-03-11 10:15:13 +01:00
Kconfig
Makefile
manage.c
mcelog.c
mem-reservation.c
pci.c
pcpu.c xen/pcpu: fix possible memory leak in register_pcpu() 2022-11-25 17:40:24 +01:00
platform-pci.c xen/platform-pci: add missing free_irq() in error path 2022-12-08 11:18:31 +01:00
preempt.c
privcmd-buf.c
privcmd.c xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource() 2023-01-18 11:30:07 +01:00
privcmd.h
pvcalls-back.c xen/pvcalls-back: fix double frees with pvcalls_new_active_socket() 2023-05-30 12:42:15 +01:00
pvcalls-front.c xen/pvcalls: use alloc/free_pages_exact() 2022-03-11 10:15:13 +01:00
pvcalls-front.h
swiotlb-xen.c
sys-hypervisor.c
time.c
tmem.c
xen-acpi-cpuhotplug.c
xen-acpi-memhotplug.c
xen-acpi-pad.c
xen-acpi-processor.c
xen-balloon.c
xen-scsiback.c
xen-selfballoon.c
xen-stub.c
xlate_mmu.c xen: unexport __init-annotated xen_xlate_map_ballooned_pages() 2022-07-02 16:27:39 +02:00