-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Labels
Description
Describe the bug
The library experiences a deadlock when initialization fails due to insufficient lockable memory (mlock) on memory-constrained systems, particularly Android devices with a 64KB mlock limit. When the system has insufficient lockable memory available and memguard attempts to initialize, a deadlock occurs due to recursive mutex locking in the getOrCreateKey function.
Root Cause
- The getOrCreateKey function acquires a lock on the key mutex
Line 14 in b28f395
keyMtx.Lock() - When memory locking fails (due to mlock limits), an error occurs
Line 74 in b28f395
Panic(err) - The error handling calls a Panic function
- The Panic function attempts to acquire the same key mutex that is already held
Line 22 in b28f395
keyMtx.Lock() - This results in a deadlock, causing the application to freeze
To Reproduce
Steps to reproduce the behaviour:
- Set up an Android environment (or create env in some other way with limited mlock)
- Consume some of the available lockable memory
- Initialize memguard library for the first time (e.g. call memguard.NewEnclave())
- Observe application freeze during initialization
Expected behaviour
Getting crash or error
System (please complete the following information):
- OS and Kernel Versions: Android (64KB mlock limit)
- Memguard Version:
- Go Version: 1.24.0