Skip to content

Commit 1cfd895

Browse files
mlangsdorfrafaeljw
authored andcommitted
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: 526b4af ("ACPI: Split out custom_method functionality into an own driver") Signed-off-by: Mark Langsdorf <[email protected]> Cc: 5.4+ <[email protected]> # 5.4+ Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e483bb9 commit 1cfd895

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/acpi/custom_method.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
4242
sizeof(struct acpi_table_header)))
4343
return -EFAULT;
4444
uncopied_bytes = max_size = table.length;
45+
/* make sure the buf is not allocated */
46+
kfree(buf);
4547
buf = kzalloc(max_size, GFP_KERNEL);
4648
if (!buf)
4749
return -ENOMEM;

0 commit comments

Comments
 (0)