ghes_has_active_errors() walks the SEA and NMI source lists under RCU and reads the mapped error status register for each source. The corresponding removal paths delete the source from the list, but unmap the register before waiting for existing RCU readers.
A reader that obtained the source before list_del_rcu() can therefore dereference the mapping after it has been released. Keep the mapping valid until synchronize_rcu() has drained those readers. Reported-by: [email protected] Link: https://sashiko.dev/#/message/20260708141859.0FA971F000E9%40smtp.kernel.org Fixes: f2edc1fb9c81 ("ACPI: APEI: GHES: Improve ghes_notify_nmi() status check") Fixes: b73cf7eaa6ee ("ACPI: APEI: GHES: Improve ghes_notify_sea() status check") Signed-off-by: Ahmed Tiba <[email protected]> --- drivers/acpi/apei/ghes.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 5d888c82efea..18dc77491277 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -1598,8 +1598,10 @@ static void ghes_sea_remove(struct ghes *ghes) mutex_lock(&ghes_list_mutex); list_del_rcu(&ghes->list); mutex_unlock(&ghes_list_mutex); - ghes_unmap_error_status(ghes); + + /* Wait for RCU readers before unmapping the error status. */ synchronize_rcu(); + ghes_unmap_error_status(ghes); } #else /* CONFIG_ACPI_APEI_SEA */ static inline int ghes_sea_add(struct ghes *ghes) { return -EINVAL; } @@ -1660,13 +1662,12 @@ static void ghes_nmi_remove(struct ghes *ghes) unregister_nmi_handler(NMI_LOCAL, "ghes"); mutex_unlock(&ghes_list_mutex); - ghes_unmap_error_status(ghes); - /* * To synchronize with NMI handler, ghes can only be * freed after NMI handler finishes. */ synchronize_rcu(); + ghes_unmap_error_status(ghes); } #else /* CONFIG_HAVE_ACPI_APEI_NMI */ static inline int ghes_nmi_add(struct ghes *ghes) { return -EINVAL; } -- 2.43.0
