Skip to content

Commit fc7fb94

Browse files
ruscurgregkh
authored andcommitted
powerpc/eeh: Avoid use after free in eeh_handle_special_event()
commit daeba2956f32f91f3493788ff6ee02fb1b2f02fa 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: 8a6b1bc ("powerpc/eeh: EEH core to handle special event") Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Russell Currey <ruscur@russell.cc> Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 93d0380 commit fc7fb94

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

arch/powerpc/kernel/eeh_driver.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
655655
*/
656656
#define MAX_WAIT_FOR_RECOVERY 300
657657

658-
static void eeh_handle_normal_event(struct eeh_pe *pe)
658+
static bool eeh_handle_normal_event(struct eeh_pe *pe)
659659
{
660660
struct pci_bus *frozen_bus;
661661
int rc = 0;
@@ -665,7 +665,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
665665
if (!frozen_bus) {
666666
pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n",
667667
__func__, pe->phb->global_number, pe->addr);
668-
return;
668+
return false;
669669
}
670670

671671
eeh_pe_update_time_stamp(pe);
@@ -790,7 +790,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
790790
pr_info("EEH: Notify device driver to resume\n");
791791
eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
792792

793-
return;
793+
return false;
794794

795795
excess_failures:
796796
/*
@@ -831,7 +831,11 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
831831
pci_lock_rescan_remove();
832832
pcibios_remove_pci_devices(frozen_bus);
833833
pci_unlock_rescan_remove();
834+
835+
/* The passed PE should no longer be used */
836+
return true;
834837
}
838+
return false;
835839
}
836840

837841
static void eeh_handle_special_event(void)
@@ -897,7 +901,14 @@ static void eeh_handle_special_event(void)
897901
*/
898902
if (rc == EEH_NEXT_ERR_FROZEN_PE ||
899903
rc == EEH_NEXT_ERR_FENCED_PHB) {
900-
eeh_handle_normal_event(pe);
904+
/*
905+
* eeh_handle_normal_event() can make the PE stale if it
906+
* determines that the PE cannot possibly be recovered.
907+
* Don't modify the PE state if that's the case.
908+
*/
909+
if (eeh_handle_normal_event(pe))
910+
continue;
911+
901912
eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
902913
} else {
903914
pci_lock_rescan_remove();

0 commit comments

Comments
 (0)