# CVE-2021-3156 (Baron Samedit): Sudo Heap-Based Buffer Overflow

> A heap-based buffer overflow in Sudo allows local attackers to escalate privileges to root via a crafted command-line argument.

- **Severity:** High 7.8 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Yes, since 6 Apr 2022 (CISA KEV)
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 26 Jan 2021
- **Updated:** 21 Oct 2025
- **Also known as:** ALPINE-CVE-2021-3156, CLSA-2021-1611743864, CLSA-2021-1634925665, DEBIAN-CVE-2021-3156, DLA-2534-1, DSA-4839-1, GHSA-w5vh-2923-gp5c, MGASA-2021-0056, RHSA-2021:0218, RHSA-2021:0219, RHSA-2021:0220, RHSA-2021:0221, RHSA-2021:0222, RHSA-2021:0223, RHSA-2021:0224, RHSA-2021:0225, RHSA-2021:0226, RHSA-2021:0227, SUSE-SU-2021:0928-1, SUSE-SU-2021:1267-1, SUSE-SU-2021:1273-1, SUSE-SU-2021:1274-1, SUSE-SU-2021:1275-1, SUSE-SU-2024:4389-1, UBUNTU-CVE-2021-3156, USN-4705-2, openSUSE-SU-2021:0602-1

## What is CVE-2021-3156?

CVE-2021-3156 (Baron Samedit) is a high-severity memory corruption vulnerability in Debian Debian Linux, published on 26 Jan 2021. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

Sudo before 1.9.5p2 contains an off-by-one error that can result in a heap-based buffer overflow, which allows privilege escalation to root via "sudoedit -s" and a command-line argument that ends with a single backslash character.

Weakness: CWE-193 (Off-by-one Error)

## Which versions are affected by CVE-2021-3156?

It affects 24 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `sudo` | Red Hat:enterprise_linux:7::client | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-debuginfo` | Red Hat:enterprise_linux:7::client | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-devel` | Red Hat:enterprise_linux:7::client | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-debuginfo` | Red Hat:enterprise_linux:7::computenode | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-devel` | Red Hat:enterprise_linux:7::computenode | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo` | Red Hat:enterprise_linux:7::server | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-debuginfo` | Red Hat:enterprise_linux:7::server | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-devel` | Red Hat:enterprise_linux:7::server | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo` | Red Hat:enterprise_linux:7::workstation | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-debuginfo` | Red Hat:enterprise_linux:7::workstation | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo-devel` | Red Hat:enterprise_linux:7::workstation | All versions | 0:1.8.23-10.el7_9.1 |
| `sudo` | Red Hat:enterprise_linux:8::baseos | All versions | 0:1.8.29-6.el8_3.1 |
| `sudo-debuginfo` | Red Hat:enterprise_linux:8::baseos | All versions | 0:1.8.29-6.el8_3.1 |
| `sudo-debugsource` | Red Hat:enterprise_linux:8::baseos | All versions | 0:1.8.29-6.el8_3.1 |
| `sudo` | Red Hat:rhel_aus:7.2::server | All versions | 0:1.8.6p7-17.el7_2.3 |
| `sudo-debuginfo` | Red Hat:rhel_aus:7.2::server | All versions | 0:1.8.6p7-17.el7_2.3 |
| `sudo-devel` | Red Hat:rhel_aus:7.2::server | All versions | 0:1.8.6p7-17.el7_2.3 |
| `sudo` | Red Hat:rhel_aus:7.3::server | All versions | 0:1.8.6p7-23.el7_3.3 |
| `sudo-debuginfo` | Red Hat:rhel_aus:7.3::server | All versions | 0:1.8.6p7-23.el7_3.3 |
| `sudo-devel` | Red Hat:rhel_aus:7.3::server | All versions | 0:1.8.6p7-23.el7_3.3 |
| `sudo` | Red Hat:rhel_aus:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo-debuginfo` | Red Hat:rhel_aus:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo-devel` | Red Hat:rhel_aus:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo` | Red Hat:rhel_e4s:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo-debuginfo` | Red Hat:rhel_e4s:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo-devel` | Red Hat:rhel_e4s:7.4::server | All versions | 0:1.8.19p2-12.el7_4.2 |
| `sudo` | Red Hat:rhel_els:6 | All versions | 0:1.8.6p3-29.el6_10.4 |
| `sudo-debuginfo` | Red Hat:rhel_els:6 | All versions | 0:1.8.6p3-29.el6_10.4 |
| `sudo-devel` | Red Hat:rhel_els:6 | All versions | 0:1.8.6p3-29.el6_10.4 |
| `sudo` | Red Hat:rhel_eus:7.6::computenode | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo-debuginfo` | Red Hat:rhel_eus:7.6::computenode | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo-devel` | Red Hat:rhel_eus:7.6::computenode | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo` | Red Hat:rhel_eus:7.6::server | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo-debuginfo` | Red Hat:rhel_eus:7.6::server | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo-devel` | Red Hat:rhel_eus:7.6::server | All versions | 0:1.8.23-3.el7_6.2 |
| `sudo` | Red Hat:rhel_eus:7.7::computenode | All versions | 0:1.8.23-4.el7_7.3 |
| `sudo-debuginfo` | Red Hat:rhel_eus:7.7::computenode | All versions | 0:1.8.23-4.el7_7.3 |
| `sudo-devel` | Red Hat:rhel_eus:7.7::computenode | All versions | 0:1.8.23-4.el7_7.3 |
| `sudo` | Red Hat:rhel_eus:7.7::server | All versions | 0:1.8.23-4.el7_7.3 |
| `sudo-debuginfo` | Red Hat:rhel_eus:7.7::server | All versions | 0:1.8.23-4.el7_7.3 |

Products: Beyondtrust Privilege Management for Mac, Beyondtrust Privilege Management for Unix\/Linux, Debian Debian Linux, Fedoraproject Fedora, Mcafee Web Gateway, Netapp Active Iq Unified Manager, Netapp Cloud Backup, Netapp Hci Management Node, Netapp Oncommand Unified Manager Core Package, Netapp Ontap Select Deploy Administration Utility, Netapp Ontap Tools, Netapp Solidfire, Oracle Communications Performance Intelligence Center, Oracle Micros Compact Workstation 3 Firmware, Oracle Micros Es400 Firmware, Oracle Micros Kitchen Display System Firmware, Oracle Micros Workstation 5a Firmware, Oracle Micros Workstation 6 Firmware, Oracle Tekelec Platform Distribution, Sudo Project Sudo and 4 more.

## How do I fix CVE-2021-3156?

Apply the vendor's patch. US federal agencies must fix it by 27 Apr 2022.

## Is CVE-2021-3156 being exploited?

Yes. Attackers have exploited CVE-2021-3156 in the wild since at least 6 Apr 2022.

Public exploit code:

- https://github.com/blasty/CVE-2021-3156 (github_poc): https://github.com/blasty/CVE-2021-3156
- Sudo Baron Samedit Exploit (github_poc): https://github.com/worawit/CVE-2021-3156
- PoC for CVE-2021-3156 (sudo heap overflow) (github_poc): https://github.com/stong/CVE-2021-3156
- CVE-2021-3156 - Sudo Baron Samedit (github_poc): https://github.com/LiveOverflow/pwnedit
- CVE-2021-3156非交互式执行命令 (github_poc): https://github.com/Rvn0xsy/CVE-2021-3156-plus
- Root shell PoC for CVE-2021-3156 (github_poc): https://github.com/CptGibbon/CVE-2021-3156

## Other vulnerabilities in Debian Debian Linux

- [CVE-2021-3187](https://insights.sbomify.com/CVE-2021-3187/): Privilege escalation in n/a (high 8.8)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-3156 (Baron Samedit) and fix it if it is affected.

What it is: CVE-2021-3156 (Baron Samedit) is a high-severity memory corruption vulnerability in Debian Debian Linux, published on 26 Jan 2021. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: Yes. Attackers have exploited CVE-2021-3156 in the wild since at least 6 Apr 2022.

Affected product: Debian Debian Linux. No package-level version data is available, so check the vendor advisory linked from the reference page.

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-3156/ (Markdown: https://insights.sbomify.com/CVE-2021-3156/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-3156
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-3156
- OSV: https://osv.dev/vulnerability/CVE-2021-3156

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-3156/
Summaries are generated and may contain mistakes; the official description above is the record.
