[PATCH 1/1] mm/kasan: avoid export __kasan_kmalloc

1 view
Skip to first unread message

yanju...@linux.dev

unread,
Sep 29, 2021, 3:26:44 AMSep 29
to ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org, Zhu Yanjun
From: Zhu Yanjun <yanju...@linux.dev>

Since the function __kasan_kmalloc is only used in kasan module,
remove EXPORT_SYMBOL to this function.

Signed-off-by: Zhu Yanjun <yanju...@linux.dev>
---
mm/kasan/common.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 2baf121fb8c5..714535291ec6 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -521,7 +521,6 @@ void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object
{
return ____kasan_kmalloc(cache, object, size, flags);
}
-EXPORT_SYMBOL(__kasan_kmalloc);

void * __must_check __kasan_kmalloc_large(const void *ptr, size_t size,
gfp_t flags)
--
2.27.0

Marco Elver

unread,
Sep 29, 2021, 8:42:47 AMSep 29
to yanju...@linux.dev, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
On Wed, Sep 29, 2021 at 07:49PM -0400, yanju...@linux.dev wrote:
> From: Zhu Yanjun <yanju...@linux.dev>
>
> Since the function __kasan_kmalloc is only used in kasan module,
> remove EXPORT_SYMBOL to this function.

This is incorrect, see below.

> @@ -521,7 +521,6 @@ void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object
> {
> return ____kasan_kmalloc(cache, object, size, flags);
> }
> -EXPORT_SYMBOL(__kasan_kmalloc);

Sorry, but this will break all users of kmalloc() with KASAN on if
!TRACING:

__always_inline kmalloc() include/linux/slab.h
-> __always_inline kmem_cache_alloc_trace() include/linux/slab.h
-> __always_inline kasan_kmalloc() include/linux/kasan.h
-> __kasan_kmalloc() mm/kasan/common.c

Marco Elver

unread,
Sep 29, 2021, 8:45:31 AMSep 29
to yanju...@linux.dev, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
On Wed, 29 Sept 2021 at 14:42, Marco Elver <el...@google.com> wrote:
>
> On Wed, Sep 29, 2021 at 07:49PM -0400, yanju...@linux.dev wrote:
> > From: Zhu Yanjun <yanju...@linux.dev>
> >
> > Since the function __kasan_kmalloc is only used in kasan module,
> > remove EXPORT_SYMBOL to this function.
>
> This is incorrect, see below.
>
> > @@ -521,7 +521,6 @@ void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object
> > {
> > return ____kasan_kmalloc(cache, object, size, flags);
> > }
> > -EXPORT_SYMBOL(__kasan_kmalloc);
>
> Sorry, but this will break all users of kmalloc() with KASAN on if
> !TRACING:

*module users.

An allmodconfig but with CONFIG_TRACING=n will probably show you the problem.

yanju...@linux.dev

unread,
Sep 29, 2021, 11:50:27 PMSep 29
to Marco Elver, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
September 29, 2021 8:45 PM, "Marco Elver" <el...@google.com> wrote:

> On Wed, 29 Sept 2021 at 14:42, Marco Elver <el...@google.com> wrote:
>
>> On Wed, Sep 29, 2021 at 07:49PM -0400, yanju...@linux.dev wrote:
>> From: Zhu Yanjun <yanju...@linux.dev>
>>
>> Since the function __kasan_kmalloc is only used in kasan module,
>> remove EXPORT_SYMBOL to this function.
>>
>> This is incorrect, see below.
>>
>> @@ -521,7 +521,6 @@ void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void
>> *object
>> {
>> return ____kasan_kmalloc(cache, object, size, flags);
>> }
>> -EXPORT_SYMBOL(__kasan_kmalloc);
>>
>> Sorry, but this will break all users of kmalloc() with KASAN on if
>> !TRACING:
>
> *module users.
>
> An allmodconfig but with CONFIG_TRACING=n will probably show you the problem.

Follow your advice, I changed CONFIG_TRACING=n in .config. Then I run "make -jxx modules".
But CONFIG_TRACING is changed to y.
So what you mentioned does not appear.

Zhu Yanjun

Marco Elver

unread,
Sep 30, 2021, 2:20:06 AMSep 30
to yanju...@linux.dev, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
On Thu, Sep 30, 2021 at 03:50AM +0000, yanju...@linux.dev wrote:

> >> -EXPORT_SYMBOL(__kasan_kmalloc);
> >>
> >> Sorry, but this will break all users of kmalloc() with KASAN on if
> >> !TRACING:
> >
> > *module users.
> >
> > An allmodconfig but with CONFIG_TRACING=n will probably show you the problem.
>
> Follow your advice, I changed CONFIG_TRACING=n in .config. Then I run "make -jxx modules".
> But CONFIG_TRACING is changed to y.
> So what you mentioned does not appear.

CONFIG_TRACING is not user selectable but auto-selected, just have to
disable all those that select it. See .config, which breaks.
.config

Zhu Yanjun

unread,
Sep 30, 2021, 2:30:10 AMSep 30
to Marco Elver, yanju...@linux.dev, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
Symbol: TRACING [=y]
x Type : bool
x Defined at kernel/trace/Kconfig:114
x Selects: RING_BUFFER [=y] && STACKTRACE [=y] && TRACEPOINTS [=y]
&& NOP_TRACER [=y] && BINARY_PRINTF [=y] && EVENT_TRACING [=y] &&
TRACE_CLOCK [=y] x
x Selected by [y]:
x - PREEMPTIRQ_TRACEPOINTS [=y] && (TRACE_PREEMPT_TOGGLE [=n] ||
TRACE_IRQFLAGS [=y])
x - GENERIC_TRACER [=y]
x - KPROBE_EVENTS [=y] && FTRACE [=y] && KPROBES [=y] &&
HAVE_REGS_AND_STACK_ACCESS_API [=y]
x - UPROBE_EVENTS [=y] && FTRACE [=y] && ARCH_SUPPORTS_UPROBES
[=y] && MMU [=y] && PERF_EVENTS [=y]
x - SYNTH_EVENTS [=y] && FTRACE [=y]
x - HIST_TRIGGERS [=y] && FTRACE [=y] &&
ARCH_HAVE_NMI_SAFE_CMPXCHG [=y]
x Selected by [n]:
x - DRM_I915_TRACE_GEM [=n] && HAS_IOMEM [=y] && DRM_I915 [=m] &&
EXPERT [=y] && DRM_I915_DEBUG_GEM [=n]
x - DRM_I915_TRACE_GTT [=n] && HAS_IOMEM [=y] && DRM_I915 [=m] &&
EXPERT [=y] && DRM_I915_DEBUG_GEM [=n]
x - ENABLE_DEFAULT_TRACERS [=n] && FTRACE [=y] && !GENERIC_TRACER [=y]

From .config, I got the above. It seems that CONFIG_TRACING is
selected by a lot of things.

Is there any method to set CONFIG_TRACING=n?

Zhu Yanjun

Zhu Yanjun

unread,
Sep 30, 2021, 7:13:39 AMSep 30
to Marco Elver, yanju...@linux.dev, ryabin...@gmail.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org
On Thu, Sep 30, 2021 at 2:20 PM Marco Elver <el...@google.com> wrote:
>
Sorry. I did not find .config in the attachment just now.
Now I made tests with this .config.

I made tests in RHEL84. The followings are steps:
1. git pull

2. make olddefconfig

3. make -j xx modules

Then the followings appear

"
WARNING: Symbol version dump "vmlinux.symvers" is missing.
Modules may not have dependencies or modversions.
You may get many unresolved symbol warnings.
MODPOST modules-only.symvers
WARNING: modpost: "__asan_register_globals"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "__asan_unregister_globals"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "unregister_pernet_subsys"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "xt_unregister_template"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "register_pernet_subsys"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "xt_register_template"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "ipt_do_table" [net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "__asan_report_store8_noabort"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "nf_nat_ipv4_register_fn"
[net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: "kmemdup" [net/ipv4/netfilter/iptable_nat.ko] undefined!
WARNING: modpost: suppressed 1754 unresolved symbol warnings because
there were too many)
"
And the .config is in the attachment.

Any other methods to make what you mentioned appear?

Zhu Yanjun
config
Reply all
Reply to author
Forward
0 new messages