-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First take #1
base: main
Are you sure you want to change the base?
First take #1
Conversation
I think the solution to the crash would be to lock all threads, as Go creates threads and routines seamlessly under the screen, and this is implemented in purego it might have other threads/routines running at the same time, while we load and do the hooks :) |
https://dave.cheney.net/2014/09/28/using-build-to-switch-between-debug-and-release |
I don't think so, I tried to implement the same logic in a simple C program. It fails the same way when compiled statically :( #include <dlfcn.h>
#include <stdio.h>
int main() {
dlerror();
char * error = NULL;
void * handle = dlopen("./libmirrord_layer.so", RTLD_NOW | RTLD_GLOBAL);
error = dlerror();
if (error) {
fprintf(stderr, "ERROR %s:%d: %s\n", __FILE__, __LINE__, error);
return 1;
}
void (*exit)(int) = (void (*)(int)) dlsym(handle, "exit");
error = dlerror();
if (error) {
fprintf(stderr, "ERROR %s:%d: %s\n", __FILE__, __LINE__, error);
return 1;
}
exit(0);
return 1;
} |
Loved the test :) |
A segfault when layer initialization tries to access thread local storage. Do you mean linking the layer statically? Wouldn't this end badly when the user binary itself links to libc dynamically? We would have two versions of libc working in the same address space. |
https://github.com/pfalcon/foreign-dlopen maybe we can use this code to solve the problem? |
The flow there is a bit complex, requiring to compile some helper binary against the target system. I'm not sure yet how to fit it into a golang package. There's also one thing about this project that concerns me: And: $ ldd foreign_dlopen_demo
linux-vdso.so.1 (0x00007ffc7c6f5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc6f1400000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc6f171d000) |
tbh I thought integrating into our source code :) but let's hold this for now. |
This does not work when forcing the Go binary to be statically linked (build command is
go build -ldflags "-linkmode 'external' -extldflags '-static'"
). An attempt to load the layer this way crashes the program at runtime. However, this happens only when injecting the mirrord layer. I tested this with other shared libraries (libc
andlibcurl
) and all worked fine. So there might be some issue with the layer itself.When layer path is provided in
LD_PRELOAD
, the program crashes at runtime with this stacktrace: