Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <errno.h>
#include <locale.h>
#include <sodium.h>
#include <stdio.h>
#include <string.h>

const tal_t *wally_tal_ctx = NULL;
secp256k1_context *secp256k1_ctx;
Expand Down Expand Up @@ -100,8 +102,22 @@ 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daemon_setup() already calls err_set_progname(argv0) (via common_setup) before mlock_tal_memory() can run. Did you consider using ccan warn()/warnx() instead of a hand-rolled fprintf + strerror, so the message gets the daemon-name prefix for free and matches the warnx() call in crashdump() that immediately follows it on the same failure path?

if (sodium_mlock((void *)ptr, tal_bytelen(ptr)) != 0) {
fprintf(stderr,
"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\n",
tal_bytelen(ptr), strerror(errno));
abort();
}
tal_add_destructor(ptr, destroy_munlock);
}

Expand Down