是否有可能使64位Linux加载程序将加载的32位程序的地址空间限制在某个上限?
还是在地址空间中设置一些不被内核分配的漏洞?
我指的是特定的可执行文件,而不是所有进程的全局可执行文件,也不是通过内核配置。一些代码或ELF可执行标志是适当解决方案的示例。
对于所有加载的共享库,也应该强制限制。
澄清:
我想解决的问题是,我的代码使用0xc0000000以上的数字作为句柄值,并且我希望明确区分句柄值和内存地址,即使内存地址是由某个第三方库函数分配和返回的。
只要64位Linux中的地址空间非常接近4G限制,就没有足够的寻址空间来处理句柄值。
另一方面,3GB甚至更低的容量已经足够满足我的所有需求了。
发布于 2016-03-12 14:48:15
好吧,我在别的地方找到了这个问题的答案。
解决方案是使用Linux系统调用PER_LINUX32_3GB,将程序的“个性”更改为sys_personality。
但有个问题。切换到PER_LINUX32_3GB之后,Linux内核将不会在1GB上分配空间,但是已经分配的空间(例如应用程序堆栈)仍然存在。
解决方案是通过sys_execve系统调用“重新启动”您的程序。
下面是我把所有东西打包在一起的代码:
proc ___SwitchLinuxTo3GB
begin
cmp esp, $c0000000
jb .finish ; the system is native 32bit
; check the current personality.
mov eax, sys_personality
mov ebx, -1
int $80
; and exit if it is what intended
test eax, ADDR_LIMIT_3GB
jnz .finish ; everything is OK.
; set the needed personality
mov eax, sys_personality
mov ebx, PER_LINUX32_3GB
int $80
; and restart the process
mov eax, [esp+4] ; argument count
mov ebx, [esp+8] ; the filename of the executable.
lea ecx, [esp+8] ; the arguments list.
lea edx, [ecx+4*eax+4] ; the environment list.
mov eax, sys_execve
int $80
; if something gone wrong, it comes here and stops!
int3
.finish:
return
endphttps://stackoverflow.com/questions/35913140
复制相似问题