Thread (55 messages) 55 messages, 7 authors, 2018-09-19
STALE2811d
Revisions (9)
  1. rfc [diff vs current]
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v1 [diff vs current]
  5. v2 [diff vs current]
  6. v3 [diff vs current]
  7. v4 [diff vs current]
  8. v5 [diff vs current]
  9. v6 current

[PATCH v6 11/18] khwasan, mm: perform untagged pointers comparison in krealloc

From: Andrey Konovalov <hidden>
Date: 2018-08-29 11:35:50
Also in: linux-doc, linux-kbuild, linux-mm, lkml
Subsystem: memory management, slab allocator, the rest · Maintainers: Andrew Morton, Vlastimil Babka, Harry Yoo, Linus Torvalds

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
not.

Signed-off-by: Andrey Konovalov <redacted>
---
 mm/slab_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 3abfa0f86118..0d588dfebd7d 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1513,7 +1513,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))
 		kfree(p);
 
 	return ret;
-- 
2.19.0.rc0.228.g281dcd1b4d0-goog
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help