CWE-591: Sensitive Data Storage in Improperly Locked Memory
The product stores sensitive data in memory that is not locked, or that has been incorrectly locked, which might cause the memory to be written to swap files on disk by the virtual memory manager. This can make the data more accessible to external actors.
How it's found
Sensitive Data Storage in Improperly Locked Memory is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
On Windows systems the VirtualLock function can lock a page of memory to ensure that it will remain present in memory and not be swapped to disk. However, on older versions of Windows, such as 95, 98, or Me, the VirtualLock() function is only a stub and provides no protection. On POSIX systems the mlock() call ensures that a page will stay resident in memory but does not guarantee that the page will not appear in the swap. Therefore, it is unsuitable for use as a protection mechanism for sensitive data. Some platforms, in particular Linux, do make the guarantee that the page will not be swapped, but this is non-standard and is not portable. Calls to mlock() also require supervisor privilege. Return values for both of these calls must be checked to ensure that the lock operation was actually successful.
Consequences
- Read Application Data, Read Memory: Sensitive data that is written to a swap file may be exposed.
Mitigations
- Architecture and Design: Identify data that needs to be protected from swapping and choose platform-appropriate protection mechanisms.
- Implementation: Check return values to ensure locking operations are successful.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-591?
The product stores sensitive data in memory that is not locked, or that has been incorrectly locked, which might cause the memory to be written to swap files on disk by the virtual memory manager. This can make the data more accessible to external actors.
How do you find Sensitive Data Storage in Improperly Locked Memory?
Sensitive Data Storage in Improperly Locked Memory is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-591?
Read Application Data, Read Memory: Sensitive data that is written to a swap file may be exposed.
Does TurboPentest test for Sensitive Data Storage in Improperly Locked Memory?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
- Base weaknessCWE-413: Improper Resource Locking
- Variant weaknessCWE-14: Compiler Removal of Code to Clear Buffers
- Base weaknessCWE-261: Weak Encoding for Password
- Class weaknessCWE-311: Missing Encryption of Sensitive Data
- Variant weaknessCWE-321: Use of Hard-coded Cryptographic Key
- Class weaknessCWE-326: Inadequate Encryption Strength
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a pentest