gpt4 book ai didi

linux - GNU ld 的 --audit 标志有什么作用?

转载 作者:太空狗 更新时间:2023-10-29 12:01:33 26 4
gpt4 key购买 nike

我有一个应用程序,我想在其中使用 rtld-audit Linux 提供的接口(interface)来 Hook 共享库加载过程。如果我使用 LD_AUDIT 环境变量告诉动态链接器在我运行我的程序时使用我的审计库 audit.so,这会很好用。

不过,我想让它更自动化一些,不需要特殊的环境设置。 GNU ld 提供了一个--audit 标志,说明如下:

--audit AUDITLIB

Adds AUDITLIB to the "DT_AUDIT" entry of the dynamic section. AUDITLIB is not checked for existence, nor will it use the DT_SONAME specified in the library. If specified multiple times "DT_AUDIT" will contain a colon separated list of audit interfaces to use. If the linker finds an object with an audit entry while searching for shared libraries, it will add a corresponding "DT_DEPAUDIT" entry in the output file. This option is only meaningful on ELF platforms supporting the rtld-audit interface.

这向我建议,如果我使用 --audit audit.so 链接我的程序,那么它应该将我的审计库与该程序相关联。我希望在程序运行时加载审计库。

果然,使用 readelf,我可以验证使用此标志会导致 audit.so 在 ELF header 中注册为审计库。但是,如果我在未设置 LD_AUDIT 的情况下运行我的程序,则永远不会调用审计库。似乎我必须设置 LD_AUDIT=audit.so 才能获得我想要的行为。

这引出了一个问题:--audit 标志实际上做了什么?上面引用的手册页之外的任何文档似乎都非常稀缺。我不清楚 Linux 动态加载器甚至使用 ELF header 中的 DT_AUDIT 字段。这是设计使然吗?

最佳答案

This begs the question: what does the --audit flag actually do?

它设置了DT_AUDIT动态入口,谁愿意关注它。

问题是(从 current trunk 开始)GLIBC 动态加载器关注它(查找process_dl_audit 例程)。它只关注LD_AUDIT环境变量,并在直接调用加载器时关注--audit标志:ld.so

直到有人贡献代码也关注DT_AUDIT--audit 标志到ld 将保持无用。

关于linux - GNU ld 的 --audit 标志有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34034009/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com