]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
kasan: Fix a type conversion error
authorWang Long <long.wanglong@huawei.com>
Wed, 21 Oct 2015 22:03:23 +0000 (09:03 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 21 Oct 2015 22:03:23 +0000 (09:03 +1100)
The current KASAN code can not find the following out-of-bounds bugs:

char *ptr;
ptr = kmalloc(8, GFP_KERNEL);
memset(ptr+7, 0, 2);

the cause of the problem is the type conversion error in
*memory_is_poisoned_n* function.  So this patch fix that.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kasan/kasan.c

index 21c50dcbc9f095a91fd9fd47193ef7054b1c7fad..2b21ccd55cd4a867c902d0ea3e7d04f66de7c634 100644 (file)
@@ -203,7 +203,7 @@ static __always_inline bool memory_is_poisoned_n(unsigned long addr,
                s8 *last_shadow = (s8 *)kasan_mem_to_shadow((void *)last_byte);
 
                if (unlikely(ret != (unsigned long)last_shadow ||
-                       ((last_byte & KASAN_SHADOW_MASK) >= *last_shadow)))
+                       ((long)(last_byte & KASAN_SHADOW_MASK) >= *last_shadow)))
                        return true;
        }
        return false;