Setuid 与 GTK+
我正在尝试编写一个程序并将其与使用 Gtk+ 构建的 gui 集成。然而,由 GUI 调用的 exe 已设置了 setuid 位。但是 gtk 不允许此 exe 按照 gtk 社区的指定运行。然而他们说我们必须编写单独的帮助程序等等。我真的不明白这意味着什么。任何人都可以阐明如何克服这个问题吗?我真的需要一个立即的解决方案。
I'm trying to write a program and integrate it with gui built with Gtk+. The exe that is to be called by the gui however has the setuid bit set. However gtk does not allow this exe to run as specified by the gtk community. They however say that we have to write separate helper programs and all. I really dont understand what that means. Can anyone please shed some light on how to overcome this problem? I really need an immediate solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个问题:为什么你的程序是setuid?编写 setuid 程序不适合自称 Linux 新手的人玩。他们很危险。它们很有用——不要误会我的意思。但它们很危险并且难以安全地写入。
GTK+ 项目在“GTK+ - 使用 setuid”中非常直率地阐述了他们对 setuid 程序的看法。他们给出了自己的理由——很好的理由。它们指出了如何避免问题:
既然您应该编写一个帮助程序,您是否寻找过示例?他们很可能是被给予的。你的程序本身是一个GUI应用程序吗?
所以,这正是 GTK+ 团队所描述的场景。您需要一个由 GUI 启动的小型 setuid root 程序,并通过管道或 Unix 域套接字或某种类似技术与其连接。
当您需要来自外设的数据时,您的主应用程序向守护程序/帮助程序写入请求,然后等待包含数据的响应。
概括地说,您的 GUI 中将包含以下代码:
同时,您的守护程序/帮助程序将:
您仍然应该查看外围设备上的权限是否正确 - 或者为什么您需要从只有 root 才能读取的数据中读取数据。
First question: why is your program setuid? Writing setuid programs is not a game that should be played by self-professed Linux newbies. They're dangerous. They're useful - do not get me wrong. But they are dangerous and difficult to write securely.
The GTK+ project states their view on setuid programs very forthrightly at 'GTK+ - Using setuid'. They give their reasons - good ones. They indicate how to avoid problems:
Since you're supposed to write a helper program, have you looked for examples? It is likely that they're given. Is your program itself a GUI application?
So, this is exactly the sort of scenario that the GTK+ team describe. You need a small setuid root program that is launched by your GUI, and that is connected to it by pipes or a Unix-domain socket, or some similar technique.
When you need data from the peripheral, your main application writes a request to the daemon/helper and then waits for a response containing the data.
In outline, you will have code in your GUI to:
Meanwhile, your daemon/helper program will:
You should still look at whether the permissions on the peripheral are correct - or why you are needing to read data from something that only root is supposed to be able to read from.
我认为,当 GTK+ 团队在这里警告不要在 setuid 中使用 GTK+ 时,他们的心是对的。程序。但我有两个观察结果和一个解决方法。
首先,警告这种做法是一回事,而让这种做法看似不可能则完全是另一回事。想到那些设计师说“用户没有正当理由去做 XXX”,然后又不遗余力地让 XXX 变得不可能,这让我很恼火。警告风险,让用户承担风险。
其次,GTK+团队混淆了“setuid”和“setuid root”。下面的例子说明了这种区别的重要性。在这个例子中,我不想扩大使用 GTK+ 的程序的权限,而是减少它们。在某些情况下,我希望能够运行 Firefox(好吧,iceweasel,但它基本上是相同的),使其只能查看本地文件,而没有网络功能。因此,我在 Linux 系统中设置了 iptables,以便特定的(人为创建的)用户无法访问外部世界。我希望能够以该用户身份运行 Firefox,无论我实际上是哪个用户。假设受限用户的uid和gid为1234,则以下总体思路将起作用。将其构建为 setuid root。希望这有帮助。
编辑 2014-02-22 15:13 UTC
我忘了提到你可以用 0 代替每个 1234,然后你就获得了 root 权限。有人可能会说这是一个完全糟糕的主意,我想我可以理解这一点。
I think that the GTK+ team's heart is in the right place when they warn here against using GTK+ in setuid programs. But I have two observations, and a workaround.
First, it is one thing to warn against such a practice, and another thing entirely to make such a practice seemingly impossible. It irritates me to think of designers who say "There is no valid reason for users to do XXX", and then go out of their way to make XXX impossible. Warn of the risk, and let the user take the risk.
Second, the GTK+ team confuses "setuid" with "setuid root". Here's an example of where the distinction is important. In this example, I want not to expand the privileges of a program using GTK+, but to reduce them. Under certain circumstances, I want to be able to run Firefox (well, iceweasel, but it's basically the same) crippled so it can look at only local files, with no network capability. So I've set up iptables in my Linux system so that a particular (artificially created) user has no access to the outside world. I want to be able to run Firefox as that user, no matter which user I actually am. Assuming that the restricted user's uid and gid are 1234, the following general idea will work. Build it as setuid root. Hope this helps.
EDIT 2014-02-22 15:13 UTC
I neglected to mention that you can substitute 0 for each 1234, and you've got root. One could argue that this would be a totally bad idea, and I guess I can understand that point.
我的代码与 rpi 上的 DMA 硬件(pigpio 的修改版本)紧密连接,以获得最大可能的计时精度。 (应用程序是计时器和赛狗赛事的判断系统)
使用守护程序进行需要根访问的操作可能会在关键路径中引入不可接受的延迟。至少,需要进行广泛的测试,以确保一切都满足绝对计时精度要求。
该应用程序在独立的 rpi 上运行。没有联网,没有人会通过 ssh 进入其中。
获得替代方案并进行测试需要花费真正的美元!
没有人能够比应用程序开发人员更好地在安全风险与其他应用程序考虑因素之间做出权衡。
我现在经常看到这种情况。安全问题已经成为一个大问题,安全策略是由那些真正无法考虑其影响的所有用例的人执行的。
太傻了——所以我将使用 sudo 来运行。
My code interfaces closely with DMA hardware (modified version of pigpio) on an rpi to get the greatest possible timing accuracy. (Application is timers and judging system for dog racing events)
Using a daemon for the operations that required root access will likely introduce unacceptable latency in critical paths. At a minimum, it will require extensive testing to make sure everything will meet absolute timing accuracy requirement.
The application runs on a standalone rpi. Not networked, no one will ssh into it.
It costs real $$$ to do get an alternative working and tested!
No one can make an informed decision about trading off security risks against other application considerations better than the developer of the app.
I see this frequently nowadays. Security concerns have become such a big deal, security policies are enforced by those who really can't consider all use cases they impact.
So silly--so I will run using sudo instead.
通常,最好将系统设置为非 root 用户可以打开设备文件,然后让普通的非 root 进程与它们通信。
Often, it is better to set up the system such that the device files can be opened by a non-root user, and then let normal non-root processes talk to them.