A secret too large for the locked-memory limit fails with an error, not a panic (closes #145)
check / check (push) Canceled after 0s

secret add, import and generate secret crashed with memguard's panic once a
value outgrew the locked-memory limit, and because the value was held twice,
half the usual 8 MiB limit was enough. secret now raises the limit to the hard
limit at startup. The value is read a page at a time into a memguard.Stream,
which keeps it encrypted, then copied once into locked memory after its size is
checked against 100 MiB and against the limit less 16 pages for the command's
keys. It comes out of the stream through Next, not Read: Read re-encrypts a
leftover piece, and memguard hangs if that runs out of locked memory.

Judgement call: with a limit of 64 KiB or less, nothing can be stored.

Model: opus-5-5
This commit is contained in:
2026-10-14 21:02:38 +00:00
committed by sneak
parent fe94e99801
commit ef10bdddda
6 changed files with 217 additions and 100 deletions
+11
View File
@@ -18,6 +18,17 @@ https://git.eeqj.de/sneak/secret/milestone/12
# Completed Steps
- 2026-10-14: A secret too large for the locked-memory limit (`ulimit -l`) makes
`secret add`, `secret import` and `secret generate secret` fail with an error
that names the limit, not crash with a panic
(https://git.eeqj.de/sneak/secret/issues/145). memguard panics when it cannot
lock memory, and the value was held twice, so with the usual 8 MiB limit any
value over about 4 MiB crashed. `secret` now raises the limit to the hard
limit at startup. The value is read a page at a time into a `memguard.Stream`,
which keeps it encrypted, and copied once into locked memory only after its
size is checked against 100 MiB and against the limit less 16 pages for the
command's keys. `generate secret` checks the length before it generates
anything.
- 2026-10-14: `secret generate mnemonic`, `secret vault list` and
`secret unlocker list` print their output to stdout, as `secret list` does, so
it can be piped or captured (https://git.eeqj.de/sneak/secret/issues/138).