5 ms·
I feel like I've learned something new from this, I'd never heard of this before. Would this work with Go or Rust binaries?
by djhworld 8y ago
I feel like I've learned something new from this, I'd never heard of this before.
Would this work with Go or Rust binaries?
- cyphar 8y agoLD_PRELOAD only works for binaries that are dynamically linked (LD_PRELOAD is actually handled by the link loader not the kernel[1]), and you can only use it to overwrite dynamic symbols IIRC. It definitely doesn't work with Go, and Rust might work but I'm not sure they use the glibc syscall wrappers. [1]: http://man7.org/linux/man-pages/man8/ld.so.8.html http://man7.org/linux/man-pages/man8/ld.so.8.html
- steveklabnik 8y agoRust uses glibc by default; you can use MUSL but you have to opt in.
- floatboth 8y agoNot that it matters which particular libc you use, any libc is going to have dynamic symbols named 'open', 'read' etc. that can be hooked :)
- steveklabnik 8y agoMUSL is statically linked, and so you don’t have those dynamic symbols. That’s the point!
- floatboth 8y agooh. I understand why that's the default, but it should be possible to dynamically link musl on a distro like Alpine, right?
- steveklabnik 8y agoMy understanding is that there’s some complications there, but I’m not fully aware of all the details, honestly.
- cyphar 8y agoMusl supports dynamic linking. But it also supports static linking (which glibc doesn't really support because of NSS and similarly fun features) -- hence why Rust requires musl to statically link Rust binaries.
- cyphar 8y agoI'm aware of that, I guess my point was that Rust probably doesn't use a lot of glibc (like most C programs would) so the utility of LD_PRELOAD is quite minimal. I don't know enough about .rlib to know whether you could overwrite Rust library functions, but that's a different topic.
- steveklabnik 8y agoRust uses glibc to call into the kernel like anything else. The standard library is built on top of it.
- cyphar 8y agoRight, but does that mean it's only used as a way of getting syscall numbers (without embedding it like Go does) or is it the case that you could actually LD_PRELOAD random things like nftw(3) and it would actually affect Rust programs? I'll be honest, I haven't tried it, but it was my impression that Rust only used glibc for syscall wrappers?
- steveklabnik 8y agoWe don’t provide nftw like functionality in std, and so you can’t replace it as it would have never even been called. But for example, malloc and free are used, not sbrk directly: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/alloc.rs https://github.com/rust-lang/rust/blob/master/src/libstd/sys...