Bug 1881037 (CVE-2020-25637)

Summary: CVE-2020-25637 libvirt: double free in qemuAgentGetInterfaces() in qemu_agent.c
Product: [Other] Security Response Reporter: Mauro Matteo Cascella <mcascell>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: agedosier, berrange, clalancette, eblake, erik-fedora, itamar, jdenemar, jforbes, jsuchane, knoel, laine, libvirt-maint, marcandre.lureau, pkrempa, rjones, security-response-team, veillard, virt-maint, virt-maint, yafu
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt 6.8.0 Doc Type: If docs needed, set a value
Doc Text:
A double free memory issue was found to occur in the libvirt API responsible for requesting information about network interfaces of a running QEMU domain. This flaw affects the polkit access control driver. Specifically, clients connecting to the read-write socket with limited ACL permissions could use this flaw to crash the libvirt daemon, resulting in a denial of service, or potentially escalate their privileges on the system. The highest threat from this vulnerability is to data confidentiality and integrity as well as system availability.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-10 14:21:34 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1881899, 1881900, 1881902, 1881903, 1881904, 1882721, 1883864, 1883865, 1896789, 1910617    
Bug Blocks: 1878876    

Description Mauro Matteo Cascella 2020-09-21 12:18:32 UTC
A double free vulnerability was found in libvirt while requesting information about the network interfaces of a running domain. The flaw lies in qemuAgentGetInterfaces() in qemu/qemu_agent.c. More specifically, this function interacts with the guest agent and receives JSON data from the agent that contains network interface information. It enumerates the interfaces one by one, using a pointer to a pointers to hold a split interface name (ifname). At some point in every iteration ifname is free'd. If an error occurs right after this, there is a 'goto error', the error handler at this label will free ifname again, leading to a double free. Depending on the ability of the attacker to control and shape the heap state when the second free happens, this flaw may be exploited to achieve code execution.

Comment 1 Mauro Matteo Cascella 2020-09-21 12:18:37 UTC
Acknowledgments:

Name: Ilja Van Sprundel (IOActive)

Comment 3 Mauro Matteo Cascella 2020-09-21 13:37:32 UTC
Seems like this flaw was introduced way back in libvirt v1.2.14 with the following commit:
  -> https://libvirt.org/git/?p=libvirt.git;a=commit;h=0977b8aa071de550e1a013d35e2c72615e65d520

As a side note, a recent update in version 6.7.0 replaced virStringListFree (responsible for freeing ifname) with g_strfreev():
  -> https://libvirt.org/git/?p=libvirt.git;a=commit;h=ee247e1d3fbfcf8d2aaff9447b79a65910bcf026

This change didn't have any repercussions on the impact of this flaw, though.

Comment 4 Mauro Matteo Cascella 2020-09-21 13:59:40 UTC
Statement:

Red Hat Enterprise Linux 5 and 6 are not affected by this issue as they shipped an older version of `libvirt` which did not include the vulnerable code. This flaw affects versions of the `libvirt` package as shipped with Red Hat Enterprise Linux 7 and 8 as well as Red Hat Enterprise Linux Advanced Virtualization 8. Future `libvirt` package updates for these products may address this issue.

Comment 7 Mauro Matteo Cascella 2020-09-28 08:17:42 UTC
The check in virDomainInterfaceAddresses() in libvirt-domain.c prevents read-only clients from exploiting this flaw:

```
if (source == VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT)
    virCheckReadOnlyGoto(dom->conn->flags, error);
```

This issue mostly involves a security boundary violation in the polkit access control driver: https://libvirt.org/aclpolkit.html.
Specifically, clients connecting to the read-write socket with limited ACL permissions (i.e., read-only) could use this flaw to crash the libvirt daemon, resulting in a denial of service, or potentially escalate their privileges on the system.

Comment 9 Mauro Matteo Cascella 2020-09-30 12:30:06 UTC
Created libvirt tracking bugs for this issue:

Affects: fedora-all [bug 1883864]


Created mingw-libvirt tracking bugs for this issue:

Affects: fedora-all [bug 1883865]

Comment 12 errata-xmlrpc 2020-11-10 13:13:37 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 7

Via RHSA-2020:5040 https://access.redhat.com/errata/RHSA-2020:5040

Comment 13 Product Security DevOps Team 2020-11-10 14:21:34 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):

https://access.redhat.com/security/cve/cve-2020-25637

Comment 14 errata-xmlrpc 2020-11-16 09:10:02 UTC
This issue has been addressed in the following products:

  Advanced Virtualization for RHEL 8.2.1

Via RHSA-2020:5111 https://access.redhat.com/errata/RHSA-2020:5111

Comment 16 errata-xmlrpc 2021-05-18 14:51:05 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2021:1762 https://access.redhat.com/errata/RHSA-2021:1762