ACPI: sysfs: Expose BDAT data region
v3 cover ACPI: sysfs: Expose BDAT data region
The BIOS Data ACPI Table (BDAT) points to a firmware data structure that carries memory training results and other boot-time data. Patch 2 exposes that data as /sys/firmware/acpi/tables/data/BDAT, like the existing BERT and CCEL data files.
Patch 1 fixes a leak in the existing data file code, where data_attr is not freed if sysfs_create_bin_file() fails. It moves the file creation and the cleanup into acpi_table_data_init(), and patch 2 builds on that.
Changes in v3:
- Rebased onto v7.4-rc1, which includes the two fixes posted during the v2 review [1][2]. No code changes.
- Dropped the "Assisted-by:" tag as per latest guidelines, though an LLM was used to write, review, and test this series.
Changes in v2:
- New patch 1, fixing the data_attr leak for BERT and CCEL as well.
- Patch 2: the BDAT callback only checks the table and sets the address and size of the data, and returns -ENOMEM if mapping the header fails.
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]
[1]: https://lore.kernel.org/r/[email protected]
[2]: https://lore.kernel.org/r/[email protected]
Tested on an arm64 server (64K pages):
- The file matches a /dev/mem dump of the data region taken in the same boot, byte for byte, and decodes with valid CRCs.
- With lockdown=integrity, /dev/mem is refused and the file still reads.
- Malformed BDAT tables loaded via initrd table upgrade (test-only change adding BDAT to table_sigs[]) are rejected without creating a file: no "BDATHEAD" signature, size below the header, non-memory address space, zero address, and a table shorter than struct acpi_table_bdat.
- With a test-only change that makes sysfs_create_bin_file() fail with -EEXIST for one BDAT table, kmemleak reports its data_attr as leaked without patch 1, and the data_attr is freed with patch 1 applied.
Jamie Nguyen (2):
ACPI: sysfs: Fix data_attr leak when creating a data file fails
ACPI: sysfs: Expose BDAT data region
Documentation/ABI/testing/sysfs-firmware-acpi | 12 ++++ drivers/acpi/sysfs.c | 69 ++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.43.0
PATCH v3 1/2 ACPI: sysfs: Fix data_attr leak when creating a data file fails
acpi_table_data_init() allocates the data_attr for a table's data file and passes it to the table's init callback. The BERT and CCEL callbacks free data_attr when the table is invalid, but return the result of sysfs_create_bin_file() directly, so data_attr is leaked if creating the file fails.
Create the file and free data_attr on failure in acpi_table_data_init() instead, so that the callbacks only check the table and set the address and size of the data.
--- drivers/acpi/sysfs.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/acpi/sysfs.c +14 -10
@@ -454,14 +454,13 @@ static int acpi_bert_data_init(void *th, struct acpi_data_attr *data_attr)struct acpi_table_bert *bert = th;if (bert->header.length <sizeof (struct acpi_table_bert ) || - bert->region_length <sizeof (struct acpi_bert_region )) { -kfree (data_attr); + bert->region_length <sizeof (struct acpi_bert_region ))return -EINVAL ; - } + data_attr->addr = bert->address; data_attr->attr.size = bert->region_length; -return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +return 0 ; }static int acpi_ccel_data_init (void *th,struct acpi_data_attr *data_attr)
@@ -469,14 +468,13 @@ static int acpi_ccel_data_init(void *th, struct acpi_data_attr *data_attr)struct acpi_table_ccel *ccel = th;if (ccel->header.length <sizeof (struct acpi_table_ccel ) || - !ccel->log_area_start_address || !ccel->log_area_minimum_length) { -kfree (data_attr); + !ccel->log_area_start_address || !ccel->log_area_minimum_length)return -EINVAL ; - } + data_attr->addr = ccel->log_area_start_address; data_attr->attr.size = ccel->log_area_minimum_length; -return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +return 0 ; } static struct acpi_data_obj {
@@ -492,7 +490,7 @@ static struct acpi_data_obj {static int acpi_table_data_init (struct acpi_table_header *th,struct acpi_table_attr *table_attr) {struct acpi_data_attr *data_attr; -int i; +int i, ret;for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) {if (ACPI_COMPARE_NAMESEG (th->signature, acpi_data_objs[i].name)) {
@@ -504,7 +502,13 @@ static int acpi_table_data_init(struct acpi_table_header *th, struct acpi_table_ data_attr->attr.attr.mode =0400 ;strscpy (data_attr->filename, table_attr->filename); data_attr->attr.attr.name = data_attr->filename; -return acpi_data_objs[i].fn (th, data_attr); + ret = acpi_data_objs[i].fn (th, data_attr); +if (!ret) + ret =sysfs_create_bin_file (tables_data_kobj, + &data_attr->attr); +if (ret) +kfree (data_attr); +return ret; } }return 0 ;
Signature · 1 line
2.43.0
PATCH v3 2/2 ACPI: sysfs: Expose BDAT data region
In reply to Jamie NguyenThe BIOS Data ACPI Table (BDAT) points to a firmware data structure that carries memory training results and other boot-time data. The table is only a pointer: /sys/firmware/acpi/tables/BDAT holds the ACPI header and a Generic Address Structure, and the data itself lives in reserved memory.
Expose the data as /sys/firmware/acpi/tables/data/BDAT, as is already done for BERT and CCEL. Unlike those tables, BDAT carries no length, so check the "BDATHEAD" signature at the start of the data structure and take the size from its BiosDataStructSize field. Reject sizes smaller than that header, and document the new file in Documentation/ABI.
The BDAT specification is published by the UEFI Forum [1].
--- Documentation/ABI/testing/sysfs-firmware-acpi | 12 +++++ drivers/acpi/sysfs.c | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+)
Documentation/ABI/testing/sysfs-firmware-acpi +12 -0
@@ -275,3 +275,15 @@ Description: remote_region_id: ID associated with access by agents non-local to this range of addresses. + +What: /sys/firmware/acpi/tables/data/BDAT +Date: October 2026 +Contact: Jamie Nguyen <[email protected]> +Description: + The BIOS data structure referenced by the ACPI BDAT (BIOS Data + ACPI Table). It starts with a "BDATHEAD" header and holds data + published by firmware, such as memory training results. The + file size is the structure size given in that header. + + The format is defined by the BDAT Interface Specification, + published by the UEFI Forum. The file is readable by root only.
drivers/acpi/sysfs.c +45 -0
57 lines not on this page · raw message
Signature · 1 line
2.43.0