cryptenroll,cryptsetup,shutdown: only call mlockall if we have CAP_IPC_LOCK

Calling mlockall in an unprivileged process most notably had the effect
of making systemd-cryptenroll OOM while trying to open a normal-sized
argon2 keyslot due to it hitting RLIMIT_MEMLOCK.
This commit is contained in:
cyclopentane
2026-01-18 19:15:30 +01:00
committed by Mike Yuan
parent 6b3c289406
commit 465f6a6284
5 changed files with 31 additions and 5 deletions
+3 -3
View File
@@ -401,9 +401,9 @@ int main(int argc, char *argv[]) {
init_watchdog();
/* Lock us into memory */
(void) mlockall(MCL_FUTURE|MCL_ONFAULT);
(void) mlockall(MCL_CURRENT);
/* Lock us into memory. If the first mlockall call fails, don't attempt it again. */
if (safe_mlockall(MCL_FUTURE|MCL_ONFAULT) >= 0)
(void) mlockall(MCL_CURRENT);
/* We need to make mounts private so that we can MS_MOVE in unmount_all(). Kernel does not allow
* MS_MOVE when parent mountpoints have shared propagation. */