Directory isolation for POSIX IPC?

Aaron Rainbolt arraybolt3@gmail.com
Sun Nov 8 04:18:26 GMT 2026


glibc's temporary file creation functions can use the value of the
TMPDIR environment variable to determine where to place a temporary
file. This feature is used by Debian's libpam-tmpdir package (which
unfortunately seems to exist only in Debian's archives) to implement
per-user temp file isolation; a /tmp/user/<UID> directory is created
with mode 0700 when a user logs in, and TMPDIR is set in the
environment of whatever process is launched as part of login. This way
it's harder for malicious users on the same machine to mess with temp
files created by other processes in various ways. This mostly protects
against poorly written programs since anyone using mkstemp() and friends
will get files with mode 0600 that are guaranteed to be newly created,
but for some systems this is useful. systemd finds it valuable enough
to protect against /tmp-based attacks that it provides a PrivateTmp
option for services that serves a similar purpose but at a per-service
level using mount namespaces instead.

At the moment, there is no similar mechanism for/dev/shm. Anything that
uses shm_open() or sem_open() will end up with files created in
world-writable dirs that could theoretically be snooped on or
interfered with by malicious programs. These directories are arguably
at higher risk for abuse than /tmp, since neither of these functions
come with built-in filename randomization, both of them can be called
without passing O_EXCL, and both of them allow specifying an unsafe mode
like 0644. This could let a malicious process potentially snoop on the
contents of shared memory belonging to processes running under
different user accounts, or into overwriting things they shouldn't, and
so on. This is not a theoretical concern, as haveged created a named
semaphore with 0644 permissions until June 27, 2026 [1], which isn't
necessarily that bad but demonstrates that people can and do mess up
file permissions when working with POSIX IPC.

With this in mind, I'm wondering if it makes sense to introduce an
environment variable (maybe SHMDIR?) for Linux and other Unices that
use  for shared memory, which would specify an alternative
location for shared memory files. Then something like libpam-tmpdir
could create hardened directories like /dev/shm/user/1000, and programs
that use these functions would have shared memory protected at least
from other users. This of course could cause issues for programs that
intentionally want to share memory across processes running under
different user accounts, but in that instance, the end-user could
override SHMDIR for those programs.

If this sounds like a good idea, I can try to send patches for it.

--
Aaron

[1] https://github.com/jirka-h/haveged/commit/99d5b8de8339ba7725e3cff005e2f77ccf699582
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 358 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20261107/592b30fa/attachment.sig>


More information about the Libc-alpha mailing list