Open nwf opened 3 years ago
I haven't run the libunwind tests on RISC-V for a while. It's possible that they are currently broken.
Ah nevermind, I see the crash is inside libelf trying to read the symbol table. I wouldn't be surprised if libelf has lots of memory safety issues.
Time has marched on but sadly this bug is still here. On the latest efforts to CHERIfy snmalloc
on RISC-V, it now presents itself as
Program received signal SIGPROT, CHERI protection violation
Capability sealed fault caused by register ca1.
0x0000000040174e38 in symtab_find (st=0x40a67030 [rwRW,0x40a67030-0x40a67060], p=0x11c0aa <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()+92> [rxR,0x100000-0x13dd00] (sentry), dli=0x3fffdfb1a0 [rwRW,0x3fffdfb1a0-0x3fffdfb1e0]) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/symtab.c:188
188 /cheri/source/mainline/cheribsd/contrib/libexecinfo/symtab.c: No such file or directory.
(gdb) bt
#0 0x0000000040174e38 in symtab_find (st=0x40a67030 [rwRW,0x40a67030-0x40a67060], p=0x11c0aa <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()+92> [rxR,0x100000-0x13dd00] (sentry), dli=0x3fffdfb1a0 [rwRW,0x3fffdfb1a0-0x3fffdfb1e0]) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/symtab.c:188
#1 0x00000000401745ba in format_address (st=0x40a67030 [rwRW,0x40a67030-0x40a67060], buf=0x3fffdfad80 [,0xfdec000000000000-0xffffffffffffffff], bufsiz=0x3fffdfad78 [,0xfdec000000000000-0xffffffffffffffff], offs=80, fmt=0x40172e20 [rR,0x40172e20-0x40172e30] "%a <%n%D> at %f",
addr=0x11c0aa <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()+92> [rxR,0x100000-0x13dd00] (sentry)) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/backtrace.c:175
#2 backtrace_symbols_fmt (trace=<optimized out>, len=5, fmt=<optimized out>) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/backtrace.c:211
#3 0x00000000401748c0 in backtrace_symbols_fd_fmt (len=<optimized out>, fd=<optimized out>, fmt=0x3fffdfb1a0 [rwRW,0x3fffdfb1a0-0x3fffdfb1e0] " \377\337\277?", trace=<optimized out>) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/backtrace.c:238
#4 backtrace_symbols_fd (trace=<optimized out>, len=<optimized out>, fd=<optimized out>) at /cheri/source/mainline/cheribsd/contrib/libexecinfo/backtrace.c:259
#5 0x000000000011c0e0 in snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace () at /cheri/source/mainline/snmalloc2/src/ds/../pal/pal_posix.h:154
#6 0x000000000011c046 in snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::error (str=0x3fffdff4e0 [rwRW,0x3fffdff4e0-0x3fffdff8e0] "memcpy with destination out of bounds of heap allocation: 0x40e04080 is in allocation 0x40e04080--0x40e040a0, offset 0x21 is past the end.\n")
at /cheri/source/mainline/snmalloc2/src/ds/../pal/pal_posix.h:166
#7 0x000000000011bb28 in (anonymous namespace)::crashWithMessage (p=0x40e04080 [rwRW,0x40e04080-0x40e040a0], len=33, msg=0x10d1de [rR,0x10d1de-0x10d217] "memcpy with destination out of bounds of heap allocation", alloc=...) at /cheri/source/mainline/snmalloc2/src/override/memcpy.cc:120
#8 0x000000000011a938 in (anonymous namespace)::check_bounds<false> (ptr=0x40e04080 [rwRW,0x40e04080-0x40e040a0], len=33, msg=0x10d1de [rR,0x10d1de-0x10d217] "memcpy with destination out of bounds of heap allocation") at /cheri/source/mainline/snmalloc2/src/override/memcpy.cc:151
#9 my_memcpy (dst=0x40e04080 [rwRW,0x40e04080-0x40e040a0], src=0x40e04060 [rwRW,0x40e04060-0x40e04080], len=33) at /cheri/source/mainline/snmalloc2/src/override/memcpy.cc:218
#10 0x000000000011b1d0 in check_bounds (size=32, out_of_bounds=1) at /cheri/source/mainline/snmalloc2/src/test/func/memcpy/func-memcpy.cc:121
#11 0x000000000011b370 in main () at /cheri/source/mainline/snmalloc2/src/test/func/memcpy/func-memcpy.cc:150
(gdb) i r
ra 0x401745ba 1075267002
sp 0x3fffdfacf0 274875788528
gp 0x0 0
tp 0x40a10050 1084293200
t0 0xfff2 65522
t1 0x4017501c 1075269660
t2 0x40acc000 1085063168
fp 0x0 0
s1 0x3fffdfad78 274875788664
a0 0x40a67030 1084649520
a1 0x11c0aa 1163434
a2 0x3fffdfb1a0 274875789728
a3 0x184 388
a4 0x0 0
a5 0x11c04e 1163342
a6 0x100000 1048576
a7 0x1c0aa 114858
s2 0x63 99
s3 0xffffffffffffffff -1
s4 0x40172e20 1075260960
s5 0x0 0
s6 0x50 80
s7 0x3fffdfb1a0 274875789728
s8 0x11c0aa 1163434
s9 0x3fffdfad80 274875788672
s10 0x40a67030 1084649520
s11 0x25 37
t3 0x40174e14 1075269140
t4 0xa 10
t5 0x1000 4096
t6 0x1 1
pc 0x40174e38 1075269176
cnull 0x0 0x0
cra 0xf11720000801880600000000401745ba 0x401745ba <backtrace_symbols_fmt+378> [rxR,0x40172000-0x40178000] (sentry)
csp 0xd17d000003ff2ffe0000003fffdfacf0 0x3fffdfacf0 [rwRW,0x3fbfe00000-0x3fffe00000]
cgp 0x0 0x0
ctp 0xd17d0000015d800e0000000040a10050 0x40a10050 [rwRW,0x40a10020-0x40a155c0]
ct0 0xfff2 0xfff2
ct1 0xf117200008018806000000004017501c 0x4017501c [rxR,0x40172000-0x40178000] (sentry)
ct2 0xd17d0000030599830000000040acc000 0x40acc000 [rwRW,0x40acc000-0x40b60800]
cfp 0x0 0x0
cs1 0xd17d00000761ad7c0000003fffdfad78 0x3fffdfad78 [rwRW,0x3fffdfad78-0x3fffdfad80]
ca0 0xd17d00000419b0340000000040a67030 0x40a67030 [rwRW,0x40a67030-0x40a67060]
ca1 0xd11720000bbb8001000000000011c0aa 0x11c0aa <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()+92> [rxR,0x100000-0x13dd00] (sentry)
ca2 0xd17d00000479b1a40000003fffdfb1a0 0x3fffdfb1a0 [rwRW,0x3fffdfb1a0-0x3fffdfb1e0]
ca3 0x184 0x184
ca4 0x0 0x0
ca5 0x3bb8001000000000011c04e 0x11c04e <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()> [,0x100000-0x13dd00]
ca6 0x3bb80010000000000100000 0x100000 [,0x100000-0x13dd00]
ca7 0x1c0aa 0x1c0aa
cs2 0x63 0x63
cs3 0xffffffffffffffff 0xffffffffffffffff
cs4 0xf1152000078dae240000000040172e20 0x40172e20 [rR,0x40172e20-0x40172e30]
cs5 0x0 0x0
cs6 0x50 0x50
cs7 0xd17d00000479b1a40000003fffdfb1a0 0x3fffdfb1a0 [rwRW,0x3fffdfb1a0-0x3fffdfb1e0]
cs8 0xd11720000bbb8001000000000011c0aa 0x11c0aa <snmalloc::PALPOSIX<snmalloc::PALFreeBSD>::print_stack_trace()+92> [rxR,0x100000-0x13dd00] (sentry)
cs9 0xd17d00000765ad840000003fffdfad80 0x3fffdfad80 [rwRW,0x3fffdfad80-0x3fffdfad90]
cs10 0xd17d00000419b0340000000040a67030 0x40a67030 [rwRW,0x40a67030-0x40a67060]
cs11 0x25 0x25
ct3 0xf1172000080188060000000040174e14 0x40174e14 <symtab_find> [rxR,0x40172000-0x40178000] (sentry)
ct4 0xa 0xa
ct5 0x1000 0x1000
ct6 0x1 0x1
pcc 0xf1172000000188060000000040174e38 0x40174e38 <symtab_find+36> [rxR,0x40172000-0x40178000]
ddc 0x0 0x0
cap_valid 0xb3bc90eb 3015479531
(gdb) x/i $pcc
=> 0x40174e38 <symtab_find+36>: csetaddr ct3,ca1,a7
which is to say that uintptr_t me = (uintptr_t)p - fbase
does not go well when p
is a sentry. I suspect that all of fbase
, dd
, sd
, me
, and ad
should be ptraddr_t
rather than uintptr_t
, since it looks like that routine is just doing math and not actually anything with pointers/capabilities.
Ah yeah, this is a repeat of a similar thing I saw in LLVM's stack trace implementation
I am to the point that snmalloc compiles on CHERI again but am doing something wrong in startup. On its way out, it tries to generate a stack trace by calling backtrace_symbols_fd and that, in turn, dies a CHERI death:
ETA: Forgot to say, this is on 68bb19024845