andrey.k...@linux.dev
unread,Mar 2, 2022, 10:13:40 AM3/2/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Andrew Morton, Andrey Konovalov, Marco Elver, Alexander Potapenko, Dmitry Vyukov, Andrey Ryabinin, kasa...@googlegroups.com, Will Deacon, Sami Tolvanen, linu...@kvack.org, linux-...@vger.kernel.org, Andrey Konovalov
From: Andrey Konovalov <
andre...@google.com>
Fix up the custom KASAN instrumentation for Shadow Call Stack to support
vmalloc() mappings and pointers being tagged.
- Use the tagged pointer returned by kasan_unpoison_vmalloc() in
__scs_alloc() when calling memset() to avoid false-positives.
- Do not return a tagged Shadow Call Stack pointer from __scs_alloc(),
as this might lead to conflicts with the instrumentation.
Andrew, please put this patch after
"kasan, vmalloc: only tag normal vmalloc allocations".
---
kernel/scs.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/scs.c b/kernel/scs.c
index 1033a76a3284..b7e1b096d906 100644
--- a/kernel/scs.c
+++ b/kernel/scs.c
@@ -32,16 +32,19 @@ 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_PROT_NORMAL);
+ s = kasan_unpoison_vmalloc(s, SCS_SIZE,
+ KASAN_VMALLOC_PROT_NORMAL);
memset(s, 0, SCS_SIZE);
- return s;
+ goto out;
}
}
- return __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
+ s = __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
GFP_SCS, PAGE_KERNEL, 0, node,
__builtin_return_address(0));
+
+out:
+ return kasan_reset_tag(s);
}
void *scs_alloc(int node)
--
2.25.1