]> git.baikalelectronics.ru Git - kernel.git/commitdiff
kasan, mm: perform untagged pointers comparison in krealloc
authorAndrey Konovalov <andreyknvl@google.com>
Fri, 28 Dec 2018 08:30:35 +0000 (00:30 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 28 Dec 2018 20:11:43 +0000 (12:11 -0800)
The krealloc function checks where the same buffer was reused or a new one
allocated by comparing kernel pointers.  Tag-based KASAN changes memory
tag on the krealloc'ed chunk of memory and therefore also changes the
pointer tag of the returned pointer.  Therefore we need to perform
comparison on untagged (with tags reset) pointers to check whether it's
the same memory region or not.

Link: http://lkml.kernel.org/r/14f6190d7846186a3506cd66d82446646fe65090.1544099024.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/slab_common.c

index a4a82fbdefd400758c7ec64e32c32d560990d720..bc24100682b03a02cf38fc8c19b834a490313e0f 100644 (file)
@@ -1534,7 +1534,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
        }
 
        ret = __do_krealloc(p, new_size, flags);
-       if (ret && p != ret)
+       if (ret && kasan_reset_tag(p) != kasan_reset_tag(ret))
                kfree(p);
 
        return ret;