xen/evtchn: Add missing barriers when accessing/allocating an event channel
authorJulien Grall <jgrall@amazon.com>
Tue, 22 Sep 2020 13:49:40 +0000 (15:49 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2020 13:49:40 +0000 (15:49 +0200)
commit112992b05b2d2ca63f3c78eefe1cf8d192d7303a
tree355ae46c106037213b78d6408d62b18ab1f99c76
parent910093d54fc758e7d69261b344fdc8da3a7bd81e
xen/evtchn: Add missing barriers when accessing/allocating an event channel

While the allocation of a bucket is always performed with the per-domain
lock, the bucket may be accessed without the lock taken (for instance, see
evtchn_send()).

Instead such sites relies on port_is_valid() to return a non-zero value
when the port has a struct evtchn associated to it. The function will
mostly check whether the port is less than d->valid_evtchns as all the
buckets/event channels should be allocated up to that point.

Unfortunately a compiler is free to re-order the assignment in
evtchn_allocate_port() so it would be possible to have d->valid_evtchns
updated before the new bucket has finish to allocate.

Additionally on Arm, even if this was compiled "correctly", the
processor can still re-order the memory access.

Add a write memory barrier in the allocation side and a read memory
barrier when the port is valid to prevent any re-ordering issue.

This is XSA-340.

Reported-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/common/event_channel.c
xen/include/xen/event.h