Skip to content

Commit e483bb9

Browse files
mlangsdorfrafaeljw
authored andcommitted
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: 03d1571 ("ACPI: custom_method: fix memory leaks") Signed-off-by: Mark Langsdorf <[email protected]> Cc: 5.4+ <[email protected]> # 5.4+ Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d8f9176 commit e483bb9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/acpi/custom_method.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
5555
(*ppos + count < count) ||
5656
(count > uncopied_bytes)) {
5757
kfree(buf);
58+
buf = NULL;
5859
return -EINVAL;
5960
}
6061

@@ -76,7 +77,6 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
7677
add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
7778
}
7879

79-
kfree(buf);
8080
return count;
8181
}
8282

0 commit comments

Comments
 (0)