Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Patch the Linux Sudo Security Hole: Step-by-Step

· 5 min read · Home Security

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you must patch the new Linux sudo security hole as soon as possible. This vulnerability (CVE-2021-3156, nicknamed "Baron Samedit") allows any local user to gain root privileges without a password, even if they're not in the sudoers file. The exploit is trivial to run, and it affects most Linux distributions with sudo versions before 1.9.5p2. Patching is straightforward: update your system's sudo package to the latest version. Below is a practical guide to do that safely, whether you're on Ubuntu, Debian, Fedora, CentOS, or Arch. You'll need root or sudo access to perform the update, and you'll want to verify the fix afterward.

What You'll Need

  • A Linux system with sudo installed (almost all do).
  • Root access or a user account with sudo privileges to run the update commands.
  • An internet connection to download the updated package.
  • Basic comfort with the terminal (you'll run a few commands).

Step-by-Step

  1. Check your current sudo version. Open a terminal and run: sudo --version. Note the version number. If it's 1.9.5p2 or later, you're already patched. If it's older, continue.
  2. Update your package lists. This ensures your system knows about the latest available packages. For Debian/Ubuntu: sudo apt update. For Fedora/RHEL/CentOS: sudo dnf check-update (or yum check-update on older CentOS). For Arch: sudo pacman -Sy.
  3. Upgrade the sudo package. This installs the patched version. On Debian/Ubuntu: sudo apt install --only-upgrade sudo. On Fedora/CentOS: sudo dnf update sudo (or sudo yum update sudo). On Arch: sudo pacman -S sudo.
  4. Verify the new version. Run sudo --version again. Confirm the version is now 1.9.5p2 or newer. If not, your distribution may not have released the patch yet—see Troubleshooting.
  5. Test the vulnerability (optional but recommended). Run the proof-of-concept command: sudoedit -s /. If the system is patched, you'll see an error like "sudoedit: /: not a regular file" or "usage: sudoedit ...". If it's vulnerable, you'll get a root shell (don't do this on a production system without a backup plan). If you get a root shell, your patch failed—immediately exit and recheck.
  6. Reboot if required. Usually not needed, but if your kernel was also updated as part of the package update, a reboot is good practice. You can check with ls /var/run/reboot-required on Debian/Ubuntu.

Common Mistakes

  • Forgetting to update package lists first. If you run apt install sudo without apt update, you might get an older version that's still vulnerable.
  • Assuming the first update fixes everything. Some distributions had multiple sudo updates; ensure you have the latest by checking your distro's security announcements.
  • Running the exploit test carelessly. The test command sudoedit -s / can actually give you a root shell if vulnerable. Only run it if you're prepared to handle that (e.g., on a test machine).
  • Ignoring other affected packages. Sudo is the main one, but some systems also ship a separate sudo-logsrvd package—update that too if it exists.
  • Not checking for custom-compiled sudo. If you compiled sudo from source, the package manager won't update it. You'll need to manually download and compile the patched version from sudo.ws.

Tips

  • Set up automatic security updates. On Ubuntu, enable unattended-upgrades; on Fedora, use dnf-automatic. This prevents future vulnerabilities from lingering.
  • Check your distribution's security feed. Bookmark your distro's security advisories page (e.g., Ubuntu Security Notices, Fedora Security Updates) and check it weekly.
  • If you manage many servers, use a configuration management tool. Ansible, Puppet, or Chef can push the sudo update to all machines at once.
  • Keep a backup of your sudoers file. Before any major sudo update, copy /etc/sudoers to /etc/sudoers.bak just in case.

Troubleshooting

If the update isn't available: Your distribution may not have released the patched package yet. Check your distro's security mailing list or website for a workaround. As a temporary mitigation, you can restrict sudo access to trusted users only, but this does not fully fix the vulnerability—the exploit works even for non-sudo users.

If the update fails to install: Try cleaning the package cache (e.g., sudo apt clean) and retry. If you get dependency errors, run sudo apt -f install to fix broken packages. On Fedora, try sudo dnf distro-sync.

If the version is still old after update: Some distros backport security patches without bumping the version number. Check the package's changelog: apt changelog sudo (Debian/Ubuntu) or dnf changelog sudo (Fedora). Look for a mention of CVE-2021-3156 or "Baron Samedit".

If you accidentally get a root shell during testing: Immediately type exit to leave the shell. Then re-run the update steps. If you still get a root shell, your system is still vulnerable—do not use it for anything sensitive until fixed.

If you can't use sudo at all after the update: This is rare, but if sudo is broken, you'll need to boot into recovery mode or use a live USB to edit /etc/sudoers and restore permissions. Always keep a backup of that file.

Frequently Asked Questions

How do I know if I'm vulnerable?

Run sudo --version. If it's below 1.9.5p2, you're likely vulnerable. Also, run the test command sudoedit -s /—if you get a root shell, you're definitely vulnerable.

Can I patch without rebooting?

Yes, sudo is a user-space program. The new binary takes effect immediately after installation. No reboot is required unless the kernel was also updated.

What does the vulnerability actually do?

It allows a local user to gain root privileges by exploiting a heap-based buffer overflow in sudo's argument parsing. The exploit can be run by any user, even one not listed in sudoers, and doesn't require a password.

Is there a manual workaround if I can't patch right now?

You can temporarily remove sudo's setuid bit with sudo chmod 0755 /usr/bin/sudo, but this will break sudo for all users. A better temporary fix is to restrict sudo to trusted users only, but that doesn't fully fix the vulnerability. Patch as soon as possible.

Does this affect all Linux distributions?

Any distribution with sudo versions before 1.9.5p2 is affected. Most major distros have released patches; check your specific distro's security advisories.

How long does the patch take?

Typically under 5 minutes, including the update and verification. The actual download and install is quick; the verification step is the most important part.