Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2021-20277

CVE-2021-20277: Samba LDAP Denial of Service Vulnerability

CVE-2021-20277 is a denial of service flaw in Samba's libldb where consecutive leading spaces in LDAP attributes cause memory corruption. This article covers the technical details, affected versions, and solutions.

Published:

CVE-2021-20277 Overview

A flaw was found in Samba's libldb library that affects LDAP attribute parsing. When processing LDAP attributes containing multiple, consecutive leading spaces, the parsing logic fails to properly handle boundary conditions, resulting in an out-of-bounds memory write. This memory corruption leads to a crash of the LDAP server process handling the malicious request, causing a denial of service condition.

Critical Impact

Remote attackers can crash Samba LDAP server processes by sending specially crafted LDAP requests with malformed attributes containing consecutive leading spaces, causing system availability disruption.

Affected Products

  • Samba (multiple versions)
  • Debian Linux 9.0 and 10.0
  • Fedora 32, 33, and 34

Discovery Timeline

  • May 12, 2021 - CVE-2021-20277 published to NVD
  • November 21, 2024 - Last updated in NVD database

Technical Details for CVE-2021-20277

Vulnerability Analysis

This vulnerability exists in Samba's libldb library, which provides an LDAP-like database API used by Samba's Active Directory Domain Controller (AD DC) functionality. The flaw is triggered when the library parses LDAP attributes that contain multiple consecutive leading spaces.

The vulnerability is classified as both CWE-125 (Out-of-Bounds Read) and CWE-787 (Out-of-Bounds Write), indicating that the parsing logic can read beyond allocated buffer boundaries and subsequently write to memory locations outside the intended buffer. This memory corruption directly impacts the stability of the LDAP server process.

The attack can be executed remotely over the network without requiring authentication or user interaction, making it particularly concerning for internet-facing Samba deployments acting as domain controllers.

Root Cause

The root cause lies in improper boundary checking within libldb's LDAP attribute parsing routines. When the parser encounters multiple consecutive leading spaces in an attribute value, it miscalculates the buffer boundaries needed for processing. This miscalculation leads to memory operations that extend beyond the allocated buffer, corrupting adjacent memory regions and causing the LDAP server process to crash.

Attack Vector

An attacker can exploit this vulnerability by sending specially crafted LDAP requests to a vulnerable Samba server. The attack requires network access to the LDAP service (typically port 389 or 636 for LDAPS). The malicious request contains LDAP attributes with multiple consecutive leading spaces that trigger the out-of-bounds memory write condition.

The exploitation mechanism involves crafting LDAP bind or search requests with attribute values that begin with several consecutive space characters. When the Samba LDAP server processes these malformed attributes through libldb, the parsing logic fails to correctly handle the whitespace sequence, leading to memory corruption and process termination.

Detection Methods for CVE-2021-20277

Indicators of Compromise

  • Unexpected crashes or restarts of the Samba LDAP server process (samba or smbd)
  • Core dumps or crash logs indicating memory corruption in libldb functions
  • LDAP service unavailability following receipt of unusual LDAP requests
  • Log entries showing malformed LDAP attribute processing errors

Detection Strategies

  • Monitor Samba process stability and implement alerting for unexpected service terminations
  • Analyze LDAP traffic for requests containing attributes with unusual whitespace patterns
  • Implement intrusion detection rules to flag LDAP requests with excessive leading spaces in attribute values
  • Review Samba logs for parsing errors or warnings related to LDAP attribute handling

Monitoring Recommendations

  • Enable verbose logging for Samba LDAP services to capture attribute parsing details
  • Configure system monitoring to track Samba process health and automatic restart events
  • Deploy network-based monitoring for LDAP protocol anomalies targeting Samba servers
  • Implement application crash monitoring with core dump analysis capabilities

How to Mitigate CVE-2021-20277

Immediate Actions Required

  • Update Samba to the latest patched version available for your distribution
  • Review firewall rules to restrict LDAP service access to trusted networks only
  • Implement network segmentation to limit exposure of Samba AD DC services
  • Enable rate limiting on LDAP connections to reduce denial of service impact

Patch Information

Samba has released security patches addressing this vulnerability. System administrators should apply updates through their distribution's package management system. Detailed patch information is available in the Samba Security Advisory.

Distribution-specific advisories:

Workarounds

  • Restrict network access to LDAP services using firewall rules to limit exposure to trusted clients only
  • Implement network-level rate limiting to mitigate the impact of potential denial of service attempts
  • Deploy a Web Application Firewall (WAF) or LDAP proxy that can inspect and filter malformed LDAP requests
  • Consider temporarily disabling LDAP services if they are not critical until patches can be applied
bash
# Example firewall configuration to restrict LDAP access
# Limit LDAP (389) and LDAPS (636) to trusted networks only
iptables -A INPUT -p tcp --dport 389 -s 10.0.0.0/8 -j ACCEPT
iptables -A INPUT -p tcp --dport 389 -j DROP
iptables -A INPUT -p tcp --dport 636 -s 10.0.0.0/8 -j ACCEPT
iptables -A INPUT -p tcp --dport 636 -j DROP

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.