当前位置: 首页>>技术教程>>正文


什么是葡萄酒计划的’ptrace_scope’解决方法,有任何风险吗?

, , ,

问题描述

要在WINE中运行某些Windows程序,您需要以下解决方法:

echo 0|sudo tee /proc/sys/kernel/yama/ptrace_scope

根据支持网站的说法,这是因为Ubuntu内核中的一个错误会阻止ptrace和WINE一起播放。

使用上面的命令你将ptrace设置为0,根据研究I’ve done(don’t问我哪些网站,我看起来很多),ptrace与程序之间的交互有关。 0设置比1更宽松。

我必须假设有一个很好的理由Ubuntu想要ptrace = 1所以这导致我回到问题的简短形式。

设置ptrace = 0是否存在任何风险。降低安全性?问题调试?我还没有想到的任何其他人?

附:对于任何阅读此内容的人来说,想知道这个bug会导致什么,Windows程序根本无法打开,在系统监视器中你会看到程序的许多实例试图打开,然后他们最终都会退出,如果你运行的程序是终端您将收到一个错误,告诉您已达到最大程序实例数。

最佳解决思路

简短的回答:没有实际的危险,但请继续阅读以获得更好的方法……


无论如何,这个ptrace是什么东西?

this is due to a bug in the Ubuntu kernel that prevents ptrace and WINE playing well together.

  • 不,ptrace保护是围绕Ubuntu 10.10首次引入的deliberate kernel security measure。这不是一个错误,所以不会是”fixed”。

  • 简单来说,1的默认ptrace_scope值阻止一个进程检查和修改另一个进程,除非第二个进程(子进程)由第一个进程(父进程)启动。

  • 由于wineserver为这些程序提供”Windows Services”的方式,这可能会导致Wine下的某些程序出现问题。

ptrace_scope设置为0有哪些风险?

  • 这将恢复旧行为,其中一个进程可以”trace”另一个进程,即使没有parent-child关系。

  • 从理论上讲,一件恶意软件可以用它来伤害你/你的电脑;例如它可以附加到Firefox并记录您的所有URL /密码等。在实践中,这是极不可能的,除非你盲目地从随机站点等安装二进制debs。

  • 就调试而言,0设置实际上需要gdbstrace等附加到non-children,除非您使用提升的权限(sudo)运行它们。

解决方法有什么问题?

  • 解决方法有些问题,因为ptrace_scope是一个全局值,并且当它设置为0时,系统上的所有进程都免于non-child限制。

  • 如果使用解决方法,请将其放在启用它的简单bash脚本中,运行Windows程序,然后在退出时禁用(设置为1)。

    • 请不要将ptrace_scope world-writable(666)作为论坛帖子推荐 – 这是一个巨大的安全风险,因为现在任何流程都可以随意更改它!

有更好的解决方案吗?

  • 更安全且不需要重复修改ptrace_scope的更好的解决方案是grant Wineserver ptrace capabilities

    • 在终端:sudo apt-get安装libcap2-bin sudo setcap cap_sys_ptrace = eip /usr /bin /wineserver sudo setcap cap_sys_ptrace = eip /usr /bin /wine-preloader

    • 这可以将wineserver和wine-preloader二进制文件从non-child ptrace限制中免除,并允许它们对任何进程进行ptrace。

    • 它只需要完成一次,并且更安全,因为这些二进制文件通常来自可靠的来源 – 官方存储库或官方Wine PPA,因此它们不会是恶意软件。

如果你正在使用Crossover

安装libcap2:

sudo apt-get install libcap2-bin;

然后,为Crossover添加一个例外:

sudo setcap cap_sys_ptrace=eip /opt/cxoffice/bin/wineserver;
sudo setcap cap_sys_ptrace=eip /opt/cxoffice/bin/wine-preloader;

最后,将其库添加到ld.so.conf(或者在加载共享库时会出现“错误:libwine.so.1:无法打开共享对象文件:没有这样的文件或目录”):

echo /opt/cxoffice/lib/ | sudo tee /etc/ld.so.conf.d/crossover.conf
sudo /sbin/ldconfig

次佳解决思路

ubuntuforums.org中,我得到了以下链接的答案

https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection

这是链接中的粘贴(加上我的重点)

As Linux grows in popularity, it will become a growing target for malware. One particularly troubling weakness of the Linux process interfaces is that a single user is able to examine the memory and running state of any of their processes. For example, if one application (e.g. firefox) was compromised, it would be possible for an attacker to attach to other running processes (e.g. gpg-agent) to extract additional credentials and continue to expand the scope of their attack.

This is not a theoretical problem. SSH session hijacking and even arbitrary code injection is fully possible if ptrace is allowed normally.

For a solution, some applications use prctl() to specifically disallow such ptrace attachment (e.g. ssh-agent). A more general solution is to only allow ptrace directly from a parent to a child process (i.e. direct gdb and strace still work), or as the root user (i.e. gdb BIN PID, and strace -p PID still work as root).

This behavior is controlled via the /proc/sys/kernel/yama/ptrace_scope sysctl value. The default is “1” to block non-child ptrace. A value of “0” restores the prior more permissive behavior, which may be more appropriate for some development systems and servers with only admin accounts. Using “sudo” can also grant temporarily ptrace permissions via the CAP_SYS_PTRACE capability, though this method allows the ptrace of any process.

所以我想简短的答案是它不太安全,但个人计算机遭遇这类攻击的可能性很小。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/6322.html,未经允许,请勿转载。