From 1caf1d3016fcf51a9cb67ac0b750ac90cbc32bbe Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Tue, 22 Dec 2015 17:25:21 +0200 Subject: [PATCH] stm class: Prevent user-controllable allocations Currently, the character device write method allocates a temporary buffer for user's data, but the user's data size is not sanitized and can cause arbitrarily large allocations via kzalloc() or an integer overflow that will then result in overwriting kernel memory. This patch trims the input buffer size to avoid these issues. Reported-by: Sasha Levin Signed-off-by: Alexander Shishkin Signed-off-by: Greg Kroah-Hartman (cherry picked from commit f08b18266c7116e2ec6885dd53a928f580060a71) --- drivers/hwtracing/stm/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index ddcb606acea6..76697ad59f2d 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -406,6 +406,9 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf, char *kbuf; int err; + if (count + 1 > PAGE_SIZE) + count = PAGE_SIZE - 1; + /* * if no m/c have been assigned to this writer up to this * point, use "default" policy entry -- 2.34.1