common: explain why mlock() failed instead of a bare abort.
What changed, and why it matters
This change only improves the error message shown when the program aborts because it cannot lock secret memory. It does not fix a security vulnerability, change behavior, or remove the abort. The program still crashes, but now tells the operator why and how to grant the needed permission.
No security action required; this is a usability/diagnostics improvement. Operators who previously saw unexplained SIGABRT/SIGSEGV will now get a actionable message.
Security signals we found
diagnostic-only change around memory-locking failure path
abort-on-mlock-failure retained to avoid silently using swappable memory
no cryptographic or memory-safety logic altered
Evidence from the diff
The commit modifies mlock_tal_memory() in common/utils.c to call warnx() with a detailed diagnostic before abort() when sodium_mlock() fails. The abort-on-failure behavior is preserved; only observability is improved. The change adds includes for ccan/err/err.h and string.h and prints the byte count, strerror(errno), and platform-specific remediation hints.
Changed components
common/utils.c:mlock_tal_memory()Inspect captured patch +16 / −1
### common/utils.c
@@ -1,6 +1,7 @@
#include "config.h"
#include <assert.h>
#include <bitcoin/chainparams.h>
+#include <ccan/err/err.h>
#include <ccan/list/list.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
@@ -11,6 +12,7 @@
#include <errno.h>
#include <locale.h>
#include <sodium.h>
+#include <string.h>
const tal_t *wally_tal_ctx = NULL;
secp256k1_context *secp256k1_ctx;
@@ -100,8 +102,21 @@ static void destroy_munlock(const tal_t *ptr)
void mlock_tal_memory(const tal_t *ptr)
{
- if (sodium_mlock((void *)ptr, tal_bytelen(ptr)) != 0)
+ if (sodium_mlock((void *)ptr, tal_bytelen(ptr)) != 0) {
+ warnx("FATAL: could not lock %zu bytes of sensitive memory"
+ " into RAM: %s\n"
+ "Memory locking is required to keep secrets out of"
+ " swap.\n"
+ "If you are running in a container or jail, the"
+ " privilege must be granted:\n"
+ " FreeBSD jail: set allow.mlock=1 for the jail\n"
+ " Linux: raise RLIMIT_MEMLOCK (ulimit -l), or grant"
+ " the CAP_IPC_LOCK capability\n"
+ " Docker/Podman: --ulimit memlock=-1:-1 or"
+ " --cap-add=IPC_LOCK",
+ tal_bytelen(ptr), strerror(errno));
abort();
+ }
tal_add_destructor(ptr, destroy_munlock);
}
Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.