Skip to contentSkip to conversation

ACPI: custom_method: fix a possible memory leak

PATCH New Mark Langsdorf 1 participant 1 message Apr 27, 2021 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: custom_method: fix a possible memory leak

In cm_write(), if the 'buf' is allocated memory but not fully consumed, it is possible to reallocate the buffer without freeing it by passing '*ppos' as 0 on a subsequent call.

Add an explicit kfree() before kzalloc() to prevent the possible memory leak.

Fixes 526b4af47f44 ("ACPI: Split out custom_method functionality into an own driver")
---
 drivers/acpi/custom_method.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/custom_method.c +2 -0
index 443fdf62dd22..6dc96f2cef1d 100644
@@ -42,6 +42,8 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
 				   sizeof(struct acpi_table_header)))
 			return -EFAULT;
 		uncopied_bytes = max_size = table.length;
+		/* make sure the buf is not allocated */
+		kfree(buf);
 		buf = kzalloc(max_size, GFP_KERNEL);
 		if (!buf)
 			return -ENOMEM;
Signature · 1 line
2.26.3