* Re: [PATCH] kasan: avoid out-of-bounds in unwind_frame
[not found] <1539079863-19645-1-git-send-email-chunhui.li@mediatek.com>
@ 2018-10-09 10:38 ` Mark Rutland
2018-10-10 6:45 ` 答复: " Chunhui Li (李春辉)
0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2018-10-09 10:38 UTC (permalink / raw)
To: Chunhui Li
Cc: Catalin Marinas, Will Deacon, Matthias Brugger, Marc Zyngier,
Ard Biesheuvel, James Morse, Masahiro Yamada, linux-arm-kernel,
linux-kernel, linux-mediatek, wsd_upstream
On Tue, Oct 09, 2018 at 06:11:03PM +0800, Chunhui Li wrote:
> From: "chunhui.li" <chunhui.li@mediatek.com>
>
> kasan detect unwind_frame out-of-bounds error when one task
> dump another, log as below
> BUG: KASAN: out-of-bounds in unwind_frame+0x140/0x20c Read of
> size 8 at addr ffffffea1e2378e0 by task AnrMonitorThrea/1111
> avoid kasan out-of-bounds error by disable kasan for stacktrace.c
This doesn't look right. Since unwind_frame uses READ_ONCE_NOCHECK(),
we should never perform an access that KASAN complains about.
I don't think that we should completely disable instrumentation of
stacktrace.c.
Can you please figure out precisely which line KASAN is complaining
about? i.e. use scripts/faddr2line.
Thanks,
Mark.
>
> Signed-off-by: chunhui.li <chunhui.li@mediatek.com>
> ---
> arch/arm64/kernel/Makefile | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> index 95ac737..606d0e2 100644
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -57,6 +57,8 @@ arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
> arm64-obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o
> arm64-obj-$(CONFIG_ARM64_SSBD) += ssbd.o
>
> +KASAN_SANITIZE_stacktrace.o := n
> +
> obj-y += $(arm64-obj-y) vdso/ probes/
> obj-m += $(arm64-obj-m)
> head-y := head.o
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* 答复: [PATCH] kasan: avoid out-of-bounds in unwind_frame
2018-10-09 10:38 ` [PATCH] kasan: avoid out-of-bounds in unwind_frame Mark Rutland
@ 2018-10-10 6:45 ` Chunhui Li (李春辉)
2018-10-10 9:26 ` Mark Rutland
0 siblings, 1 reply; 4+ messages in thread
From: Chunhui Li (李春辉) @ 2018-10-10 6:45 UTC (permalink / raw)
To: Mark Rutland
Cc: Catalin Marinas, Will Deacon, Matthias Brugger, Marc Zyngier,
Ard Biesheuvel, James Morse, Masahiro Yamada, linux-arm-kernel,
linux-kernel, linux-mediatek, wsd_upstream,
Miles Chen (��民��),
Walter-ZH Wu (�亲驽�),
Yu Liang (梁宇),
Nicholas Tang (��秦�x)
Hi Mark,
kasan detect out-of-bounds in stacktrace.c line 70, it's already over READ_ONCE_NOCHECK, but still crash
kernel-4.9/arch/arm64/kernel/stacktrace.c
69 frame->sp = fp + 0x10;
70 frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
we test on Android platform, kernel-4.9 build with clang 6.0.2, we will do experiment to clarify whether compiler related issue.
READ_ONCE_NOCHECK->__read_once_size_nocheck with __no_sanitize_address if enable CONFIG_KASAN
kernel-4.9/include/linux/compiler-gcc.h
#define __no_sanitize_address __attribute__((no_sanitize_address))
kernel-4.9/include/linux/compiler-clang.h
#define __no_sanitize_address __attribute__((no_sanitize("address")))
there is patch from internet, avoid kasan by wrapping with kasan_disable_current, it seems better.
https://lore.kernel.org/patchwork/patch/644463
such as:
+ kasan_disable_current();
// access fp
+ kasan_enable_current();
Thanks
Chunhui Li
-----邮件原件-----
发件人: Mark Rutland [mailto:mark.rutland@arm.com]
发送时间: 2018年10月9日 18:39
收件人: Chunhui Li (李春辉)
抄送: Catalin Marinas; Will Deacon; Matthias Brugger; Marc Zyngier; Ard Biesheuvel; James Morse; Masahiro Yamada; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; linux-mediatek@lists.infradead.org; wsd_upstream
主题: Re: [PATCH] kasan: avoid out-of-bounds in unwind_frame
On Tue, Oct 09, 2018 at 06:11:03PM +0800, Chunhui Li wrote:
> From: "chunhui.li" <chunhui.li@mediatek.com>
>
> kasan detect unwind_frame out-of-bounds error when one task dump
> another, log as below
> BUG: KASAN: out-of-bounds in unwind_frame+0x140/0x20c Read of size 8
> at addr ffffffea1e2378e0 by task AnrMonitorThrea/1111 avoid kasan
> out-of-bounds error by disable kasan for stacktrace.c
This doesn't look right. Since unwind_frame uses READ_ONCE_NOCHECK(), we should never perform an access that KASAN complains about.
I don't think that we should completely disable instrumentation of stacktrace.c.
Can you please figure out precisely which line KASAN is complaining about? i.e. use scripts/faddr2line.
Thanks,
Mark.
>
> Signed-off-by: chunhui.li <chunhui.li@mediatek.com>
> ---
> arch/arm64/kernel/Makefile | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> index 95ac737..606d0e2 100644
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -57,6 +57,8 @@ arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
> arm64-obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o
> arm64-obj-$(CONFIG_ARM64_SSBD) += ssbd.o
>
> +KASAN_SANITIZE_stacktrace.o := n
> +
> obj-y += $(arm64-obj-y) vdso/ probes/
> obj-m += $(arm64-obj-m)
> head-y := head.o
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 答复: [PATCH] kasan: avoid out-of-bounds in unwind_frame
2018-10-10 6:45 ` 答复: " Chunhui Li (李春辉)
@ 2018-10-10 9:26 ` Mark Rutland
2018-10-10 11:20 ` 答复: " Chunhui Li (李春辉)
0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2018-10-10 9:26 UTC (permalink / raw)
To: Chunhui Li (李春辉)
Cc: Catalin Marinas, Will Deacon, Matthias Brugger, Marc Zyngier,
Ard Biesheuvel, James Morse, Masahiro Yamada, linux-arm-kernel,
linux-kernel, linux-mediatek, wsd_upstream,
Miles Chen (陳民樺),
Walter-ZH Wu (吳祖寰),
Yu Liang (梁宇),
Nicholas Tang (鄭秦輝)
On Wed, Oct 10, 2018 at 06:45:17AM +0000, Chunhui Li (李春辉) wrote:
> Hi Mark,
>
> kasan detect out-of-bounds in stacktrace.c line 70, it's already over READ_ONCE_NOCHECK, but still crash
> kernel-4.9/arch/arm64/kernel/stacktrace.c
> 69frame->sp = fp + 0x10;
> 70frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
>
> we test on Android platform, kernel-4.9 build with clang 6.0.2, we will do experiment to clarify whether compiler related issue.
>
> READ_ONCE_NOCHECK->__read_once_size_nocheck with __no_sanitize_address if enable CONFIG_KASAN
>
> kernel-4.9/include/linux/compiler-gcc.h
> #define __no_sanitize_address __attribute__((no_sanitize_address))
>
> kernel-4.9/include/linux/compiler-clang.h
> #define __no_sanitize_address __attribute__((no_sanitize("address")))
If READ_ONCE_NOCHECK() isn't working as intended, then this is a
compiler issue, and there are bigger problems regardless.
If we need to workaround some compiler issue, that should be done in the
implementation of READ_ONCE_NOCHECK().
Please note that there are other issues with using clang to compile the
kernel; at minimum 7.0.0 is required to build a mainline kernel (and
even then, the LSE atomics have to be explicitly disabled), so if this
only affects 6.0.x, I don't think we need to carry any workaround
upstream.
> there is patch from internet, avoid kasan by wrapping with kasan_disable_current, it seems better.
> https://lore.kernel.org/patchwork/patch/644463
> such as:
> +kasan_disable_current();
> // access fp
> +kasan_enable_current();
Please note that the solution later in the thread [1] was to use
READ_ONCE_NOCHECK().
Thanks,
Mark.
[1] https://lore.kernel.org/patchwork/patch/644463/#829858
^ permalink raw reply [flat|nested] 4+ messages in thread
* 答复: 答复: [PATCH] kasan: avoid out-of-bounds in unwind_frame
2018-10-10 9:26 ` Mark Rutland
@ 2018-10-10 11:20 ` Chunhui Li (李春辉)
0 siblings, 0 replies; 4+ messages in thread
From: Chunhui Li (李春辉) @ 2018-10-10 11:20 UTC (permalink / raw)
To: Mark Rutland
Cc: Catalin Marinas, Will Deacon, Matthias Brugger, Marc Zyngier,
Ard Biesheuvel, James Morse, Masahiro Yamada, linux-arm-kernel,
linux-kernel, linux-mediatek, wsd_upstream,
Miles Chen (陳民樺),
Walter-ZH Wu (吳祖寰),
Yu Liang (梁宇),
Nicholas Tang (鄭秦輝)
Hi Mark,
Ok, thanks for your help
Best regards,
Chunhui Li
-----邮件原件-----
发件人: Mark Rutland [mailto:mark.rutland@arm.com]
发送时间: 2018年10月10日 17:26
收件人: Chunhui Li (李春辉)
抄送: Catalin Marinas; Will Deacon; Matthias Brugger; Marc Zyngier; Ard Biesheuvel; James Morse; Masahiro Yamada; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; linux-mediatek@lists.infradead.org; wsd_upstream; Miles Chen (陳民樺); Walter-ZH Wu (吳祖寰); Yu Liang (梁宇); Nicholas Tang (鄭秦輝)
主题: Re: 答复: [PATCH] kasan: avoid out-of-bounds in unwind_frame
On Wed, Oct 10, 2018 at 06:45:17AM +0000, Chunhui Li (李春辉) wrote:
> Hi Mark,
>
> kasan detect out-of-bounds in stacktrace.c line 70, it's already over
> READ_ONCE_NOCHECK, but still crash
> kernel-4.9/arch/arm64/kernel/stacktrace.c
> 69frame->sp = fp + 0x10;
> 70frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
>
> we test on Android platform, kernel-4.9 build with clang 6.0.2, we will do experiment to clarify whether compiler related issue.
>
> READ_ONCE_NOCHECK->__read_once_size_nocheck with __no_sanitize_address
> if enable CONFIG_KASAN
>
> kernel-4.9/include/linux/compiler-gcc.h
> #define __no_sanitize_address __attribute__((no_sanitize_address))
>
> kernel-4.9/include/linux/compiler-clang.h
> #define __no_sanitize_address __attribute__((no_sanitize("address")))
If READ_ONCE_NOCHECK() isn't working as intended, then this is a compiler issue, and there are bigger problems regardless.
If we need to workaround some compiler issue, that should be done in the implementation of READ_ONCE_NOCHECK().
Please note that there are other issues with using clang to compile the kernel; at minimum 7.0.0 is required to build a mainline kernel (and even then, the LSE atomics have to be explicitly disabled), so if this only affects 6.0.x, I don't think we need to carry any workaround upstream.
> there is patch from internet, avoid kasan by wrapping with kasan_disable_current, it seems better.
> https://lore.kernel.org/patchwork/patch/644463
> such as:
> +kasan_disable_current();
> // access fp
> +kasan_enable_current();
Please note that the solution later in the thread [1] was to use READ_ONCE_NOCHECK().
Thanks,
Mark.
[1] https://lore.kernel.org/patchwork/patch/644463/#829858
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-10 11:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1539079863-19645-1-git-send-email-chunhui.li@mediatek.com>
2018-10-09 10:38 ` [PATCH] kasan: avoid out-of-bounds in unwind_frame Mark Rutland
2018-10-10 6:45 ` 答复: " Chunhui Li (李春辉)
2018-10-10 9:26 ` Mark Rutland
2018-10-10 11:20 ` 答复: " Chunhui Li (李春辉)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).