如何禁用Linux上的二进制文件的地址空间随机化? [英] How to disable address space randomization for a binary on Linux?

查看:252
本文介绍了如何禁用Linux上的二进制文件的地址空间随机化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



由于我确定有人会提出这个建议,我已经意识到我们可以制作这个更改在运行时使用 setarch -R ,但最好将它记录在可执行文件中。



它看起来像 paxctl -rx 应该做到这一点,但它似乎并不适用于不包含PaX修补程序的内核中使用的当前方法。

解决方案

假设你有某种在节点上调用并行程序的守护进程。如果是这样,你可以使这个公共的父母禁用ASLR为它创建的任何子进程。



查看GDB源代码(7.0或CVS头)如何做到这一点。它的要点是在 fork 之后和 exec之前调用个性(orig_personality | ADDR_NO_RANDOMIZE)


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.

解决方案

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.

这篇关于如何禁用Linux上的二进制文件的地址空间随机化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆