From: Andrey Konovalov Date: Fri, 28 Dec 2018 08:30:35 +0000 (-0800) Subject: kasan, mm: perform untagged pointers comparison in krealloc X-Git-Tag: v5.0-rc1~107^2~152 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=772a2fa50ffb2f4282be8436da6e70530a2ac63c;p=people%2Froyger%2Flinux.git kasan, mm: perform untagged pointers comparison in krealloc 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 Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Cc: Christoph Lameter Cc: Mark Rutland Cc: Will Deacon Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/slab_common.c b/mm/slab_common.c index a4a82fbdefd4..bc24100682b0 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -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;