From c6d4cb702f4c3ff063520d8661213bab67dab785 Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Mon, 29 Jan 2024 18:18:58 +0100 Subject: [PATCH] nitro_enclaves: Fix race when accessing has_event flag The `has_event` flag is set while holding the `enclave_info_mutex` mutex. Let's also hold the mutex while reading the flag to avoid races. Signed-off-by: Costin Lupu --- drivers/virt/nitro_enclaves/ne_misc_dev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c index f36d6cb3..b4b1ebbd 100644 --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c @@ -1645,9 +1645,13 @@ static __poll_t ne_enclave_poll(struct file *file, poll_table *wait) poll_wait(file, &ne_enclave->eventq, wait); + mutex_lock(&ne_enclave->enclave_info_mutex); + if (ne_enclave->has_event) mask |= EPOLLHUP; + mutex_unlock(&ne_enclave->enclave_info_mutex); + return mask; }