]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
xen/events: fix race in evtchn_fifo_unmask()
authorJuergen Gross <jgross@suse.com>
Tue, 20 Oct 2020 04:52:55 +0000 (06:52 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Thu, 10 Dec 2020 11:02:37 +0000 (12:02 +0100)
BugLink: https://bugs.launchpad.net/bugs/1904450
commit f01337197419b7e8a492e83089552b77d3b5fb90 upstream.

Unmasking a fifo event channel can result in unmasking it twice, once
directly in the kernel and once via a hypercall in case the event was
pending.

Fix that by doing the local unmask only if the event is not pending.

This is part of XSA-332.

Cc: stable@vger.kernel.org
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: William Breathitt Gray <william.gray@canonical.com>
drivers/xen/events/events_fifo.c

index 76b318e88382e1e83448f8a42caac995651bd4a9..3071256a9413196c8b04561b29fcc8aa621580fc 100644 (file)
@@ -227,19 +227,25 @@ static bool evtchn_fifo_is_masked(unsigned port)
        return sync_test_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word));
 }
 /*
- * Clear MASKED, spinning if BUSY is set.
+ * Clear MASKED if not PENDING, spinning if BUSY is set.
+ * Return true if mask was cleared.
  */
-static void clear_masked(volatile event_word_t *word)
+static bool clear_masked_cond(volatile event_word_t *word)
 {
        event_word_t new, old, w;
 
        w = *word;
 
        do {
+               if (w & (1 << EVTCHN_FIFO_PENDING))
+                       return false;
+
                old = w & ~(1 << EVTCHN_FIFO_BUSY);
                new = old & ~(1 << EVTCHN_FIFO_MASKED);
                w = sync_cmpxchg(word, old, new);
        } while (w != old);
+
+       return true;
 }
 
 static void evtchn_fifo_unmask(unsigned port)
@@ -248,8 +254,7 @@ static void evtchn_fifo_unmask(unsigned port)
 
        BUG_ON(!irqs_disabled());
 
-       clear_masked(word);
-       if (evtchn_fifo_is_pending(port)) {
+       if (!clear_masked_cond(word)) {
                struct evtchn_unmask unmask = { .port = port };
                (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
        }