CVE-2021-27921

7.5 HIGH

📋 TL;DR

This vulnerability in Pillow (Python Imaging Library) allows attackers to cause denial of service through memory exhaustion by exploiting improper size validation of BLP image containers. Attackers can craft malicious BLP files that trigger excessive memory allocation, potentially crashing affected applications. This affects any system using vulnerable versions of Pillow to process BLP image files.

💻 Affected Systems

Products:
  • Pillow (Python Imaging Library)
Versions: All versions before 8.1.2
Operating Systems: All operating systems running Python with Pillow
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects systems that process BLP image files through Pillow. Other image formats are not vulnerable.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete service outage due to memory exhaustion, potentially leading to system instability or crashes across multiple services using Pillow.

🟠

Likely Case

Application crashes or degraded performance when processing malicious BLP files, affecting image processing functionality.

🟢

If Mitigated

Minimal impact with proper input validation, memory limits, and updated Pillow versions preventing successful exploitation.

🌐 Internet-Facing: MEDIUM - Web applications accepting image uploads could be targeted, but requires specific BLP file format exploitation.
🏢 Internal Only: LOW - Requires attackers to supply malicious BLP files to internal systems, limiting exposure surface.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires supplying a malicious BLP file to vulnerable Pillow instances. No authentication needed if file upload/processing is accessible.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 8.1.2 and later

Vendor Advisory: https://pillow.readthedocs.io/en/stable/releasenotes/8.1.2.html

Restart Required: No

Instructions:

1. Update Pillow using pip: 'pip install --upgrade pillow>=8.1.2' 2. Verify installation: 'pip show pillow' should show version 8.1.2 or higher 3. Test BLP file processing functionality

🔧 Temporary Workarounds

Disable BLP file processing

all

Configure applications to reject or skip BLP image format processing

# Application-specific configuration required

Implement memory limits

linux

Set memory limits on processes using Pillow to contain potential memory exhaustion

ulimit -v [memory_limit_in_kb]  # Linux example
docker run --memory=[limit]  # Container example

🧯 If You Can't Patch

  • Implement strict file type validation to reject BLP files at application boundaries
  • Deploy memory monitoring and alerting for processes using Pillow to detect potential exploitation attempts

🔍 How to Verify

Check if Vulnerable:

Check Pillow version: 'python -c "import PIL; print(PIL.__version__)"' and compare to 8.1.2

Check Version:

python -c "import PIL; print('Pillow version:', PIL.__version__)"

Verify Fix Applied:

Confirm version is 8.1.2 or higher and test processing of legitimate BLP files

📡 Detection & Monitoring

Log Indicators:

  • Memory allocation errors
  • Process crashes when handling image files
  • Unusually large memory consumption by Python processes

Network Indicators:

  • Uploads of BLP files to web applications
  • File transfers containing .blp extensions

SIEM Query:

source="application_logs" AND ("memory allocation failed" OR "Pillow" OR "BLP") AND event_type="error"

🔗 References

📤 Share & Export