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 package | Versions | Reported by |
|---|---|---|
| Unspecified product | n/a | CVE List |
| derive-com-impl (crates.io) | before 0.1.2, all versions, from 0.0.0-0 before 0.1.2 | GitHub Advisory Database, RustSec Advisory Database |
| derive-com-impl_project derive-com-impl | before 0.1.2 | NVD |
All scores
| GitHub | medium rating | |
| GitHub | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| NVD | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| NVD | 5.0medium CVSS:2.0 | AV: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
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-45681 changed 2024-08-04 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-9rg7-3j4f-cf4x changed 2023-11-08 | CC-BY-4.0 |
| GitHub Advisory Database | GHSA-w4cc-pc2h-whcj changed 2023-11-08 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2021-0083 changed 2023-11-08 | CC0-1.0 |
| NVD | CVE-2021-45681 changed 2026-06-17 | Public domain |