]> Git Repo - linux.git/commitdiff
ACPI: custom_method: fix a possible memory leak
authorMark Langsdorf <[email protected]>
Tue, 27 Apr 2021 18:54:33 +0000 (13:54 -0500)
committerRafael J. Wysocki <[email protected]>
Wed, 28 Apr 2021 17:17:54 +0000 (19:17 +0200)
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 <[email protected]>
Cc: 5.4+ <[email protected]> # 5.4+
Signed-off-by: Rafael J. Wysocki <[email protected]>
drivers/acpi/custom_method.c

index 8844f895f9bed04936e8e4a00f94f4f02b20b2ea..d39a9b474727dc052fd4a6f5079314802615c8fb 100644 (file)
@@ -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;
This page took 0.055085 seconds and 4 git commands to generate.