docker内部的GDB问题
·
问题:docker内部的GDB问题
在 Ubuntu 13.04 上使用 docker 版本Docker version 1.1.0, build 79812e3
,并使用由以下人员创建的 docker 容器:
# docker build -t gdb_problem_testing - < THIS_FILE
FROM ubuntu
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y build-essential gdb
这样做:
user@host $ sudo docker run --rm -it --user=root gdb_problem_testing su root -c bash
root@690396061e81:/# cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test
> #include <stdio.h>
>
> int main(int argc, char **argv) {
> printf("Hello\n!");
> }
> EOF
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /test...done.
Starting program: /test
user@host $
不运行程序。 gdb 刚刚启动并退出。请注意最后一行,我什至从 docker 容器启动并且没有返回到 bash 提示符 (!)
我无法在非 docker 环境(su <some_user> -c bash
等)中重现这一点。
如果我不使用su <some_user> -c bash
而只是使用bash
,则不会出现此问题。由于各种原因,必须使用su
,主要是因为这是我发现能够为 docker 容器中的特定用户强制执行 ulimit 的唯一方法。
为什么 gdb 在这种情况下不起作用?
编辑
在 docker 容器中运行的 copy-pastable 命令:
cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello\n!");
}
EOF
更新
只是为了表明是 docker 容器中的su
命令搞砸了,下面是使用bash
而不是su root -c bash
执行相同操作的输出:
user@host $ sudo docker run --rm -it --user=root gdb_problem_testing bash
root@ce1581184f7a:/# cat <<EOF > test.c && gcc -ggdb test.c -o test && gdb -ex run test
> #include <stdio.h>
>
> int main(int argc, char **argv) {
> printf("Hello\n!");
> }
> EOF
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /test...done.
Starting program: /test
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
Hello
![Inferior 1 (process 17) exited with code 07]
(gdb)
注意程序实际是如何运行的(打印出“Hello”),我留在了 gdb 和 docker 容器中。
解答
这是由于apparmor。我有一个解决方案,但需要在每次启动后应用。
诀窍是告诉 apparmor 对安全违规行为“抱怨”而不是阻止它们。这不是最安全的解决方法,我真的很想找到一种更好的方法来处理它(比如只允许 ptrace 和 GDB 需要的其他任何东西)。
要告诉 apparmor 投诉,您需要将 /etc/apparmor.d/docker 中的行从:
profile docker-default flags=(attach_disconnected,mediate_deleted) {
至:
profile docker-default flags=(attach_disconnected,mediate_deleted,complain) {
更多推荐
所有评论(0)