pycares
Affected
- introduced
0, fixed4.9.0(ecosystem)
Fixed versions
4.9.0
Fix
- Fixed version
4.9.0pip install --upgrade pycares==4.9.0
Advisory
Also known as: CVE-2025-48945
pycares has a Use-After-Free Vulnerability
Summary
pycares is vulnerable to a use-after-free condition that occurs when a Channel object is garbage collected while DNS queries are still pending. This results in a fatal Python error and interpreter crash.
Details
Root Cause
The vulnerability stems from improper handling of callback references when the Channel object is destroyed:
ffi.new_handle()This issue was much more likely to occur when using event_thread=True but could happen without it under the right circumstances.
Technical Details
The core issue is a race condition between Python's garbage collector and c-ares's callback execution:
__del__ is called from within a c-ares callback context, we cannot immediately call ares_destroy() because c-ares is still executing code after the callback returnsImpact
Applications using pycares can be crashed remotely by triggering DNS queries that result in Channel objects being garbage collected before query completion. This is particularly problematic in scenarios where:
The error manifests as:
Fatal Python error: b_from_handle: ffi.from_handle() detected that the address passed points to garbage
Fix
The vulnerability has been fixed in pycares 4.9.0 by implementing a safe channel destruction mechanism
Mitigation
For Application Developers
# Explicit cleanup
channel.close()
# Or use context manager
with pycares.Channel() as channel:
# ... use channel ...
# Automatically closed
The fix is completely transparent - no API changes or code modifications are required.
Credit
This vulnerability was reported by @vEpiphyte through the aio-libs security program.
Medium Basis: The source's own band: MODERATE
0, fixed 4.9.0 (ecosystem)4.9.0
4.9.0pip install --upgrade pycares==4.9.0Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0