How do I use fopen() and freopen() within DynamoRIO client?

37 views
Skip to first unread message

Alexey Popov

unread,
Feb 2, 2024, 12:53:26 PMFeb 2
to DynamoRIO Users
I'm new to DynamoRIO and just tinkering with sample clients for now. I noticed that fopen() and freopen() always crash my clients. I've modified empty.c example, adding line 
fopen ("any.file", "w");
and got this message:

<Application /usr/bin/ls (4112).  DynamoRIO Sample Client 'empty' internal crash at PC 0x00007f5c26b591d3.  Please report this at http://dynamorio.org/issues.  Program aborted.
Received SIGSEGV at pc 0x00007f5c26b591d3 in thread 4112
Base: 0x00007f5c26f70000
Registers:eax=0x0000000000000000 ebx=0x00007f59e300e350 ecx=0x0000000000000000 edx=0x00000000fbad248c
esi=0x00000000fbad0000 edi=0x00007fff62c3e250 esp=0x00007fff62c3e248 ebp=0x0000000000000000
r8 =0x00007f5c26cdf0c0 r9 =0x0000000000000020 r10=0x00007f5c2715c000 r11=0x0000000000000246
r12=0x00007fff62c3e250 r13=0x00007f5c26ce4a50 r14=0x0000000000000000 r15=0x0000000000000001
eflags=0x0000000000010246
version 10.0.19741, custom build
-no_dynamic_options -client_lib '/home/alexei/ispras/DynamoRIO-Linux-10.0.19741/test_build/bin/libempty.so;0;' -client_lib64 '/home/alexei/ispras/DynamoRIO-Linux-10.0.19741/test_build/bin/libempty.so;0;' -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inl
0x00007f59e2fc1080 0x0000000000000000>

Other libc functions seem to work fine. For build, default CMake was used:

DYNAMORIO_DIR='DynamoRIO-Linux-10.0.19741'
CLIENT=$DYNAMORIO_DIR'/test_build/bin/libempty.so'
TARGET_CALL='ls'

mkdir $DYNAMORIO_DIR/test_build
cd $DYNAMORIO_DIR/test_build
cmake -DDynamoRIO_DIR=../cmake ../samples
make

Maybe I'm missing something? Please help with it.

Derek Bruening

unread,
Feb 5, 2024, 3:25:42 PMFeb 5
to Alexey Popov, DynamoRIO Users
I can't reproduce this problem: the fopen works fine in a client on my system.  Probably this is specific to the glibc version.  I tested on 2.37 where it worked.  Recent versions of glibc have made it much harder for DR to provide an isolated, private copy of libraries for clients to use.  See some discussion at https://github.com/DynamoRIO/dynamorio/issues/5437#issuecomment-1083108099.  Unfortunately, it is likely to come down to some undocumented initialization of libc done by ld.so, and making it work with a simple fix probably requires a fragile emulation of that initialization; longer-term possible solutions are discussed in the aforementioned issue.  This is speculation: you would have to delve into the crash in a debugger and track down the cause to know for sure.  I would suggest at least looking at a symbolized callstack of the crash to get a basic understanding of what is going on, and trying with different glibc to see where it happens.

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/6c87921e-4a04-4c34-82c5-973281374edfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages