Skip to content
Memory corruption Write-up Advanced

Pwnkit: Local Privilege Escalation in polkit's pkexec (CVE-2021-4034)

pkexec mishandles an empty argument list, causing an out-of-bounds read and write that lets a local user re-introduce dangerous environment variables and execute a shared library as root. This gives any unprivileged local user full root privileges.

seclists.org

Published on seclists.org

======================================================================== Contents ========================================================================

The author, on seclists.org

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

What the attacker needed

Local user account; pkexec installed with SUID bit; ability to execute a program with empty argv

The fix

The vulnerability was fixed by patching pkexec to handle argc 0 correctly; as a temporary mitigation, remove the SUID bit from pkexec.

How it was found

  1. Call execve() with an empty argument list (argc = 0).
  2. Set an environment variable whose name is used as the program name and whose value is a path to an executable.
  3. Set PATH to a directory containing an executable with that name.
  4. pkexec reads the environment variable as the program path and writes the full path back into the environment.
  5. This re-introduces an unsecure variable such as GCONV_PATH, which pkexec then uses to load a shared library as root.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

pkexec is a program that runs commands with higher privileges, like a supervisor. It made a mistake when given no arguments, letting a normal user sneak in a dangerous setting that makes the system load their own code with full control. This means anyone with a login could become the all-powerful root user.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.