CVE-2025-21687 - Out-of-bounds Read

Severity

78%

Complexity

18%

Confidentiality

98%

In the Linux kernel, the following vulnerability has been resolved: vfio/platform: check the bounds of read/write syscalls count and offset are passed from user space and not checked, only offset is capped to 40 bits, which can be used to read/write out of bounds of the device.

CVSS 3.1 Base Score 7.8. CVSS Attack Vector: local. CVSS Attack Complexity: low. CVSS Vector: (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Demo Examples

Out-of-bounds Read

CWE-125

In the following code, the method retrieves a value from an array at a specific array index location that is given as an input parameter to the method


               
}
return value;// check that the array index is less than the maximum// length of the array
value = array[index];// get the value at the specified index of the array
// if array index is invalid then output error message// and return value indicating error
value = -1;

However, this method only verifies that the given array index is less than the maximum length of the array but does not check for the minimum value (CWE-839). This will allow a negative value to be accepted as the input array index, which will result in a out of bounds read (CWE-125) and may allow access to sensitive memory. The input array index should be checked to verify that is within the maximum and minimum range required for the array (CWE-129). In this example the if statement should be modified to include a minimum range check, as shown below.


               
...// check that the array index is within the correct// range of values for the array

Demo Examples

Out-of-bounds Write

CWE-787

The following code attempts to save four different identification numbers into an array.


               
id_sequence[3] = 456;

Out-of-bounds Write

CWE-787

In the following example, it is possible to request that memcpy move a much larger segment of memory than assumed:


               
}
.../* if chunk info is valid, return the size of usable memory,* else, return -1 to indicate an error*/
...

If returnChunkSize() happens to encounter an error it will return -1. Notice that the return value is not checked before the memcpy operation (CWE-252), so -1 can be passed as the size argument to memcpy() (CWE-805). Because memcpy() assumes that the value is unsigned, it will be interpreted as MAXINT-1 (CWE-195), and therefore will copy far more memory than is likely available to the destination buffer (CWE-787, CWE-788).

Out-of-bounds Write

CWE-787

This example takes an IP address from a user, verifies that it is well formed and then looks up the hostname and copies it into a buffer.


               
}
strcpy(hostname, hp->h_name);/*routine that ensures user_supplied_addr is in the right format for conversion */

This function allocates a buffer of 64 bytes to store the hostname, however there is no guarantee that the hostname will not be larger than 64 bytes. If an attacker specifies an address which resolves to a very large hostname, then we may overwrite sensitive data or even relinquish control flow to the attacker.

Note that this example also contains an unchecked return value (CWE-252) that can lead to a NULL pointer dereference (CWE-476).

Out-of-bounds Write

CWE-787

This example applies an encoding procedure to an input string and stores it into a buffer.


               
}
return dst_buf;
die("user string too long, die evil hacker!");
else dst_buf[dst_index++] = user_supplied_string[i];
dst_buf[dst_index++] = ';';
/* encode to < */

The programmer attempts to encode the ampersand character in the user-controlled string, however the length of the string is validated before the encoding procedure is applied. Furthermore, the programmer assumes encoding expansion will only expand a given character by a factor of 4, while the encoding of the ampersand expands by 5. As a result, when the encoding procedure expands the string it is possible to overflow the destination buffer if the attacker provides a string of many ampersands.

Out-of-bounds Write

CWE-787

In the following C/C++ example, a utility function is used to trim trailing whitespace from a character string. The function copies the input string to a local character string and uses a while statement to remove the trailing whitespace by moving backward through the string and overwriting whitespace with a NUL character.


               
}
return retMessage;// copy input string to a temporary string
message[index] = strMessage[index];
// trim trailing whitespace
len--;
// return string without trailing whitespace

However, this function can cause a buffer underwrite if the input character string contains all whitespace. On some systems the while statement will move backwards past the beginning of a character string and will call the isspace() function on an address outside of the bounds of the local buffer.

Out-of-bounds Write

CWE-787

The following is an example of code that may result in a buffer underwrite, if find() returns a negative value to indicate that ch is not found in srcBuf:


               
}
...

If the index to srcBuf is somehow under user control, this is an arbitrary write-what-where condition.

Overview

First reported 1 week ago

2025-02-10 16:15:00

Last updated 1 day ago

2025-02-21 16:49:00

Affected Software

Linux Kernel

References

https://git.kernel.org/stable/c/665cfd1083866f87301bbd232cb8ba48dcf4acce

https://git.kernel.org/stable/c/6bcb8a5b70b80143db9bf12dfa7d53636f824d53

https://git.kernel.org/stable/c/92340e6c5122d823ad064984ef7513eba9204048

https://git.kernel.org/stable/c/a20fcaa230f7472456d12cf761ed13938e320ac3

https://git.kernel.org/stable/c/c981c32c38af80737a2fedc16e270546d139ccdd

https://git.kernel.org/stable/c/ce9ff21ea89d191e477a02ad7eabf4f996b80a69

https://git.kernel.org/stable/c/d19a8650fd3d7aed8d1af1d9a77f979a8430eba1

https://git.kernel.org/stable/c/f21636f24b6786c8b13f1af4319fa75ffcf17f38

https://git.kernel.org/stable/c/03844b1908114680ca35fa0a0aba3d906a6d78af

https://git.kernel.org/stable/c/198090eb6f5f094cf3a268c3c30ef1e9c84a6dbe

https://git.kernel.org/stable/c/61ba518195d61c38c6cb86f83135e51f93735442

https://git.kernel.org/stable/c/1485932496a1b025235af8aa1e21988d6b7ccd54

Patch

https://git.kernel.org/stable/c/665cfd1083866f87301bbd232cb8ba48dcf4acce

Patch

https://git.kernel.org/stable/c/6bcb8a5b70b80143db9bf12dfa7d53636f824d53

Patch

https://git.kernel.org/stable/c/92340e6c5122d823ad064984ef7513eba9204048

Patch

https://git.kernel.org/stable/c/a20fcaa230f7472456d12cf761ed13938e320ac3

Patch

https://git.kernel.org/stable/c/c981c32c38af80737a2fedc16e270546d139ccdd

Patch

https://git.kernel.org/stable/c/ce9ff21ea89d191e477a02ad7eabf4f996b80a69

Patch

https://git.kernel.org/stable/c/d19a8650fd3d7aed8d1af1d9a77f979a8430eba1

Patch

https://git.kernel.org/stable/c/f21636f24b6786c8b13f1af4319fa75ffcf17f38

Patch

Stay updated

ExploitPedia is constantly evolving. Sign up to receive a notification when we release additional functionality.

Get in touch

If you'd like to report a bug or have any suggestions for improvements then please do get in touch with us using this form. We will get back to you as soon as we can.