This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Add the settings of Read and Write flags in SignalContext for LoongArch
ClosedPublic

Authored by tangyouling on Nov 2 2022, 1:10 AM.

Details

Summary

The bit-30 in this __flags means the address error is due to memory load, and the
bit-31 means the address error is due to memory store. (see SC_ADDRERR_RD
and SC_ADDRERR_WR in kernel arch/loongarch/include/uapi/asm/sigcontext.h).

illegal_write_test.cpp and illegal_read_test.cpp have been tested and passed.

Diff Detail

Event Timeline

tangyouling created this revision.Nov 2 2022, 1:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 1:10 AM
tangyouling requested review of this revision.Nov 2 2022, 1:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 1:10 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
tangyouling edited the summary of this revision. (Show Details)Nov 2 2022, 1:12 AM
tangyouling added a reviewer: Restricted Project.

The signal is caused by a READ memory access,

$ ./test/sanitizer_common/asan-loongarch64-Linux/Posix/Output/illegal_read_test.cpp.tmp
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3114306==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x555558803104 bp 0x7ffffbd391a0 sp 0x7ffffbd39160 T0)
==3114306==The signal is caused by a READ memory access.
==3114306==Hint: address points to the zero page.
    #0 0x555558803104 in main /home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_read_test.cpp:13:7
    #1 0x7ffff1a09678  (/usr/lib64/libc.so.6+0x25678)
    #2 0x7ffff1a09764 in __libc_start_main (/usr/lib64/libc.so.6+0x25764)
    #3 0x55555871eac4  (/home/loongson/llvm-work/llvm-project-test2/llvm-project/build_crt/test/sanitizer_common/asan-loongarch64-Linux/Posix/Output/illegal_read_test.cpp.tmp+0x26ac4)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_read_test.cpp:13:7 in main
==3114306==ABORTING

The signal is caused by a WRITE memory access,

$ ./test/sanitizer_common/asan-loongarch64-Linux/Posix/Output/illegal_write_test.cpp.tmp 
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3114308==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5555579c70c8 bp 0x7ffffba24c50 sp 0x7ffffba24c10 T0)
==3114308==The signal is caused by a WRITE memory access.
==3114308==Hint: address points to the zero page.
    #0 0x5555579c70c8 in main /home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_write_test.cpp:12:9
    #1 0x7ffff07b9678  (/usr/lib64/libc.so.6+0x25678)
    #2 0x7ffff07b9764 in __libc_start_main (/usr/lib64/libc.so.6+0x25764)
    #3 0x5555578e2a84  (/home/loongson/llvm-work/llvm-project-test2/llvm-project/build_crt/test/sanitizer_common/asan-loongarch64-Linux/Posix/Output/illegal_write_test.cpp.tmp+0x26a84)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_write_test.cpp:12:9 in main
==3114308==ABORTING
SixWeining accepted this revision.Nov 2 2022, 2:23 AM

LGTM but wait for others.

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
1963
This revision is now accepted and ready to land.Nov 2 2022, 2:23 AM

Don’t use else after a return.

xen0n added inline comments.Nov 2 2022, 8:14 PM
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
1961

Define static const u32 SC_ADDRERR_RD and similarly SC_ADDRERR_WR to avoid magic numbers, as the other arches did.

tangyouling marked an inline comment as done.Nov 2 2022, 8:24 PM
tangyouling added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
1961

Define static const u32 SC_ADDRERR_RD and similarly SC_ADDRERR_WR to avoid magic numbers, as the other arches did.

I will use the definition in /usr/include/asm/sigcontext.h directly, if redefined will conflict.

/home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1959:20: error: expected ')'
/usr/include/asm/sigcontext.h:17:25: note: expanded from macro 'SC_ADDRERR_RD'
#define SC_ADDRERR_RD           (1 << 30)
                                 ^
/home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1959:20: note: to match this '('
/usr/include/asm/sigcontext.h:17:24: note: expanded from macro 'SC_ADDRERR_RD'
#define SC_ADDRERR_RD           (1 << 30)
                                ^
/home/loongson/llvm-work/llvm-project-test2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1960:20: error: expected unqualified-id
  static const u32 SC_ADDRERR_WR = 1U << 31;
                   ^
/usr/include/asm/sigcontext.h:19:25: note: expanded from macro 'SC_ADDRERR_WR'
#define SC_ADDRERR_WR           (1 << 31)

Use the SC_ADDRERR_RD and SC_ADDRERR_WR macros in /usr/include/asm/sigcontext.h directly.

xen0n added inline comments.Nov 2 2022, 8:35 PM
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
1963

Missing space after if.

Add the missing space after if.

What is the kernel version that support this flags? Maybe give a link on Github?

xry111 added a comment.Nov 2 2022, 9:12 PM

What is the kernel version that support this flags? Maybe give a link on Github?

These flags are there since the day one LoongArch support was added into the kernel:
https://git.kernel.org/torvalds/c/c6f2f3e2c80e

What is the kernel version that support this flags? Maybe give a link on Github?

Upstream kernel supports from the beginning,
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/?id=b74baf4ad05b5ebe3152592fb2fa80d51681392a

xen0n accepted this revision.Nov 2 2022, 10:30 PM

Should be good LoongArch-wise.

XiaodongLoong accepted this revision.Nov 2 2022, 11:01 PM
This revision was landed with ongoing or failed builds.Nov 9 2022, 9:35 PM
This revision was automatically updated to reflect the committed changes.