Commit 82ee8ae3 authored by Russell Currey's avatar Russell Currey Committed by Greg Kroah-Hartman

powerpc/eeh: Avoid use after free in eeh_handle_special_event()

commit daeba295 upstream.

eeh_handle_special_event() is called when an EEH event is detected but
can't be narrowed down to a specific PE.  This function looks through
every PE to find one in an erroneous state, then calls the regular event
handler eeh_handle_normal_event() once it knows which PE has an error.

However, if eeh_handle_normal_event() found that the PE cannot possibly
be recovered, it will free it, rendering the passed PE stale.
This leads to a use after free in eeh_handle_special_event() as it attempts to
clear the "recovering" state on the PE after eeh_handle_normal_event() returns.

Thus, make sure the PE is valid when attempting to clear state in
eeh_handle_special_event().

Fixes: 8a6b1bc7 ("powerpc/eeh: EEH core to handle special event")
Reported-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: default avatarRussell Currey <ruscur@russell.cc>
Reviewed-by: default avatarGavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1c59546e
...@@ -678,7 +678,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus) ...@@ -678,7 +678,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
*/ */
#define MAX_WAIT_FOR_RECOVERY 300 #define MAX_WAIT_FOR_RECOVERY 300
static void eeh_handle_normal_event(struct eeh_pe *pe) static bool eeh_handle_normal_event(struct eeh_pe *pe)
{ {
struct pci_bus *frozen_bus; struct pci_bus *frozen_bus;
int rc = 0; int rc = 0;
...@@ -688,7 +688,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -688,7 +688,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
if (!frozen_bus) { if (!frozen_bus) {
pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n", pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n",
__func__, pe->phb->global_number, pe->addr); __func__, pe->phb->global_number, pe->addr);
return; return false;
} }
eeh_pe_update_time_stamp(pe); eeh_pe_update_time_stamp(pe);
...@@ -805,7 +805,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -805,7 +805,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
pr_info("EEH: Notify device driver to resume\n"); pr_info("EEH: Notify device driver to resume\n");
eeh_pe_dev_traverse(pe, eeh_report_resume, NULL); eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
return; return false;
excess_failures: excess_failures:
/* /*
...@@ -845,7 +845,11 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -845,7 +845,11 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
pci_lock_rescan_remove(); pci_lock_rescan_remove();
pcibios_remove_pci_devices(frozen_bus); pcibios_remove_pci_devices(frozen_bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
/* The passed PE should no longer be used */
return true;
} }
return false;
} }
static void eeh_handle_special_event(void) static void eeh_handle_special_event(void)
...@@ -911,7 +915,14 @@ static void eeh_handle_special_event(void) ...@@ -911,7 +915,14 @@ static void eeh_handle_special_event(void)
*/ */
if (rc == EEH_NEXT_ERR_FROZEN_PE || if (rc == EEH_NEXT_ERR_FROZEN_PE ||
rc == EEH_NEXT_ERR_FENCED_PHB) { rc == EEH_NEXT_ERR_FENCED_PHB) {
eeh_handle_normal_event(pe); /*
* eeh_handle_normal_event() can make the PE stale if it
* determines that the PE cannot possibly be recovered.
* Don't modify the PE state if that's the case.
*/
if (eeh_handle_normal_event(pe))
continue;
eeh_pe_state_clear(pe, EEH_PE_RECOVERING); eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
} else { } else {
pci_lock_rescan_remove(); pci_lock_rescan_remove();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment