https://github.com/vadimkantorov/libarchivepreload
Demo of abusing libarchive to make LD_PRELOAD-based overrides of file-related functions
https://github.com/vadimkantorov/libarchivepreload
ld-preload libarchive virtual-file-system zip
Last synced: 4 months ago
JSON representation
Demo of abusing libarchive to make LD_PRELOAD-based overrides of file-related functions
- Host: GitHub
- URL: https://github.com/vadimkantorov/libarchivepreload
- Owner: vadimkantorov
- Created: 2024-09-06T15:10:24.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-10-17T15:05:38.000Z (7 months ago)
- Last Synced: 2024-11-13T10:48:12.926Z (6 months ago)
- Topics: ld-preload, libarchive, virtual-file-system, zip
- Language: C
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# libarchivepreload
Demo of abusing https://github.com/libarchive/libarchive to make `LD_PRELOAD`-based overrides of file-related functions. The `LD_PRELOAD`-based approach is useful when one doesn't have FUSE kernel module installed or does not have root permissions do use https://github.com/google/fuse-archive/ and it's wasteful to decompress a given archive.**Limitations:** This demo does not optimize for iterative entry reads or iterative seeks, https://github.com/google/fuse-archive/ makes an attempt in that direction; also see https://github.com/libarchive/libarchive/issues/2306 for future support of fast seeks in ZIP / TAR / CPIO in libarchive
```shell
cc -shared -fPIC libarchivepreload.c -o libarchivepreload.so -ldl libarchive/.libs/libarchive.a zlib/libz.a -Ilibarchive -Ilibarchive/libarchivezip -r libarchivepreload.zip libarchivepreload.c .git
LD_PRELOAD=$PWD/libarchivepreload.so /usr/bin/ls -lah libarchivepreload.zip/
LD_PRELOAD=$PWD/libarchivepreload.so /usr/bin/ls -lah libarchivepreload.zip
LD_PRELOAD=$PWD/libarchivepreload.so /usr/bin/ls -lah libarchivepreload.zip/libarchivepreload.c
LD_PRELOAD=$PWD/libarchivepreload.so /usr/bin/cat libarchivepreload.zip/libarchivepreload.c
LD_PRELOAD=$PWD/libarchivepreload.so /usr/bin/find libarchivepreload.zip
```# Overridden libc / posix functions
- [`open`](https://man7.org/linux/man-pages/man2/open.2.html)
- [`openat`](https://man7.org/linux/man-pages/man2/openat.2.html)
- [`close`](https://man7.org/linux/man-pages/man2/close.2.html)
- [`read`](https://man7.org/linux/man-pages/man2/read.2.html)
- [`access`](https://man7.org/linux/man-pages/man2/access.2.html)
- [`lseek`](https://man7.org/linux/man-pages/man2/lseek.2.html)
- [`stat`](https://man7.org/linux/man-pages/man2/stat.2.html)
- [`fstat`](https://man7.org/linux/man-pages/man2/fstat.2.html)
- [`fstatat`](https://man7.org/linux/man-pages/man2/fstatat.2.html)
- [`statx`](https://man7.org/linux/man-pages/man2/statx.2.html)
- [`fopen`](https://en.cppreference.com/w/c/io/fopen)
- [`fclose`](https://en.cppreference.com/w/c/io/fclose)
- [`fileno`](https://man7.org/linux/man-pages/man3/fileno.3.html)
- [`fcntl`](https://man7.org/linux/man-pages/man2/fcntl.2.html) - only `F_DUPFD` and `F_DUPFD_CLOEXEC` is emulated
- [`opendir`](https://man7.org/linux/man-pages/man3/opendir.3.html)
- [`fdopendir`](https://man7.org/linux/man-pages/man3/fdopendir.3p.html)
- [`readdir`](https://man7.org/linux/man-pages/man3/readdir.3.html)
- [`closedir`](https://man7.org/linux/man-pages/man3/closedir.3.html)# References
- https://mropert.github.io/2018/02/02/pic_pie_sanitizers/
- https://github.com/google/fuse-archive/
- https://gist.github.com/vadimkantorov/2a4e092889b7132acd3b7ddfc2f2f907
- https://github.com/libarchive/libarchive/issues/2306
- https://github.com/coreutils/coreutils/blob/master/src/ls.c
- https://github.com/coreutils/coreutils/blob/master/src/cat.c
- https://git.busybox.net/busybox/tree/coreutils/ls.c
- https://git.busybox.net/busybox/tree/coreutils/cat.c
- https://git.musl-libc.org/cgit/musl/tree/src/dirent/opendir.c
- https://git.musl-libc.org/cgit/musl/tree/src/dirent/readdir.c- https://stackoverflow.com/questions/77100299/implementing-a-simple-version-of-readdir-with-system-call
- https://stackoverflow.com/questions/74890409/what-happens-in-c-function-readdir-from-dirent-h
- https://stackoverflow.com/questions/24103009/is-it-possible-to-implement-readdir-in-ubuntu-12-10-kernel-3-5
- https://unix.stackexchange.com/questions/625899/correctly-implementing-seeking-in-fuse-readdir-operation
- https://github.com/facebook/sapling/blob/5cc682e8ff24ef182be2dbe07e484396539e80f4/eden/fs/inodes/TreeInode.cpp#L1798-L1833
- https://github.com/facebook/sapling/blob/main/eden/fs/docs/InodeLifetime.md
- https://lwn.net/Articles/544520/
- https://lwn.net/Articles/544298/
- https://github.com/TheAssassin/AppImageLauncher/issues/361
- https://github.com/sholtrop/ldpfuse/
- https://github.com/google/fuse-archive/blob/main/src/main.cc
- https://superuser.com/questions/1601311/fuse-fs-without-root-privileges-e-g-a-ld-preload-gateway-or-a-proot-plugin
- https://theses.liacs.nl/pdf/2021-2022-HoltropS.pdf
- https://github.com/fritzw/ld-preload-open
- https://github.com/strace/strace/blob/8399328f628182cf236a1c39a074d601babdeaa4/src/fcntl.c#L102
- https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/fcntl.c;h=7cd3a0f976d9f9c9fbb1b5cab5b57780a72cec58;hb=HEAD
- https://savannah.gnu.org/bugs/?48169
- https://github.com/coreutils/gnulib/blob/master/lib/fcntl.c
- https://github.com/coreutils/gnulib/blob/master/lib/cloexec.c
- https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/fcntl.c
- https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/cloexec.c
- https://man7.org/linux/man-pages/man2/fcntl.2.html