-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(lib): use memfd on linux instead of dumping libddwaf.so in /tmp #106
Conversation
Signed-off-by: Eliott Bouhana <[email protected]>
c840ba3
to
5048c4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this documentation as well? Thank you!
Lines 128 to 137 in 48f7206
### CGO-less C Bindings | |
This library uses [purego](https://github.com/ebitengine/purego) to implement C bindings without requiring use of CGO at compilation time. The high-level workflow | |
is to embed the C shared library using `go:embed`, dump it into a file, open the library using `dlopen`, load the | |
symbols using `dlsym`, and finally call them. | |
> :warning: Keep in mind that **purego only works on linux/darwin for amd64/arm64 and so does go-libddwaf.** | |
Another requirement of `libddwaf` is to have a FHS filesystem on your machine and, for linux, to provide `libc.so.6`, | |
`libpthread.so.0`, and `libdl.so.2` as dynamic libraries. |
Signed-off-by: Eliott Bouhana <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have background context of errors that have been ignored.
Logging or returning an error should help support team in the future!
// The caller is responsible for calling wafDl.Close on the returned object once they | ||
// are done with it so that associated resources can be released. | ||
func NewWafDl() (dl *WafDl, err error) { | ||
file, err := lib.DumpEmbeddedWAF() | ||
path, closer, err := lib.DumpEmbeddedWAF() | ||
if err != nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not ignore this err
?
return | |
return nil, fmt.Errorf("write an embedded WAF library: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sh*t. Should have disabled auto-merge when I saw your comments. Don't worry I will do it in another PR
} | ||
}() | ||
|
||
var handle uintptr | ||
if handle, err = purego.Dlopen(file, purego.RTLD_GLOBAL|purego.RTLD_NOW); err != nil { | ||
if handle, err = purego.Dlopen(path, purego.RTLD_GLOBAL|purego.RTLD_NOW); err != nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return | |
return nil, fmt.Errorf("dlopen: %w", err) |
Context: #106 (comment) I am doing this on behave of @eliottness.
What
This PR refactors the code in
internal/lib
to accommodate two implementations of theDumpEmbeddedWAF()
function. One for linux usingmemfd
, ultimately callingdlopen("/proc/self/fd/{fd}")
, and one for darwin still creating a temporary file and callingdlopen("/tmp/libddwaf-*.so")
.Side quest: some function comments were not starting by the name of the function, fixed it.
Motivation
Being able to use dd-trace-go on full read-only filesystems. On linux only for now but still