Skip to content

Commit e2abc47

Browse files
shijujose4rafaeljw
authored andcommitted
ACPI: APEI: Fix AER info corruption when error status data has multiple sections
ghes_handle_aer() passes AER data to the PCI core for logging and recovery by calling aer_recover_queue() with a pointer to struct aer_capability_regs. The problem was that aer_recover_queue() queues the pointer directly without copying the aer_capability_regs data. The pointer was to the ghes->estatus buffer, which could be reused before aer_recover_work_func() reads the data. To avoid this problem, allocate a new aer_capability_regs structure from the ghes_estatus_pool, copy the AER data from the ghes->estatus buffer into it, pass a pointer to the new struct to aer_recover_queue(), and free it after aer_recover_work_func() has processed it. Reported-by: Bjorn Helgaas <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Signed-off-by: Shiju Jose <[email protected]> [ rjw: Subject edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ce9ecca commit e2abc47

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

drivers/acpi/apei/ghes.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ int ghes_estatus_pool_init(unsigned int num_ghes)
209209
return -ENOMEM;
210210
}
211211

212+
/**
213+
* ghes_estatus_pool_region_free - free previously allocated memory
214+
* from the ghes_estatus_pool.
215+
* @addr: address of memory to free.
216+
* @size: size of memory to free.
217+
*
218+
* Returns none.
219+
*/
220+
void ghes_estatus_pool_region_free(unsigned long addr, u32 size)
221+
{
222+
gen_pool_free(ghes_estatus_pool, addr, size);
223+
}
224+
EXPORT_SYMBOL_GPL(ghes_estatus_pool_region_free);
225+
212226
static int map_gen_v2(struct ghes *ghes)
213227
{
214228
return apei_map_generic_address(&ghes->generic_v2->read_ack_register);
@@ -564,6 +578,7 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
564578
pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) {
565579
unsigned int devfn;
566580
int aer_severity;
581+
u8 *aer_info;
567582

568583
devfn = PCI_DEVFN(pcie_err->device_id.device,
569584
pcie_err->device_id.function);
@@ -577,11 +592,17 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
577592
if (gdata->flags & CPER_SEC_RESET)
578593
aer_severity = AER_FATAL;
579594

595+
aer_info = (void *)gen_pool_alloc(ghes_estatus_pool,
596+
sizeof(struct aer_capability_regs));
597+
if (!aer_info)
598+
return;
599+
memcpy(aer_info, pcie_err->aer_info, sizeof(struct aer_capability_regs));
600+
580601
aer_recover_queue(pcie_err->device_id.segment,
581602
pcie_err->device_id.bus,
582603
devfn, aer_severity,
583604
(struct aer_capability_regs *)
584-
pcie_err->aer_info);
605+
aer_info);
585606
}
586607
#endif
587608
}

drivers/pci/pcie/aer.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/kfifo.h>
3030
#include <linux/slab.h>
3131
#include <acpi/apei.h>
32+
#include <acpi/ghes.h>
3233
#include <ras/ras_event.h>
3334

3435
#include "../pci.h"
@@ -996,6 +997,15 @@ static void aer_recover_work_func(struct work_struct *work)
996997
continue;
997998
}
998999
cper_print_aer(pdev, entry.severity, entry.regs);
1000+
/*
1001+
* Memory for aer_capability_regs(entry.regs) is being allocated from the
1002+
* ghes_estatus_pool to protect it from overwriting when multiple sections
1003+
* are present in the error status. Thus free the same after processing
1004+
* the data.
1005+
*/
1006+
ghes_estatus_pool_region_free((unsigned long)entry.regs,
1007+
sizeof(struct aer_capability_regs));
1008+
9991009
if (entry.severity == AER_NONFATAL)
10001010
pcie_do_recovery(pdev, pci_channel_io_normal,
10011011
aer_root_reset);

include/acpi/ghes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ int ghes_register_vendor_record_notifier(struct notifier_block *nb);
7373
void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
7474

7575
struct list_head *ghes_get_devices(void);
76+
77+
void ghes_estatus_pool_region_free(unsigned long addr, u32 size);
7678
#else
7779
static inline struct list_head *ghes_get_devices(void) { return NULL; }
80+
81+
static inline void ghes_estatus_pool_region_free(unsigned long addr, u32 size) { return; }
7882
#endif
7983

8084
int ghes_estatus_pool_init(unsigned int num_ghes);

0 commit comments

Comments
 (0)