x86_64: Fix strnlen_user() to not touch memory after specified maximum
authorBen Hutchings <ben@decadent.org.uk>
Tue, 21 Jul 2015 14:42:59 +0000 (15:42 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 6 Aug 2015 23:32:13 +0000 (00:32 +0100)
Inspired by commit f18c34e483ff ("lib: Fix strnlen_user() to not touch
memory after specified maximum") upstream.  This version of
strnlen_user(), no longer present upstream, has a similar off-by-one
error.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Jan Kara <jack@suse.cz>
arch/x86/lib/usercopy_64.c

index 554b7b5..433b21d 100644 (file)
@@ -113,7 +113,7 @@ long __strnlen_user(const char __user *s, long n)
        char c;
 
        while (1) {
-               if (res>n)
+               if (res >= n)
                        return n+1;
                if (__get_user(c, s))
                        return 0;