为什么在LD_PRELOAD中委托文件访问方法会导致权限错误?

时间:2018-01-09 23:43:02

标签: permissions configure ld-preload

我正在处理auto-apt的后继者,这是一个记录openaccessstat文件请求的脚本(例如在{{ 1}}}脚本)并将它们与configure索引中可用的已安装文件和文件列表进行比较。这个重新编码已在原始文件中完成,该文档未经文档记录多年(并且作者无法访问),并使用Contents.gz中使用的共享库覆盖LD_PRELOADopenaccessstatopen64

我开始学习如何将stat64https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/一起使用。我不明白原作。

虽然对于某些程序,例如LD_PRELOAD,但没有问题,我在GCC 7.2的gnome-calculator开始时遇到permission denied错误,而bison 3.0 .4,例如

configure

(我知道必须使用checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether ln works... yes checking whether ln -s works... yes checking for a sed that does not truncate output... /bin/sed checking for gawk... gawk checking for libatomic support... yes checking for libcilkrts support... yes checking for libitm support... yes checking for libsanitizer support... yes checking for libvtv support... yes checking for libmpx support... yes checking for libhsail-rt support... yes checking for gcc... gcc ./configure: line 4297: conftest.err: Permission denied ./configure: line 4297: conftest.err: Permission denied ./configure: line 4297: conftest.err: Permission denied cat: confdefs.h: Permission denied checking for C compiler default output file name... sed: can't read conftest.c: Permission denied configure: error: in `/home/richter/sources/gcc-7.2.0': configure: error: C compiler cannot create executables See `config.log' for more details. cat: confdefs.h: Permission denied 中的脚本下载prequisistes,但这不应该影响此问题,而GCC似乎是复制的好例子。

根据我创建的引用博客文章

contrib

在运行/* * Experiments with LD_PRELOAD following * https://web.archive.org/web/20171226024326/https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/ */ #define _GNU_SOURCE #include <dlfcn.h> #include <stdio.h> #include <stdlib.h> typedef int (*orig_open_f_type)(const char *filename, int flags); typedef int (*orig_stat_f_type)(int ver, const char *filename, struct stat *buf); typedef int (*orig_stat64_f_type)(int ver, const char *filename, struct stat64 *buf); int open(const char *filename, int flags, ...) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"open"); return orig_open(filename, flags); } int __libc_open(const char *filename, int flags, ...) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"__libc_open"); return orig_open(filename, flags); } int open64(const char *filename, int flags, ...) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"open64"); return orig_open(filename, flags); } int __libc_open64(const char *filename, int flags, ...) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"__libc_open64"); return orig_open(filename, flags); } int access(const char *filename, int type) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"access"); return orig_open(filename, type); } int euidaccess(const char *filename, int type) { orig_open_f_type orig_open; orig_open = (orig_open_f_type)dlsym(RTLD_NEXT,"euidaccess"); return orig_open(filename, type); } int __xstat(int ver, const char *filename, struct stat *buf) { orig_stat_f_type orig_stat; orig_stat = (orig_stat_f_type)dlsym(RTLD_NEXT,"__xstat"); return orig_stat(ver, filename, buf); } int __xstat64(int ver, const char *filename, struct stat64 *buf) { orig_stat64_f_type orig_stat64; orig_stat64 = (orig_stat64_f_type)dlsym(RTLD_NEXT,"__xstat64"); return orig_stat64(ver, filename, buf); } int __lxstat(int ver, const char *filename, struct stat *buf) { orig_stat_f_type orig_stat; orig_stat = (orig_stat_f_type)dlsym(RTLD_NEXT,"__lxstat"); return orig_stat(ver, filename, buf); } int __lxstat64(int ver, const char *filename, struct stat64 *buf) { orig_stat64_f_type orig_stat64; orig_stat64 = (orig_stat64_f_type)dlsym(RTLD_NEXT,"__lxstat64"); return orig_stat64(ver, filename, buf); } 时创建上述输出。 env LD_PRELOAD=/path/to/ldpreload.so dash ./configure似乎没有帮助:

config.log

可以在https://gitlab.com/krichter/ld-preload-demo找到MCVE。

0 个答案:

没有答案