diff mbox

[v3,10/17] khwasan, mm: perform untagged pointers comparison in krealloc

Message ID 6ab2ac0b6a7d12d2a6616e847732305dde544a99.1529515183.git.andreyknvl@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrey Konovalov June 20, 2018, 5:39 p.m. UTC
The krealloc function checks where the same buffer was reused or a new one
allocated by comparing kernel pointers. KHWASAN 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

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
 mm/slab_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox


diff --git a/mm/slab_common.c b/mm/slab_common.c
index c279b52c7565..7746d2ef5d45 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1509,7 +1509,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 && khwasan_reset_tag(p) != khwasan_reset_tag(ret))
 	return ret;