]> git.baikalelectronics.ru Git - kernel.git/commit
usercopy: avoid potentially undefined behavior in pointer math
authorEric Biggers <ebiggers@google.com>
Fri, 19 Aug 2016 19:15:22 +0000 (12:15 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 23 Aug 2016 02:07:55 +0000 (19:07 -0700)
commitff2662ad2836e18d3f5e6c83a2671fcdf9d9b0d6
tree5c77614be62600da9d02d3b57709280e91e7292d
parent477c569de3ab2b342c96d5f8ad646cc9b087c316
usercopy: avoid potentially undefined behavior in pointer math

check_bogus_address() checked for pointer overflow using this expression,
where 'ptr' has type 'const void *':

ptr + n < ptr

Since pointer wraparound is undefined behavior, gcc at -O2 by default
treats it like the following, which would not behave as intended:

(long)n < 0

Fortunately, this doesn't currently happen for kernel code because kernel
code is compiled with -fno-strict-overflow.  But the expression should be
fixed anyway to use well-defined integer arithmetic, since it could be
treated differently by different compilers in the future or could be
reported by tools checking for undefined behavior.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
mm/usercopy.c