CVE-2022-48560
Use-after-free vulnerability in heappushpop function in heapq
- CVSS 7.5
- CWE-416 Use After Free
- Memory Corruption
- Local
A use-after-free exists in Python through 3.9 via heappushpop in heapq.
- CVSS base score
- 7.5
- Published
- 2023-08-22
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Memory Corruption
- Subcategory
- Use-After-Free Errors
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Upgrade to Python 3.10.
Vulnerable code sample
import heapq
class Item:
def __init__(self, value):
self.value = value
def __lt__(self, other):
return self.value < other.value
def __gt__(self, other):
return self.value > other.value
def __eq__(self, other):
return self.value == other.value
def __ne__(self, other):
return self.value != other.value
def __le__(self, other):
return self.value <= other.value
def __ge__(self, other):
return self.value >= other.value
def __repr__(self):
return f"Item({self.value})"
items = [Item(i) for i in range(10)]
heap = items.copy()
heapq.heapify(heap)
print(f"Heap: {heap}")
smallest = heapq.heappop(heap)
print(f"Popped: {smallest}")
print(f"Heap: {heap}")
heapq.heappush(heap, smallest)
print(f"Heap: {heap}")
popped = heapq.heappushpop(heap, smallest)
print(f"Pushed and popped: {popped}")
print(f"Heap: {heap}")Patched code sample
import heapq
class Item:
def __init__(self, value):
if not isinstance(value, (int, float)):
raise ValueError("Value must be a number")
self.value = value
def __lt__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value < other.value
def __gt__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value > other.value
def __eq__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value == other.value
def __ne__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value != other.value
def __le__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value <= other.value
def __ge__(self, other):
if not isinstance(other, Item):
raise TypeError("Comparison must be between Item instances")
return self.value >= other.value
def __repr__(self):
return f"Item({self.value})"
items = [Item(i) for i in range(10)]
heap = items.copy()
heapq.heapify(heap)
print(f"Heap: {heap}")
smallest = heapq.heappop(heap)
print(f"Popped: {smallest}")
print(f"Heap: {heap}")
heapq.heappush(heap, smallest)
print(f"Heap: {heap}")
popped = heapq.heappushpop(heap, smallest)
print(f"Pushed and popped: {popped}")
print(f"Heap: {heap}")Cite this entry
@misc{vaitp:cve202248560,
title = {{Use-after-free vulnerability in heappushpop function in heapq}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-48560},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-48560/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
