Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Baron Samedit (CVE-2021-3156) is a heap overflow in sudo that let any local user on an unpatched Linux or macOS system become root, and it had been present for almost ten years.

What Is Sudo Baron Samedit?
Baron Samedit is the name Qualys gave to CVE-2021-3156, a heap buffer overflow in sudo that they disclosed on 26 January 2021. Any unprivileged local user could exploit it to obtain full root privileges, with no password and no entry in the sudoers file required. The bug had been introduced in July 2011 and shipped in every release for nearly a decade.
Because sudo is installed almost everywhere a Unix-like system runs, the advisory turned into one of the larger emergency patching exercises of that year, touching Linux distributions, macOS, and a long list of appliances with sudo embedded in their firmware.
When sudo is invoked with -s or -i, it runs the requested command through a shell. To make that work safely, sudo escapes shell metacharacters in the arguments with backslashes before building the command line, and the function that later consumes that string, set_cmnd(), removes the escaping again.
The two halves disagreed about one case. A command line ending in a single unescaped backslash made the unescaping loop read past the end of the buffer, because it consumed the backslash and then the terminating null byte as the character being escaped, and kept going. The result was a heap overflow with attacker-controlled contents and attacker-controlled length.
Crucially, the escaping step was skipped in sudoedit mode while the unescaping step still ran, which is how an attacker could place that trailing backslash in the first place. Three separate heap-based exploitation strategies were published, targeting the service user struct, the def_timestampdir structure, and the sudoers nss entry, giving reliable root on mainstream distributions.
The flaw affected all legacy versions from 1.8.2 to 1.8.31p2 and all stable versions from 1.9.0 to 1.9.5p1. The fix shipped in sudo 1.9.5p1, and distributions backported it to their own packages within days.
Qualys published a safe check that does not attempt exploitation. As any user, run:
sudoedit -s /
A patched system answers with usage: or sudoedit: /: not a regular file. A vulnerable system answers with a segmentation fault. The same bug was later confirmed on macOS Big Sur, where sudo -s rather than sudoedit was the trigger, and Apple patched it in the 11.2.1 security update.
It is tempting to rank a local flaw below a remote one. In practice, attacks arrive in stages. An attacker who lands a low-privileged shell through a vulnerable web application, a leaked SSH key, or a compromised CI runner needs exactly this kind of bug to turn that foothold into control of the host.
Baron Samedit was particularly convenient for that because it needed no sudo rights at all. A service account such as www-data, deliberately excluded from sudoers, could still use it. That also made it attractive for container escape attempts where sudo was present in the image, and for attacks on shared build servers.
Sudo has produced other serious flaws in the same family, including CVE-2019-14287, where a user permitted to run a command as any user except root could pass the user ID -1 and get root anyway, and CVE-2023-22809, which allowed editing arbitrary files through the EDITOR variable in sudoedit. The pattern is consistent: a small parsing or validation gap in a tool that grants root by design.
sudo --version on every host, including appliances and container base images, not only the servers in your configuration management inventory.ALL or wildcards frequently allow more than their author intended; review them against what each role actually needs, in line with least privilege.dmesg or the audit log are a strong signal that someone is tuning an exploit, since reliable heap grooming usually takes several attempts.The NCSC’s guidance on patch management treats a known-exploited local escalation as urgent precisely because it shortens every intrusion that follows. Our Infrastructure Security Testing Services check for this class of issue across your Linux estate, including the hosts that configuration management has quietly stopped reaching.
Qualys named it after Baron Samedi, a figure from Haitian Vodou associated with the dead, with the spelling adjusted to include the sudoedit command that triggers the bug. Vulnerability nicknames exist mainly to make coordination easier during disclosure; the authoritative identifier is CVE-2021-3156, which you should use when searching vendor advisories and patch notes.
No, and that is what made the flaw unusually dangerous. Exploitation happens during argument parsing, before sudo checks whether the user is authorised to run anything. Any local account, including service accounts such as www-data or a user created by a compromised application, could obtain root on an unpatched system without a password or a sudoers entry.
Run sudoedit -s / as any user. A patched system prints a usage message or reports that the path is not a regular file. A vulnerable system produces a segmentation fault. Checking sudo –version alone can mislead because distributions backport fixes without changing the upstream version number, so the behavioural test is more reliable.
Yes. Researchers confirmed exploitation on macOS Big Sur using sudo -s rather than sudoedit, because macOS ships its own build of the same vulnerable code. Apple addressed it in the macOS 11.2.1, Catalina, and Mojave security updates released in February 2021. Any Mac that has not received security updates since then should be considered exposed.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.