Skip to content

Commit f013371

Browse files
committed
xen/events: fix race in evtchn_fifo_unmask()
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>
1 parent 4d3fe31 commit f013371

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/xen/events/events_fifo.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,25 @@ static bool evtchn_fifo_is_masked(evtchn_port_t port)
227227
return sync_test_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word));
228228
}
229229
/*
230-
* Clear MASKED, spinning if BUSY is set.
230+
* Clear MASKED if not PENDING, spinning if BUSY is set.
231+
* Return true if mask was cleared.
231232
*/
232-
static void clear_masked(volatile event_word_t *word)
233+
static bool clear_masked_cond(volatile event_word_t *word)
233234
{
234235
event_word_t new, old, w;
235236

236237
w = *word;
237238

238239
do {
240+
if (w & (1 << EVTCHN_FIFO_PENDING))
241+
return false;
242+
239243
old = w & ~(1 << EVTCHN_FIFO_BUSY);
240244
new = old & ~(1 << EVTCHN_FIFO_MASKED);
241245
w = sync_cmpxchg(word, old, new);
242246
} while (w != old);
247+
248+
return true;
243249
}
244250

245251
static void evtchn_fifo_unmask(evtchn_port_t port)
@@ -248,8 +254,7 @@ static void evtchn_fifo_unmask(evtchn_port_t port)
248254

249255
BUG_ON(!irqs_disabled());
250256

251-
clear_masked(word);
252-
if (evtchn_fifo_is_pending(port)) {
257+
if (!clear_masked_cond(word)) {
253258
struct evtchn_unmask unmask = { .port = port };
254259
(void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
255260
}

0 commit comments

Comments
 (0)