CVE-2021-45681
JSON

7.5high

QueryInterface should call AddRef before returning pointer

Severity
7.5high CVSS:3.1 by NVD
Exploit likelihood
1.09% (higher than 66% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
mitre
Also known as
GHSA-9rg7-3j4f-cf4xGHSA-w4cc-pc2h-whcjRUSTSEC-2021-0083

Description

An issue was discovered in the derive-com-impl crate before 0.1.2 for Rust. An invalid reference (and memory corruption) can occur because AddRef might not be called before returning a pointer.

Affected

Product or packageVersionsReported by
Unspecified productn/aCVE List
derive-com-impl (crates.io)before 0.1.2, all versions, from 0.0.0-0 before 0.1.2GitHub Advisory Database, RustSec Advisory Database
derive-com-impl_project derive-com-implbefore 0.1.2NVD

All scores

GitHubmedium rating
GitHub7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NVD7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NVD5.0medium CVSS:2.0AV:N/AC:L/Au:N/C:N/I:N/A:P

Classification

What each source says

CVE List

An issue was discovered in the derive-com-impl crate before 0.1.2 for Rust. An invalid reference (and memory corruption) can occur because AddRef might not be called before returning a pointer.

GitHub Advisory Database

Affected version of this crate, which is a required dependency in com-impl, provides a faulty implementation of the IUnknown::QueryInterface method.

QueryInterface implementation must call IUnknown::AddRef before returning the pointer, as describe in this documentation: https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(refiid_void)

As it is not incrementing the refcount as expected, the following calls to IUnknown::Release method will cause WMI to drop reference to the interface, and can lead to invalid reference.

This is documented in https://docs.microsoft.com/en-us/windows/win32/learnwin32/managing-the-lifetime-of-an-object#reference-counting

There is no simple workaround, as you can't know how many time QueryInterface will be called. The only way to quick fix this is to use the macro expanded version of the code and modify the QueryInterface method to add the AddRef call yourself.

The issue was corrected in commit 9803f31fbd1717d482d848f041044d061fca6da7.

NVD (es)

Se ha detectado un problema en la crate derive-com-impl versiones anteriores a 0.1.2 para Rust. Puede producirse una referencia no válida (y corrupción de memoria) porque AddRef podría no ser llamado antes de devolver un puntero

References

Sources

SourceRecordLicence
CVE ListCVE-2021-45681 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-9rg7-3j4f-cf4x changed 2023-11-08CC-BY-4.0
GitHub Advisory DatabaseGHSA-w4cc-pc2h-whcj changed 2023-11-08CC-BY-4.0
RustSec Advisory DatabaseRUSTSEC-2021-0083 changed 2023-11-08CC0-1.0
NVDCVE-2021-45681 changed 2026-06-17Public domain