ANDROID: kasan: sync vmalloc support with linux-next/akpm
The FROMLIST patches merged in aosp/1974918 that add vmalloc support to KASAN now have a few fixes staged in linux-next/akpm. Sync the changes. Bug: 217222520 Bug: 222221793 Change-Id: I33dd30e3834a4d1bb8eac611b350004afdb08a74 Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
This commit is contained in:
committed by
Todd Kjos
parent
78c7e3132d
commit
4b6f018168
@@ -32,7 +32,8 @@ static void *__scs_alloc(int node)
|
||||
for (i = 0; i < NR_CACHED_SCS; i++) {
|
||||
s = this_cpu_xchg(scs_cache[i], NULL);
|
||||
if (s) {
|
||||
kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE);
|
||||
kasan_unpoison_vmalloc(s, SCS_SIZE,
|
||||
KASAN_VMALLOC_PROT_NORMAL);
|
||||
memset(s, 0, SCS_SIZE);
|
||||
return s;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ void scs_free(void *s)
|
||||
if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL)
|
||||
return;
|
||||
|
||||
kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE);
|
||||
kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_PROT_NORMAL);
|
||||
vfree_atomic(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -1058,7 +1058,6 @@ static void kmalloc_double_kzfree(struct kunit *test)
|
||||
static void vmalloc_helpers_tags(struct kunit *test)
|
||||
{
|
||||
void *ptr;
|
||||
int rv;
|
||||
|
||||
/* This test is intended for tag-based modes. */
|
||||
KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
|
||||
@@ -1076,11 +1075,17 @@ static void vmalloc_helpers_tags(struct kunit *test)
|
||||
KUNIT_ASSERT_TRUE(test, is_vmalloc_addr(ptr));
|
||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vmalloc_to_page(ptr));
|
||||
|
||||
#if !IS_MODULE(CONFIG_KASAN_KUNIT_TEST)
|
||||
{
|
||||
int rv;
|
||||
|
||||
/* Make sure vmalloc'ed memory permissions can be changed. */
|
||||
rv = set_memory_ro((unsigned long)ptr, 1);
|
||||
KUNIT_ASSERT_GE(test, rv, 0);
|
||||
rv = set_memory_rw((unsigned long)ptr, 1);
|
||||
KUNIT_ASSERT_GE(test, rv, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
vfree(ptr);
|
||||
}
|
||||
|
||||
@@ -484,10 +484,11 @@ void *__kasan_unpoison_vmalloc(const void *start, unsigned long size,
|
||||
return (void *)start;
|
||||
|
||||
/*
|
||||
* Don't tag executable memory.
|
||||
* Don't tag executable memory with the tag-based mode.
|
||||
* The kernel doesn't tolerate having the PC register tagged.
|
||||
*/
|
||||
if (!(flags & KASAN_VMALLOC_PROT_NORMAL))
|
||||
if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) &&
|
||||
!(flags & KASAN_VMALLOC_PROT_NORMAL))
|
||||
return (void *)start;
|
||||
|
||||
start = set_tag(start, kasan_random_tag());
|
||||
|
||||
Reference in New Issue
Block a user