UPSTREAM: kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY

Upstream commit 96fedce27e1356a2fff1c270710d9405848db562.

With CONFIG_HARDENED_USERCOPY enabled __check_heap_object() compares and
then subtracts a potentially tagged pointer with a non-tagged address of
the page that this pointer belongs to, which leads to unexpected
behavior.

Untag the pointer in __check_heap_object() before doing any of these
operations.

Link: http://lkml.kernel.org/r/7e756a298d514c4482f52aea6151db34818d395d.1546540962.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Vincenzo Frascino <vincenzo.frascino@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>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Change-Id: I4730bbf1b500a8a59b64e57325965c8affb625e7
Bug: 128674696
tirimbino
Andrey Konovalov 6 years ago committed by Paul Lawrence
parent 6f4b0fa978
commit cbf4ef9086
  1. 2
      mm/slub.c

@ -3848,6 +3848,8 @@ const char *__check_heap_object(const void *ptr, unsigned long n,
unsigned long offset;
size_t object_size;
ptr = kasan_reset_tag(ptr);
/* Find object and usable object size. */
s = page->slab_cache;
object_size = slab_ksize(s);

Loading…
Cancel
Save