lkml.org 
[lkml]   [2015]   [Jun]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] lib: Limit strnlen_user() return value to count + 1
Date
Currently strnlen_user() can return numbers between 0 and
count + sizeof(unsigned long) - 1. Currently, no in tree users seem to
care but I have found out of tree users which were broken by this. They
wanted to truncate the string if it was too long to fit into a buffer
and didn't count with the fact that strnlen_user() can return more.
So make the function harder to use wrong and return count + 1 max.

CC: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
lib/strnlen_user.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
index fd03ae980013..2e47f9e16a79 100644
--- a/lib/strnlen_user.c
+++ b/lib/strnlen_user.c
@@ -54,7 +54,10 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count,
if (has_zero(c, &data, &constants)) {
data = prep_zero_mask(c, data, &constants);
data = create_zero_mask(data);
- return res + find_zero(data) + 1 - align;
+ res = res + find_zero(data) + 1 - align;
+ if (res > count)
+ return count + 1;
+ return res;
}
res += sizeof(unsigned long);
if (unlikely(max <= sizeof(unsigned long)))
--
2.1.4


\
 
 \ /
  Last update: 2015-06-02 18:01    [W:0.386 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site