xen/events: avoid removing an event channel while handling it
authorJuergen Gross <jgross@suse.com>
Mon, 7 Sep 2020 13:47:27 +0000 (15:47 +0200)
committerJuergen Gross <jgross@suse.com>
Tue, 20 Oct 2020 08:21:51 +0000 (10:21 +0200)
commit073d0552ead5bfc7a3a9c01de590e924f11b5dd2
tree7ae185a9c3d86d3bcab390abc9b07eb6c8009699
parent32118f97f41d26a2447118fa956715cb4bd1bdac
xen/events: avoid removing an event channel while handling it

Today it can happen that an event channel is being removed from the
system while the event handling loop is active. This can lead to a
race resulting in crashes or WARN() splats when trying to access the
irq_info structure related to the event channel.

Fix this problem by using a rwlock taken as reader in the event
handling loop and as writer when deallocating the irq_info structure.

As the observed problem was a NULL dereference in evtchn_from_irq()
make this function more robust against races by testing the irq_info
pointer to be not NULL before dereferencing it.

And finally make all accesses to evtchn_to_irq[row][col] atomic ones
in order to avoid seeing partial updates of an array element in irq
handling. Note that irq handling can be entered only for event channels
which have been valid before, so any not populated row isn't a problem
in this regard, as rows are only ever added and never removed.

This is XSA-331.

Cc: stable@vger.kernel.org
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reported-by: Jinoh Kang <luke1337@theori.io>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Wei Liu <wl@xen.org>
drivers/xen/events/events_base.c