kasan, mm: perform untagged pointers comparison in krealloc
authorAndrey Konovalov <[email protected]>
Fri, 28 Dec 2018 08:30:35 +0000 (00:30 -0800)
committerLinus Torvalds <[email protected]>
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 <[email protected]>
Reviewed-by: Andrey Ryabinin <[email protected]>
Reviewed-by: Dmitry Vyukov <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
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;