• Eric Biggers's avatar
    usercopy: avoid potentially undefined behavior in pointer math · 7329a655
    Eric Biggers authored
    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: default avatarEric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    7329a655
usercopy.c 7.19 KB