System Programming: Can D binaries be set suid root without the risk of unwanted privilege escalation?
GB
gb254 at gmail.ccom
Thu Aug 20 23:19:52 UTC 2026
On Thursday, 20 August 2026 at 14:16:47 UTC, Forum User wrote:
> On Monday, 16 February 2026 at 01:24:59 UTC, Julian Fondren
> wrote:
>
> Thanks for the thorough answers and the link.
>
>> [..] For example, suppose you have a setuid program that edits
>> /home/$user/somedir/somefile . If you do this
>> straightforwardly in D you open yourself up to a ton of
>> potential race conditions that can result in you editing or
>> deleting random files across the filesystem, or pulling
>> secrets and exposing them to the user.
>
> Such access I would usually perform with the effective user and
> effective group set to $user (`seteuid`, `setegid`). For some
> edge cases the supplementary groups must also be set (assume a
> `root:video` owned file `data` has permissions `0704` and
> assume the accessing user either has or has not `video` in its
> supplementary groups list: In the first case they cannot access
> `data` while in the second they can via `o=r` permission.)
The useful thing to remember from this thread:
The binary you compile is never just your code.
Even if your own D code is pristine, you are inheriting the
behavior of druntime, the garbage collector, and the Phobos
standard library - all of which might look at the environment,
allocate memory, or handle system calls in ways you didn't
explicitly write or intend.
In systems programming, you are always writing on top of someone
else's assumptions.
More information about the Digitalmars-d
mailing list