ACPI: custom_method: fix potential use-after-free issue

In cm_write(), buf is always freed when reaching the end of the
function.  If the requested count is less than table.length, the
allocated buffer will be freed but subsequent calls to cm_write() will
still try to access it.

Remove the unconditional kfree(buf) at the end of the function and
set the buf to NULL in the -EINVAL error path to match the rest of
function.

Fixes: 03d1571d95 ("ACPI: custom_method: fix memory leaks")
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>
This commit is contained in:
Mark Langsdorf 2021-04-23 10:28:17 -05:00 committed by Rafael J. Wysocki
parent d8f9176b4e
commit e483bb9a99
1 changed files with 1 additions and 1 deletions

View File

@ -55,6 +55,7 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
(*ppos + count < count) || (*ppos + count < count) ||
(count > uncopied_bytes)) { (count > uncopied_bytes)) {
kfree(buf); kfree(buf);
buf = NULL;
return -EINVAL; return -EINVAL;
} }
@ -76,7 +77,6 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
} }
kfree(buf);
return count; return count;
} }