]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ACPI: custom_method: fix a possible memory leak
authorMark Langsdorf <mlangsdo@redhat.com>
Tue, 27 Apr 2021 18:54:33 +0000 (13:54 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 May 2021 08:38:16 +0000 (10:38 +0200)
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 <mlangsdo@redhat.com>
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/acpi/custom_method.c

index c76ab507c1821db5db8653dd1da30b25b358a2cb..ea4c7c93a9209327f2e504d25674c0331362dc83 100644 (file)
@@ -37,6 +37,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;