AppArmor 如何进行“环境清理”?
AppArmor 文档提到让应用程序能够在有或没有环境清理的情况下执行其他程序。显然,清理的环境更安全,但文档似乎没有具体说明环境清理是如何发生的。
什么是环境清理以及 AppArmor 如何清理环境?
The AppArmor documentation mentions giving applications the ability to execute other programs with or without enviroment scrubbing. Apparently a scrubbed environment is more secure, but the documentation doesn't seem to specify exactly how environment scrubbing happens.
What is environment scrubbing and what does AppArmor do to scrub the environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“环境清理”是指删除各种“危险”环境变量,这些变量可能会影响二进制文件的行为 - 例如,
LD_PRELOAD
可用于使动态链接器拉入代码,从而可以对程序的运行进行实质上任意的更改;可以设置一些变量以导致跟踪输出到具有众所周知名称的文件; 作为一种安全措施,这种清理通常是针对 setuid/setgid 二进制文件执行的,但内核提供了一个挂钩,允许安全模块也为任意其他二进制文件启用它。
内核的 ELF 加载器代码 使用此钩子 设置传递给二进制文件的信息“辅助向量”中的
AT_SECURE
条目。 (请参阅此处和此处了解实现AppArmor 代码中此挂钩的一部分。)当在用户空间中开始执行时,动态链接器获取此值并使用它来设置
__libc_en able_secure
标志;您将看到同一例程还包含为 setuid/setgid 二进制文件设置此标志的代码。 (有 静态链接的二进制文件在其他地方的等效代码。)__libc_enable_secure
影响 动态链接器代码主体,并导致 列表要删除的特定环境变量。"Environment scrubbing" is the removal of various "dangerous" environment variables which may be used to affect the behaviour of a binary - for example,
LD_PRELOAD
can be used to make the dynamic linker pull in code which can make essentially arbitrary changes to the running of a program; some variables can be set to cause trace output to files with well-known names; etc.This scrubbing is normally performed for setuid/setgid binaries as a security measure, but the kernel provides a hook to allow security modules to enable it for arbitrary other binaries as well.
The kernel's ELF loader code uses this hook to set the
AT_SECURE
entry in the "auxiliary vector" of information which is passed to the binary. (See here and here for the implementation of this hook in the AppArmor code.)As execution starts in userspace, the dynamic linker picks up this value and uses it to set the
__libc_enable_secure
flag; you'll see that the same routine also contains the code which sets this flag for setuid/setgid binaries. (There is equivalent code elsewhere for binaries which are statically linked.)__libc_enable_secure
affects a number of places in the main body of the dynamic linker code, and causes a list of specific environment variables to be removed.