CVE-2022-49771

Source
https://cve.org/CVERecord?id=CVE-2022-49771
Import Source
https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49771.json
JSON Data
https://api.test.osv.dev/v1/vulns/CVE-2022-49771
Downstream
Related
Published
2025-05-01T14:09:08.813Z
Modified
2026-03-20T11:47:14.029699Z
Summary
dm ioctl: fix misbehavior if list_versions races with module loading
Details

In the Linux kernel, the following vulnerability has been resolved:

dm ioctl: fix misbehavior if list_versions races with module loading

__listversions will first estimate the required space using the "dmtargetiterate(listversiongetneeded, &needed)" call and then will fill the space using the "dmtargetiterate(listversiongetinfo, &iterinfo)" call. Each of these calls locks the targets using the "downread(&lock)" and "upread(&lock)" calls, however between the first and second "dmtargetiterate" there is no lock held and the target modules can be loaded at this point, so the second "dmtargetiterate" call may need more space than what was the first "dmtargetiterate" returned.

The code tries to handle this overflow (see the beginning of listversionget_info), however this handling is incorrect.

The code sets "param->datasize = param->datastart + needed" and "iterinfo.end = (char *)vers+len" - "needed" is the size returned by the first dmtarget_iterate call; "len" is the size of the buffer allocated by userspace.

"len" may be greater than "needed"; in this case, the code will write up to "len" bytes into the buffer, however param->datasize is set to "needed", so it may write data past the param->datasize value. The ioctl interface copies only up to param->data_size into userspace, thus part of the result will be truncated.

Fix this bug by setting "iterinfo.end = (char *)vers + needed;" - this guarantees that the second "dmtargetiterate" call will write only up to the "needed" buffer and it will exit with "DMBUFFERFULLFLAG" if it overflows the "needed" space - in this case, userspace will allocate a larger buffer and retry.

Note that there is also a bug in listversionget_needed - we need to add "strlen(tt->name) + 1" to the needed size, not "strlen(tt->name)".

Database specific
{
    "cna_assigner": "Linux",
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2022/49xxx/CVE-2022-49771.json"
}
References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2
Fixed
0c8d4112df329bf3dfbf27693f918c3b08676538
Fixed
6a818db0d5aecf80d4ba9e10ac153f60adc629ca
Fixed
3a1c35d72dc0b34d1e746ed705790c0f630aa427
Fixed
b545c0e1e4094d4de2bdfe9a3823f9154b0c0005
Fixed
f59f5a269ca5e43c567aca7f1f52500a0186e9b7
Fixed
6ffce7a92ef5c68f7e5d6f4d722c2f96280c064b
Fixed
5398b8e275bf81a2517b327d216c0f37ac9ac5ae
Fixed
4fe1ec995483737f3d2a14c3fe1d8fe634972979

Database specific

source
"https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49771.json"