Skip to content

Commit 80744a3

Browse files
Dan Carpenterrafaeljw
authored andcommitted
ACPI: APEI: EINJ: prevent memory corruption in error_type_set()
The "einj_buf" buffer is 32 chars. If "count" is larger than that it results in memory corruption. Cap it at 31 so that we leave the last character as a NUL terminator. By the way, the highest reasonable value for "count" is 24. Fixes: 0c6176e ("ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://patch.msgid.link/ae6286cf-4d73-4b97-8c0f-0782a65b8f51@sabinyo.mountain Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8b148a9 commit 80744a3

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/acpi/apei/einj-core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ static ssize_t error_type_set(struct file *file, const char __user *buf,
826826
int rc;
827827
u64 val;
828828

829+
/* Leave the last character for the NUL terminator */
830+
if (count > sizeof(einj_buf) - 1)
831+
return -EINVAL;
832+
829833
memset(einj_buf, 0, sizeof(einj_buf));
830834
if (copy_from_user(einj_buf, buf, count))
831835
return -EFAULT;

0 commit comments

Comments
 (0)