Linux 如何将patchelf与--set解释器一起使用?

Linux 如何将patchelf与--set解释器一起使用?,linux,binary,patch,libc,Linux,Binary,Patch,Libc,我正在努力做到以下几点: 将simple test.c的libc从系统默认值(Debian 9.11,libc-2.24.so)更改为libc 2.27 这是我的尝试: user@pc:~/patchelf_test$ cat test.c #include <stdio.h> int main(int argc, char **argv) { printf("hello patchelf\n"); return 0; } user@pc:~/patchelf_

我正在努力做到以下几点:

将simple test.c的libc从系统默认值(Debian 9.11,libc-2.24.so)更改为libc 2.27

这是我的尝试:

user@pc:~/patchelf_test$ cat test.c 
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello patchelf\n");

    return 0;
}
user@pc:~/patchelf_test$ gcc test.c -o test
user@pc:~/patchelf_test$ ./test
hello patchelf
user@pc:~/patchelf_test$ ldd test
    linux-vdso.so.1 (0x00007ffd9d1d8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ea0290000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7ea0831000)
user@pc:~/patchelf_test$ patchelf --set-interpreter ./libc6-amd64_2.27-3ubuntu1_i386.so test
warning: working around a Linux kernel bug by creating a hole of 2093056 bytes in ‘test’
user@pc:~/patchelf_test$ ldd test
    linux-vdso.so.1 (0x00007fff20b9a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa46a35e000)
    ./libc6-amd64_2.27-3ubuntu1_i386.so => /lib64/ld-linux-x86-64.so.2 (0x00007fa46a900000)
user@pc:~/patchelf_test$ ./test
GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27.
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 7.3.0.
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
user@pc:~/patchelf_test$ 
我还尝试使用我的系统默认libc,并使用它进行修补,只是为了证明patchelf可以工作,但我再次遇到同样的问题——它执行链接器二进制文件本身,而不是测试二进制文件

user@pc:~/patchelf_test$ !gcc
gcc test.c -o test
user@pc:~/patchelf_test$ patchelf --set-interpreter ./libc_default.so test
warning: working around a Linux kernel bug by creating a hole of 2093056 bytes in ‘test’
user@pc:~/patchelf_test$ ./test
GNU C Library (Debian GLIBC 2.24-11+deb9u4) stable release version 2.24, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 6.3.0 20170516.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
user@pc:~/patchelf\u测试$!海湾合作委员会
gcc测试.c-o测试
user@pc:~/patchelf\u test$patchelf——设置解释器。/libc\u default.so test
警告:通过在“测试”中创建2093056字节的漏洞来解决Linux内核错误
user@pc:~/patchelf\u测试$/测试
GNU C库(Debian GLIBC 2.24-11+deb9u4)稳定发行版2.24,由Roland McGrath等人。
版权所有(C)2016免费软件基金会。
这是自由软件;有关复制条件,请参见源。
没有担保;甚至不是为了适销性或是否适合
特殊目的。
由GNU CC版本6.3.0 20170516编译。
可用扩展名:
MichaelGlady和其他人的crypt附加组件2.1版
西蒙·约瑟夫森的GNU Libidn
Ulrich Drepper等人的原生POSIX线程库
BIND-8.2.3-T5B
libc-ABIs:唯一的IFUNC
有关错误报告说明,请参阅:
.
战略:

$ strace ./test
execve("./test", ["./test"], [/* 44 vars */]) = 0
write(1, "GNU C Library (Debian GLIBC 2.24"..., 616GNU C Library (Debian GLIBC 2.24-11+deb9u4) stable release version 2.24, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 6.3.0 20170516.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
) = 616
exit_group(0)                           = ?
+++ exited with 0 +++
$strace./test
execve(“./test”、[”/test”]、[/*44变量*/])=0
Roland McGrath等人编写了(1,“GNU C库(Debian-GLIBC 2.24)”,616GNU C库(Debian-GLIBC 2.24-11+deb9u4)稳定版本2.24。
版权所有(C)2016免费软件基金会。
这是免费软件;有关复制条件,请参阅源代码。
没有任何保证;甚至不包括适销性或适用性
特殊目的。
由GNU CC版本6.3.0 20170516编译。
可用扩展名:
MichaelGlady和其他人的crypt附加组件2.1版
西蒙·约瑟夫森的GNU Libidn
Ulrich Drepper等人的原生POSIX线程库
BIND-8.2.3-T5B
libc-ABIs:唯一的IFUNC
有关错误报告说明,请参阅:
.
) = 616
退出组(0)=?
+++以0退出+++

此命令毫无意义:

patchelf——设置解释器。/libc6-amd64\u 2.27-3ubuntu1\u i386.so测试

libc.so.6
ld linux.so.2
完全不同,您正在将
PT_INTERP
设置为(相当于)
libc.so.6

此命令“正确”:

patchelf——设置解释器。/libc6-amd64\u 2.27-3ubuntu1\u i386.ld测试

但是结果很可能是由于系统GLIBC是不同的版本而崩溃。正如我所说,
ld linux
libc。因此.6
必须完全匹配

要使这一切正常工作,您应该摆脱有趣的
libc-amd64…
命名约定,将2.27版本完全解压缩到例如
/libc6-amd64\u 2.27/
目录中,然后使用类似以下内容:

patchelf --set-interpreter ./libc6-amd64_2.27/lib64/ld-linux-x86-64.so.2 test
LD_LIBRARY_PATH=./libc6-amd64_2.27/lib64 ./test

这个命令毫无意义:

patchelf——设置解释器。/libc6-amd64\u 2.27-3ubuntu1\u i386.so测试

libc.so.6
ld linux.so.2
完全不同,您正在将
PT_INTERP
设置为(相当于)
libc.so.6

此命令“正确”:

patchelf——设置解释器。/libc6-amd64\u 2.27-3ubuntu1\u i386.ld测试

但是结果很可能是由于系统GLIBC是不同的版本而崩溃。正如我所说,
ld linux
libc。因此.6
必须完全匹配

要使这一切正常工作,您应该摆脱有趣的
libc-amd64…
命名约定,将2.27版本完全解压缩到例如
/libc6-amd64\u 2.27/
目录中,然后使用类似以下内容:

patchelf --set-interpreter ./libc6-amd64_2.27/lib64/ld-linux-x86-64.so.2 test
LD_LIBRARY_PATH=./libc6-amd64_2.27/lib64 ./test