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. Each of the three commands refuses, before its first locked allocation, a limit that leaves fewer than 8 pages for its keys and buffers. The value is read a page at a time into a memguard.Stream, which keeps it encrypted, and copied once into locked memory after its size is checked against 100 MiB and the limit. It leaves the stream through Next, not Read: Read re-encrypts a leftover piece, and memguard hangs if that runs out of locked memory. Model: opus-5-5
This commit is contained in:
@@ -72,6 +72,12 @@ func newGenerateSecretCmd() *cobra.Command {
|
||||
return fmt.Errorf("failed to initialize CLI: %w", err)
|
||||
}
|
||||
|
||||
// Before readSecretEnv, which makes the first locked allocation
|
||||
err = checkLockedMemoryLimit(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
destroySecrets := cli.readSecretEnv()
|
||||
defer destroySecrets()
|
||||
|
||||
@@ -133,10 +139,16 @@ func (cli *Instance) GenerateSecret(
|
||||
return errLengthTooSmall
|
||||
}
|
||||
|
||||
var (
|
||||
secretValue string
|
||||
err error
|
||||
)
|
||||
if length > maxSecretSize {
|
||||
return errSecretTooLarge
|
||||
}
|
||||
|
||||
err := checkLockedMemoryLimit(length)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var secretValue string
|
||||
|
||||
switch secretType {
|
||||
case "base58":
|
||||
|
||||
Reference in New Issue
Block a user