Skip to content
Memory corruption Write-up Advanced

PwnKit: Vulnerability in Polkit (CVE-2021-4034)

A memory corruption flaw in polkit's pkexec, a SUID-root program, allows any unprivileged user to gain full root privileges on a vulnerable host by exploiting the default configuration. The vulnerability has existed since 2009 and affects all major Linux distributions.

blog.qualys.com

Published on blog.qualys.com

The Qualys Research Team has discovered a memory corruption vulnerability in polkit’s pkexec, a SUID-root program that is installed by default on every major Linux distribution. This easily exploited vulnerability allows any unprivileged user to gain full root privileges on a vulnerable host by exploiting this…

The author, on blog.qualys.com

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

Root cause

Likely, pkexec's main() function does not validate that argc is greater than zero, so when called with an empty argument list, it reads and writes out-of-bounds at argv[1], which overlaps with envp[0], allowing an attacker to reintroduce dangerous environment variables like LD_PRELOAD.

Impact

Successful exploitation allows any unprivileged user to gain root privileges on the vulnerable host, and the researchers verified this on default installations of Ubuntu, Debian, Fedora, and CentOS; other distributions are likely vulnerable, though OpenBSD is not exploitable because its kernel refuses to execve() a program if argc is 0.

What the attacker needed

Local access as an unprivileged user; vulnerable pkexec installed (default)

The fix

The vulnerability was fixed by applying patches from vendors; as a temporary mitigation, remove the SUID-bit from pkexec.

How it was found

  1. Call pkexec with an empty argument list (argc = 0) so that argv[0] is NULL.
  2. Set the first environment variable to a value that does not start with a slash, such as a program name.
  3. Ensure the PATH environment variable points to a directory containing an executable file with that name.
  4. pkexec reads the out-of-bounds argv[1] (envp[0]) as the program path and searches for it in PATH.
  5. pkexec writes the full path back to argv[1] (envp[0]), overwriting the first environment variable.
  6. This out-of-bounds write reintroduces an unsecure environment variable (e.g., LD_PRELOAD) that is normally removed for SUID programs, enabling privilege escalation.

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 lets users run commands with higher privileges, and it is installed by default on most Linux systems. A bug in how it handles command-line arguments lets a normal user trick it into running their own code as the root administrator, giving them complete control of the machine.

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.