CVE-2021–4034 Technical Review

Review of CVEs Used During Penetration Testing

I would like to write a Technical Detail about CVE-2021–4034, a 1-day vulnerability used for LPE (Local Privilege Escalation) during a penetration testing engagement. 
Since the LPE had to be performed on a live production server during the penetration test, it was necessary to use a relatively safe vulnerability. CVE-2021–4034 was determined to be a vulnerability that does not adversely affect the system, and this write-up covers the underlying mechanism that led to that safety assessment. 
The most detailed blog post available was used as a reference, and the GitHub PoC code reviewed was the one with the most stars.

[CVE-2021–4034 Overview]

CVE-2021–4034 leverages an OOB (Out-of-Bounds) access to inject an environment variable into a location where it normally cannot be written.

The malicious environment variable written via OOB is one related to character encoding within the code. When it operates in conjunction with other environment variables, the system mistakenly treats an executable planted by the attacker in an intended location as an encoding-related executable, and runs it.

[CVE-2021–4034 Key Mechanism_EN]

  1. Inducing OOB (Out-of-Bounds) via a null argument value

    • execve(“/usr/bin/pkexec”, args, environ);
    • By passing null for the args argument, OOB is induced inside pkexec’s internal for loop
  2. Misuse of the PATH parameter in pkexec.c’s main function

    • Inside s = g_find_program_in_path(path);, g_getenv("PATH") is called internally
    • See gutils.c in the references
  3. Injecting the GCONV_PATH parameter into envp[0] via OOB

    • argv[1] = path = s;
    • Although the memory position is envp[0], it is misidentified as argv[1], which allows GCONV_PATH — normally considered an unsafe environment variable — to be written there
  4. validate_environment_variable triggers g_printerr with a non-existent shell environment variable

  5. g_printerr executes iconv_open via the CHARSET setting

    • If CHARSET is not UTF-8, iconv_open is executed to perform character set conversion
  6. iconv_open checks for a file specified in gconv-modules under GCONV_PATH and executes it

    • See the man7 page in the references for detailed behavior of iconv_open

[CVE-2021–4034 Key Mechanism_KR]

  1. Inducing OOB (Out of Bounds) via a null argument value
    • execve(“/usr/bin/pkexec”, args, environ);
    • By passing null for the args argument, OOB is induced inside pkexec’s internal for loop
  2. Misuse of the PATH parameter in pkexec.c’s main function
    • Inside s = g_find_program_in_path(path);, g_getenv("PATH") is called internally
    • See gutils.c in the references
  3. Injecting the GCONV_PATH parameter into envp[0] via OOB
    • argv[1] = path = s;
    • Although the memory position is envp[0], it is misidentified as argv[1], which allows GCONV_PATH — normally considered an unsafe environment variable — to be written there
  4. validate_environment_variable triggers g_printerr with a non-existent shell environment variable
  5. g_printerr executes iconv_open via the CHARSET setting
    • If CHARSET is not UTF-8, iconv_open is executed to perform character set conversion
  6. iconv_open checks for a file specified in gconv-modules under GCONV_PATH and executes it
    • See the man7 page in the references for detailed behavior of iconv_open

[REFERENCE]

Writing an exploit for CVE-2021-4034 - TrustFoundry
_Writing an exploit for CVE-2021-4034 Intro Recently, a major local privilege escalation vulnerability…_trustfoundry.net

GitHub - berdav/CVE-2021-4034: CVE-2021-4034 1day
_CVE-2021-4034 1day. Contribute to berdav/CVE-2021-4034 development by creating an account on GitHub._github.com

polkit/src/programs/pkexec.c at 4c9a813f3fc1ada4fcce508d286e95f965a3002a · wingo/polkit
_Hacks to https://www.freedesktop.org/wiki/Software/polkit/ - polkit/src/programs/pkexec.c at…_github.com

File: gutils.c | Debian Sources
_Edit description_sources.debian.org

iconv(1) - Linux manual page
_This page is part of the Linux man-pages 6.15 2025-06-11 man-pages (Linux kernel and C library user-space interface…_man7.org