Review found a stack-buffer-overflow in scr_openssh_load: the public blob length came straight from the file and was memcpy'd into struct scr_priv's 4096-byte field. A crafted RSA key file (the ed25519 path cross-checks first) overwrote the stack: ASan reported a 6000-byte write. Also reject p or q <= 1 before BN_mod, arm the temp-file cleanup before the write rather than after, clear the active flag on the conversion-failure path, and block INT/TERM/HUP across ssh-keygen so a signalled child cannot rename a fresh copy back after the handler unlinked it. The new case crafts an oversized blob and asserts a clean exit 1, not a crash.
This commit is contained in:
1 parent
abdac42c83
commit
6851364ccb
4 files changed
+75
-11
No files matched your search
@@ -120,6 +120,8 @@ static EVP_PKEY *rsa_from_parts(const unsigned char *nb, size_t nl,
|
||||
goto done;
|
||||
if (!BN_sub_word(pm1, 1) || !BN_sub_word(qm1, 1))
|
||||
goto done;
|
||||
if (BN_is_zero(pm1) || BN_is_zero(qm1))
|
||||
goto done;
|
||||
if (!BN_mod(dp, d, pm1, ctx) || !BN_mod(dq, d, qm1, ctx))
|
||||
goto done;
|
||||
|
||||
@@ -273,6 +275,11 @@ int scr_openssh_load(const unsigned char *text, size_t n, struct scr_priv *out)
|
||||
"supported\n", nkeys);
|
||||
goto done;
|
||||
}
|
||||
if (publ == 0 || publ > sizeof out->blob) {
|
||||
fprintf(stderr, "sshcrypt: the public key blob is %zu bytes; the "
|
||||
"limit is %zu\n", publ, sizeof out->blob);
|
||||
goto done;
|
||||
}
|
||||
if (parse_private(priv, privl, pub, publ, out) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
Reference in new issue
Block a user