gpt4 book ai didi

c - docker 内部的 GDB 问题

转载 作者:行者123 更新时间:2023-12-02 01:47:43 25 4
gpt4 key购买 nike

使用 docker 版本 Docker version 1.1.0, build 79812e3在 Ubuntu 13.04 上,并使用由以下人员创建的 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 容器中的特定用户强制执行 ulimits 的唯一方法。

为什么 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

更新

只是为了表明它是 su docker 容器中的命令搞砸了,下面是用 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 对安全违规行为进行“投诉”而不是阻止它们。这不是最安全的解决方法,我真的很想找到一种更好的方法来处理它(比如只允许 ptrace 和 GDB 需要的任何其他东西)。

要告诉 apparmor 提示,您需要更改/etc/apparmor.d/docker 中的行:

profile docker-default flags=(attach_disconnected,mediate_deleted) {

到:

profile docker-default flags=(attach_disconnected,mediate_deleted,complain) {

关于c - docker 内部的 GDB 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24586086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com