4 ms·
Huh. If I'm reading that correctly, that means it would be possible to build a paranoid_sudo command, where you run a command and use PTRACE_SYSCALLS on it, and
by JoshuaDavid 6y ago
Huh. If I'm reading that correctly, that means it would be possible to build a paranoid_sudo command, where you run a command and use PTRACE_SYSCALLS on it, and for each of the syscalls it makes, try running it first as a non-root user, and if that fails prompt the user for whether they want to allow the base program to run whatever syscall requires the child process to be root.
I don't think the above would actually be all that useful, but still it's kind of cool that it's possible to do at all.
- roblabla 6y agoPTRACE_SYSCALL isn't what you want, since it will always run the syscall. What you can do is use PTRACE_SYSEMU, which allows you to emulate a syscall in userland. It will break on syscall enter, allow you to emulate your syscall (e.g. with your scheme of "run it without root, ask user for elevated privs if necessary"), and resume execution at the next instruction when you ptrace again, never really executing the syscall instruction. For this to work you'd also need a way to share various namespaces (like file descriptors) which is doable via the clone2 syscall. There's a ton of cool tricks you can do with linux, it's a really powerful kernel.