CVE-2025-21785 - Out-of-bounds Write

Severity

78%

Complexity

18%

Confidentiality

98%

In the Linux kernel, the following vulnerability has been resolved: arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array The loop that detects/populates cache information already has a bounds check on the array size but does not account for cache levels with separate data/instructions cache. Fix this by incrementing the index for any populated leaf (instead of any populated level).

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 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 3 months ago

2025-02-27 03:15:00

Last updated 2 months ago

2025-03-13 13:15:00

Affected Software

Linux Kernel

References

https://git.kernel.org/stable/c/4ff25f0b18d1d0174c105e4620428bcdc1213860

https://git.kernel.org/stable/c/67b99a2b5811df4294c2ad50f9bff3b6a08bd618

https://git.kernel.org/stable/c/715eb1af64779e1b1aa0a7b2ffb81414d9f708e5

https://git.kernel.org/stable/c/875d742cf5327c93cba1f11e12b08d3cce7a88d2

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

https://git.kernel.org/stable/c/4ff25f0b18d1d0174c105e4620428bcdc1213860

Patch, Mailing List

https://git.kernel.org/stable/c/67b99a2b5811df4294c2ad50f9bff3b6a08bd618

Patch, Mailing List

https://git.kernel.org/stable/c/715eb1af64779e1b1aa0a7b2ffb81414d9f708e5

Patch, Mailing List

https://git.kernel.org/stable/c/875d742cf5327c93cba1f11e12b08d3cce7a88d2

Patch, Mailing List

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

Patch, Mailing List

https://git.kernel.org/stable/c/4371ac7b494e933fffee2bd6265d18d73c4f05aa

https://git.kernel.org/stable/c/4ff25f0b18d1d0174c105e4620428bcdc1213860

Mailing List, Patch

https://git.kernel.org/stable/c/67b99a2b5811df4294c2ad50f9bff3b6a08bd618

Mailing List, Patch

https://git.kernel.org/stable/c/715eb1af64779e1b1aa0a7b2ffb81414d9f708e5

Mailing List, Patch

https://git.kernel.org/stable/c/875d742cf5327c93cba1f11e12b08d3cce7a88d2

Mailing List, Patch

https://git.kernel.org/stable/c/88a3e6afaf002250220793df99404977d343db14

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

Mailing List, Patch

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

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.