Skip to content

Commit 0aa41ca

Browse files
melvertorvalds
authored andcommitted
kfence: fix reports if constant function prefixes exist
Some architectures prefix all functions with a constant string ('.' on ppc64). Add ARCH_FUNC_PREFIX, which may optionally be defined in <asm/kfence.h>, so that get_stack_skipnr() can work properly. Link: https://lkml.kernel.org/r/f036c53d-7e81-763c-47f4-6024c6c5f058@csgroup.eu Link: https://lkml.kernel.org/r/20210304144000.1148590-1-elver@google.com Signed-off-by: Marco Elver <elver@google.com> Reported-by: Christophe Leroy <christophe.leroy@csgroup.eu> Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Alexander Potapenko <glider@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Andrey Konovalov <andreyknvl@google.com> Cc: Jann Horn <jannh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent df3ae2c commit 0aa41ca

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

mm/kfence/report.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#include "kfence.h"
2222

23+
/* May be overridden by <asm/kfence.h>. */
24+
#ifndef ARCH_FUNC_PREFIX
25+
#define ARCH_FUNC_PREFIX ""
26+
#endif
27+
2328
extern bool no_hash_pointers;
2429

2530
/* Helper function to either print to a seq_file or to console. */
@@ -67,8 +72,9 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
6772
for (skipnr = 0; skipnr < num_entries; skipnr++) {
6873
int len = scnprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skipnr]);
6974

70-
if (str_has_prefix(buf, "kfence_") || str_has_prefix(buf, "__kfence_") ||
71-
!strncmp(buf, "__slab_free", len)) {
75+
if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfence_") ||
76+
str_has_prefix(buf, ARCH_FUNC_PREFIX "__kfence_") ||
77+
!strncmp(buf, ARCH_FUNC_PREFIX "__slab_free", len)) {
7278
/*
7379
* In case of tail calls from any of the below
7480
* to any of the above.
@@ -77,10 +83,10 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
7783
}
7884

7985
/* Also the *_bulk() variants by only checking prefixes. */
80-
if (str_has_prefix(buf, "kfree") ||
81-
str_has_prefix(buf, "kmem_cache_free") ||
82-
str_has_prefix(buf, "__kmalloc") ||
83-
str_has_prefix(buf, "kmem_cache_alloc"))
86+
if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfree") ||
87+
str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_free") ||
88+
str_has_prefix(buf, ARCH_FUNC_PREFIX "__kmalloc") ||
89+
str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_alloc"))
8490
goto found;
8591
}
8692
if (fallback < num_entries)

0 commit comments

Comments
 (0)