如何在 Linux 上禁用二进制文件的地址空间随机化?

发布于 2024-08-04 22:05:35 字数 631 浏览 5 评论 0原文

我正在开发一个并行程序的运行时系统,该系统可以利用跨多个进程的公共地址空间布局,可能分布在多个(数千个)节点上。很多时候,为此环境构建的软件在默认启用地址空间随机化的 Linux 系统上运行,用户可能不希望或无法在系统范围内禁用它(通过 sysctl -w kernel.randomize_va_space=0< /code> 等)。这对并行程序施加了一些限制,并且可能会损害性能。因此,我们想要弄清楚如何为我们构建的二进制文件禁用它。安全性不是问题,因为该软件始终在受控环境中运行。

我找到了对各种标志和变量的引用,例如 ET_EXECEF_AS_NO_RANDOM (显然从未合并?)和 PF_RANDOMIZE,但我不能找到任何描述我可以做什么来设置这些标志的文档。理想的答案是告诉我什么编译器/汇编器/链接器标志将禁用生成的二进制文件的随机化,以及它适用于哪些版本的工具链/内核。下一个最好的工具是在构建二进制文件后执行相同操作的工具。

因为我确信有人会建议它,所以我已经知道我们可以在运行时使用 setarch -R 进行此更改,但最好将其记录在可执行文件中。

看起来 paxctl -rx 应该可以解决问题,但它似乎不适用于不包含 PaX 补丁的内核中当前使用的方法。

I'm working on a runtime system for parallel programs that can take advantage of a common address space layout across multiple processes, potentially spread over several (thousand) nodes. Many times, software built for this environment is run on Linux systems that have address space randomization enabled by default, and users may not want or be able to disable it system-wide (via sysctl -w kernel.randomize_va_space=0 and the like). This imposes some limitations on the parallel programs, and can hurt performance. Thus, we want to figure out how to disable it for the binaries that we build. Security is not an issue, as this software is always running in controlled environments.

I've found references to various flags and variables, like ET_EXEC, EF_AS_NO_RANDOM (apparently never merged?) and PF_RANDOMIZE, but I can't find any document that describes what I can do to set these flags. An ideal answer would tell me what compiler/assembler/linker flag will disable randomization for the resulting binary, and what versions of the tool-chain/kernel this works on. Next best would be a tool that does the same after a binary is built.

Since I'm sure someone will suggest it, I'm already aware that we can make this change at runtime with setarch -R, but it's preferable to record this in the executable.

It looks like paxctl -rx ought to do the trick, but it doesn't seem to apply to the current method used in kernels that don't include the PaX patches.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静谧 2024-08-11 22:05:35

假设您有某种守护程序可以调用节点上的并行程序。如果是这样,您可以使该公共父进程对其创建的任何子进程禁用 ASLR。

查看 GDB 源代码(7.0 或 CVS Head)了解如何做到这一点。其要点是在 fork 之后、exec 之前调用 personality(orig_personality|ADDR_NO_RANDOMIZE)

Presumably you have some kind of daemon which invokes your parallel programs on the nodes. If so, you can make this common parent disable ASLR for any child processes it creates.

Look in GDB sources (7.0 or CVS Head) for how to do that. The gist of it is to call personality(orig_personality|ADDR_NO_RANDOMIZE) after fork and before exec.

椵侞 2024-08-11 22:05:35

是否有某种原因导致您无法映射 共享内存 空间或使用命名的 < a href="http://linux.die.net/man/7/fifo" rel="nofollow noreferrer">FIFO?

Is there some reason you can't map a shared memory space or use a named FIFO?

说不完的你爱 2024-08-11 22:05:35

Linux 内核中至少有一些早期版本的 ASLR 分叉时保留了偏移量 。您是否可以简单地将它们排列在父/子进程层次结构下,从而使同一父进程派生的二进制实例之间的偏移量保持相同,而不是禁用进程的随机化?

At least some earlier versions of ASLR in the Linux kernel preserved offsets when forking. Rather than disabling randomization for your processes, might you simply be able to arrange them under a parent/child process hierarchy that kept the offsets the same between instances of the binary forked by the same parent?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文