Skip to content

Commit c5a1303

Browse files
Chen Gongaegl
authored andcommitted
ACPI/APEI: Add parameter check before error injection
When param1 is enabled in EINJ but not assigned with a valid value, sometimes it will cause the error like below: APEI: Can not request [mem 0x7aaa7000-0x7aaa7007] for APEI EINJ Trigger registers It is because some firmware will access target address specified in param1 to trigger the error when injecting memory error. This will cause resource conflict with regular memory. So It must be removed from trigger table resources, but incorrect param1/param2 combination will stop this action. Add extra check to avoid this kind of error. Signed-off-by: Chen Gong <gong.chen@linux.intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent b8edb64 commit c5a1303

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎drivers/acpi/apei/einj.c‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/seq_file.h>
3333
#include <linux/nmi.h>
3434
#include <linux/delay.h>
35+
#include <linux/mm.h>
3536
#include <acpi/acpi.h>
3637

3738
#include "apei-internal.h"
@@ -41,6 +42,10 @@
4142
#define SPIN_UNIT 100 /* 100ns */
4243
/* Firmware should respond within 1 milliseconds */
4344
#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
45+
#define ACPI5_VENDOR_BIT BIT(31)
46+
#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \
47+
ACPI_EINJ_MEMORY_UNCORRECTABLE | \
48+
ACPI_EINJ_MEMORY_FATAL)
4449

4550
/*
4651
* ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
@@ -367,7 +372,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
367372
* This will cause resource conflict with regular memory. So
368373
* remove it from trigger table resources.
369374
*/
370-
if ((param_extension || acpi5) && (type & 0x0038) && param2) {
375+
if ((param_extension || acpi5) && (type & MEM_ERROR_MASK) && param2) {
371376
struct apei_resources addr_resources;
372377
apei_resources_init(&addr_resources);
373378
trigger_param_region = einj_get_trigger_parameter_region(
@@ -427,7 +432,7 @@ static int __einj_error_inject(u32 type, u64 param1, u64 param2)
427432
struct set_error_type_with_address *v5param = einj_param;
428433

429434
v5param->type = type;
430-
if (type & 0x80000000) {
435+
if (type & ACPI5_VENDOR_BIT) {
431436
switch (vendor_flags) {
432437
case SETWA_FLAGS_APICID:
433438
v5param->apicid = param1;
@@ -512,7 +517,34 @@ static int __einj_error_inject(u32 type, u64 param1, u64 param2)
512517
static int einj_error_inject(u32 type, u64 param1, u64 param2)
513518
{
514519
int rc;
520+
unsigned long pfn;
515521

522+
/*
523+
* We need extra sanity checks for memory errors.
524+
* Other types leap directly to injection.
525+
*/
526+
527+
/* ensure param1/param2 existed */
528+
if (!(param_extension || acpi5))
529+
goto inject;
530+
531+
/* ensure injection is memory related */
532+
if (type & ACPI5_VENDOR_BIT) {
533+
if (vendor_flags != SETWA_FLAGS_MEM)
534+
goto inject;
535+
} else if (!(type & MEM_ERROR_MASK))
536+
goto inject;
537+
538+
/*
539+
* Disallow crazy address masks that give BIOS leeway to pick
540+
* injection address almost anywhere. Insist on page or
541+
* better granularity and that target address is normal RAM.
542+
*/
543+
pfn = PFN_DOWN(param1 & param2);
544+
if (!page_is_ram(pfn) || ((param2 & PAGE_MASK) != PAGE_MASK))
545+
return -EINVAL;
546+
547+
inject:
516548
mutex_lock(&einj_mutex);
517549
rc = __einj_error_inject(type, param1, param2);
518550
mutex_unlock(&einj_mutex);
@@ -590,7 +622,7 @@ static int error_type_set(void *data, u64 val)
590622
* Vendor defined types have 0x80000000 bit set, and
591623
* are not enumerated by ACPI_EINJ_GET_ERROR_TYPE
592624
*/
593-
vendor = val & 0x80000000;
625+
vendor = val & ACPI5_VENDOR_BIT;
594626
tval = val & 0x7fffffff;
595627

596628
/* Only one error type can be specified */

‎kernel/resource.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ int __weak page_is_ram(unsigned long pfn)
409409
{
410410
return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
411411
}
412+
EXPORT_SYMBOL_GPL(page_is_ram);
412413

413414
void __weak arch_remove_reservations(struct resource *avail)
414415
{

0 commit comments

Comments
 (0)