Skip to content

Commit 35e60a6

Browse files
committed
Merge tag 'acpi-4.12-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI fixes from Rafael Wysocki: "These revert an ACPICA commit from the 4.11 cycle that causes problems to happen on some systems and add a protection against possible kernel crashes due to table reference counter imbalance. Specifics: - Revert a 4.11 ACPICA change that made assumptions which are not satisfied on some systems and caused the enumeration of resources to fail on them (Rafael Wysocki). - Add a mechanism to prevent tables from being unmapped prematurely due to reference counter overflows (Lv Zheng)" * tag 'acpi-4.12-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: ACPICA: Tables: Mechanism to handle late stage acpi_get_table() imbalance Revert "ACPICA: Disassembler: Enhance resource descriptor detection"
2 parents 92091c4 + 9522933 commit 35e60a6

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

drivers/acpi/acpica/tbutils.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,18 @@ acpi_tb_get_table(struct acpi_table_desc *table_desc,
416416
}
417417
}
418418

419-
table_desc->validation_count++;
420-
if (table_desc->validation_count == 0) {
421-
table_desc->validation_count--;
419+
if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
420+
table_desc->validation_count++;
421+
422+
/*
423+
* Detect validation_count overflows to ensure that the warning
424+
* message will only be printed once.
425+
*/
426+
if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
427+
ACPI_WARNING((AE_INFO,
428+
"Table %p, Validation count overflows\n",
429+
table_desc));
430+
}
422431
}
423432

424433
*out_table = table_desc->pointer;
@@ -445,13 +454,20 @@ void acpi_tb_put_table(struct acpi_table_desc *table_desc)
445454

446455
ACPI_FUNCTION_TRACE(acpi_tb_put_table);
447456

448-
if (table_desc->validation_count == 0) {
449-
ACPI_WARNING((AE_INFO,
450-
"Table %p, Validation count is zero before decrement\n",
451-
table_desc));
452-
return_VOID;
457+
if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
458+
table_desc->validation_count--;
459+
460+
/*
461+
* Detect validation_count underflows to ensure that the warning
462+
* message will only be printed once.
463+
*/
464+
if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
465+
ACPI_WARNING((AE_INFO,
466+
"Table %p, Validation count underflows\n",
467+
table_desc));
468+
return_VOID;
469+
}
453470
}
454-
table_desc->validation_count--;
455471

456472
if (table_desc->validation_count == 0) {
457473

drivers/acpi/acpica/utresrc.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,6 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state,
474474
return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
475475
}
476476

477-
/*
478-
* The end_tag opcode must be followed by a zero byte.
479-
* Although this byte is technically defined to be a checksum,
480-
* in practice, all ASL compilers set this byte to zero.
481-
*/
482-
if (*(aml + 1) != 0) {
483-
return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
484-
}
485-
486477
/* Return the pointer to the end_tag if requested */
487478

488479
if (!user_function) {

include/acpi/actbl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ struct acpi_table_desc {
374374
u16 validation_count;
375375
};
376376

377+
/*
378+
* Maximum value of the validation_count field in struct acpi_table_desc.
379+
* When reached, validation_count cannot be changed any more and the table will
380+
* be permanently regarded as validated.
381+
*
382+
* This is to prevent situations in which unbalanced table get/put operations
383+
* may cause premature table unmapping in the OS to happen.
384+
*
385+
* The maximum validation count can be defined to any value, but should be
386+
* greater than the maximum number of OS early stage mapping slots to avoid
387+
* leaking early stage table mappings to the late stage.
388+
*/
389+
#define ACPI_MAX_TABLE_VALIDATIONS ACPI_UINT16_MAX
390+
377391
/* Masks for Flags field above */
378392

379393
#define ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL (0) /* Virtual address, external maintained */

0 commit comments

Comments
 (0)