3 ms·
> When will these distros accept suid was a mistake and disable it. I have the following C program that I use as an unprivileged user to put my system into and
by simoncion 7mo ago
> When will these distros accept suid was a mistake and disable it.
I have the following C program that I use as an unprivileged user to put my system into and out of Game Mode.
1) Do you believe that this program is unsafe when compiled and set suid root?
2) How do you propose that I replace it with something that isn't suid root?
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void maybe_do(const char * cmd) {
if(system(cmd)) {
perror(cmd);
exit(2);
}
}
int main(int argc, char** argv) {
if(argc != 2) {
return 1;
}
int turnOff = strncmp("on", argv[1], 2);
if(setuid(0)) {
perror("uid");
return 2;
}
if(turnOff) {
maybe_do("/usr/bin/cpupower frequency-set --governor schedutil > /dev/null");
maybe_do("/bin/echo auto > /sys/class/drm/card0/device/power_dpm_force_performance_level");
} else {
maybe_do("/usr/bin/cpupower frequency-set --governor performance > /dev/null");
maybe_do("/bin/echo high > /sys/class/drm/card0/device/power_dpm_force_performance_level");
}
return 0;
}
- c-hendricks 7mo agoRun the part that needs root as a daemon, some server that accepts http requests Use sudo and allow anyone to run the binary without password auth Use the existing gamemode package Those are a few options, of course it's your system in the end
- simoncion 7mo agoFirst off, thanks very much for giving me exactly what I asked for. You propose that instead of sometimes running ~five lines of C as root, I do one of the following: 1) Run a persistent whole-ass daemon using something for IPC... maybe DBUS, maybe HTTP, and all the code that that pulls in. 2) Use a setuid root program [0] to run the entire program as root, rather than just the ~five lines that need root privs. 3) Use a package that has several-thousand lines of C (and who knows how many lines of Python) running as root and does way more than I need. All of these alternatives tell a story: The alternative to running ~five lines of C as root is to run *many* more lines as root. This is kinda my point. Some people rave about setuid programs and assert that they should not exist, but when you absolutely need to let an unprivileged user do things that only root is ordinarily permitted to do you're going to have to have code running as root. And when you have code running as root, you have to be careful to get it right. Whether it's running from a setuid root-owned executable, a persistent daemon running as root, or a regular program that sudo [1] has executed as root is irrelevant: it's all code running as root! [0] People shit on sudo for both being setuid root and for being "too complicated". I love the hell out of the program; it's an essential part of how I get shit done on my PC. sudo is -very seriously- a great tool. [1] ...or similar...
- charcircuit 7mo ago>1) Building services should be easy. The fact that Linux does not have an easy to use IPC mechanism is the fault of Linux. Yes, systemd can make it so services don't have to run until they are connected, and yes dbus exists, but it's overcomplicated for something which should be easy to make. This is a Linux devex failure. >2) I agree this is going in the wrong direction. Full sudo is also even more in the wrong direction away from only giving the minimal amount of privileges to the code that needs it. >3) See my response to 1). Making programs with different capabilities able to talk to each other should be made dead easy to do.
- simoncion 7mo ago> The fact that Linux does not have an easy to use IPC mechanism... What? Send bytes down a UNIX socket. There's nothing easier, really. It's so simple, it's what systemd uses to have monitored daemons indicate that they're now actually running. The rest of your commentary has nothing to do with my commentary about unprivved users running code as root. Given the failure to address my on-topic commentary, I'll assume that you don't actually have problems with setuid-root executables.
- charcircuit 7mo ago>There's nothing easier, really. It's so simple It really isn't. You have to a whole protocol on top of it if you want to use it and then build out the daemon logic yourself. If it was so easy why didn't you write it instead of making a suid binary. The complexity is not sufficiently abstracted away. >Given the failure to address my on-topic commentary, I'll assume that you don't actually have problems with setuid-root executables. My whole response was addressing the core of your argument in your post "The alternative to running ~five lines of C as root is to run many more lines as root." The reason it's many more lines is because the Linux developers did not write abstractions to make it simple to do. If you read my original post in this comment chain you will see that I do have problems with setuid executables and want distros to disable them.
- magicalhippo 7mo ago
- charcircuit 7mo ago1) I believe the current iteration you have of it is safe. 2) I suggest that a service is created for managing system performance that exposes an API to your user to turn on and off game mode.
- simoncion 7mo agoMy commentary here [0] directly relates to your #2. [0] <https://news.ycombinator.com/item?id=47436085 https://news.ycombinator.com/item?id=47436085>