Skip to content

You set LD_PRELOAD to your own library and run a setuid-root binary. Does your library load?

Short answer

No. A setuid binary runs in secure-execution mode (the kernel sets AT_SECURE), and the dynamic linker then ignores LD_PRELOAD paths that contain slashes; only libraries from the standard directories that are themselves set-user-ID are preloaded. That is why 'LD_PRELOAD=./evil.so /usr/bin/passwd' does not hand you root. The same mode also ignores LD_LIBRARY_PATH and strips these variables from the environment.

A classic privilege-escalation reflex is "inject a library with LD_PRELOAD into something that runs as root." For setuid binaries the dynamic linker was designed to stop exactly that, and an interviewer wants to see that you know the boundary.

What triggers the restriction

The ld.so(8) manual page says the dynamic linker enters secure-execution mode when the kernel's AT_SECURE auxiliary-vector entry is non-zero. That happens when the real and effective user (or group) IDs differ, typically for set-user-ID and set-group-ID programs; when a non-root process runs a binary that grants capabilities; or when a Linux Security Module sets it.

What the linker does in that mode

In secure-execution mode, preload pathnames containing slashes are ignored. Only libraries found in the standard search directories are preloaded, and only if they have the set-user-ID bit set. LD_PRELOAD is also among the variables whose effects are voided or modified and that are stripped from the environment. LD_LIBRARY_PATH is ignored too, and LD_AUDIT and LD_DEBUG are restricted.

Why it matters

  • Defenders: a plain unprivileged user cannot turn LD_PRELOAD into a root shell via a setuid binary, so the variable is a vector mainly for processes you already control (or for lower-privilege hooking and rootkit-style behavior).
  • Persistence: the same page documents /etc/ld.so.preload, a system-wide list of libraries loaded before every program. It is worth monitoring.

Why the distractors are tempting

"Honored for every ELF" ignores the secure-execution rules. "Owned by root" invents an ownership rule — the actual conditions are the slash restriction and the set-user-ID requirement. "Setuid binaries are static" is false; most are dynamically linked.

What interviewers want

A clear "no", the name secure-execution mode with AT_SECURE, and the awareness that /etc/ld.so.preload is the next place to look.

Likely follow-ups

  • What triggers secure-execution mode besides the setuid and setgid bits?
  • Why does /etc/ld.so.preload matter for persistence and detection even though LD_PRELOAD is restricted for setuid programs?
  • Which other environment variables does the dynamic linker ignore or strip in this mode?

Sources

Get 100 cybersecurity interview questions + answers

Drop your email and we'll send you the free PDF pack and the flashcard deck.

No spam. Unsubscribe anytime.