[PATCH 5.4 003/184] ACPI: custom_method: fix a possible memory leak

From
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date
2021-05-10 10:23:51
Also in
lkml
Reply to
Greg Kroah-Hartman, 2021-05-10
From: Mark Langsdorf <redacted>

commit 1cfd8956437f842836e8a066b40d1ec2fc01f13e upstream.

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")
Signed-off-by: Mark Langsdorf <redacted>
Cc: 5.4+ <redacted> # 5.4+
Signed-off-by: Rafael J. Wysocki <redacted>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/acpi/custom_method.c |    2 ++
 1 file changed, 2 insertions(+)
--- a/drivers/acpi/custom_method.c
+++ b/drivers/acpi/custom_method.c
@@ -44,6 +44,8 @@ static ssize_t cm_write(struct file *fil
 				   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;

Thread (202 messages) 202 messages, 10 authors, last reply 2021-06-18
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help