[PATCH v3 1/2] ACPI: sysfs: Fix data_attr leak when creating a data file fails

From: Jamie Nguyen

Date: Mon Nov 09 2026 - 13:13:28 EST


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.

Fixes: 7dae6326ed76 ("ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region")
Signed-off-by: Jamie Nguyen <jamien@xxxxxxxxxx>
---
drivers/acpi/sysfs.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index a4534b3e3cfbb5b..4182627eeafd2f8 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -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;
--
2.43.0