A secret too large for the locked-memory limit fails with an error, not a panic (closes #145)
check / check (push) Waiting to run
check / check (push) Waiting to run
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:
@@ -14,6 +14,8 @@ import (
|
||||
// every memguard buffer before it returns, so the caller must do nothing
|
||||
// but exit with the code.
|
||||
func Entry() int {
|
||||
raiseLockedMemoryLimit()
|
||||
|
||||
// On SIGINT or SIGTERM memguard runs this function, wipes every buffer
|
||||
// and exits with status 1. The passphrase prompt turns terminal echo
|
||||
// off until the read finishes, so a signal there would leave echo off.
|
||||
@@ -38,6 +40,19 @@ func Entry() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// raiseLockedMemoryLimit raises this process's limit on locked memory, which
|
||||
// holds every secret value, to the hard limit, the most a process may set
|
||||
// without privileges. When that fails the limit stays as it was, and
|
||||
// checkLockedMemoryLimit names it in its error.
|
||||
func raiseLockedMemoryLimit() {
|
||||
var limit unix.Rlimit
|
||||
|
||||
if unix.Getrlimit(unix.RLIMIT_MEMLOCK, &limit) == nil {
|
||||
limit.Cur = limit.Max
|
||||
_ = unix.Setrlimit(unix.RLIMIT_MEMLOCK, &limit)
|
||||
}
|
||||
}
|
||||
|
||||
func newRootCmd() *cobra.Command {
|
||||
secret.Debug("newRootCmd starting")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user