1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00

pem: cap accepted KDF rounds in pem_parse_data_openssh()

To 1^20, which ensures the function does complete eventually.

The limit mirrors the one introduced in OpenSSH 10.6. (Release Notes
say 1M, the actual patch uses 1^20; we go with the latter.)

Refs:
https://www.openssh.org/txt/release-10.6
f938c78d49
OpenBSD-Commit-ID: 843ff37b066b2879f4579a784e42a3c9d22b2ddc

Reported-by: QcN3ep
Fixes GHSA-vc97-vgww-qggv

Closes #2657
This commit is contained in:
Viktor Szakats
2026-10-06 18:00:50 +02:00
parent 826fdb283d
commit 5d27ee28ed

View File

@@ -383,6 +383,8 @@ out:
#define OPENSSH_PRIVKEY_FOOTER "-----END OPENSSH PRIVATE KEY-----"
#define OPENSSH_PRIVKEY_AUTH_MAGIC "openssh-key-v1"
#define SSH2_KDF_ROUNDS_MAX (1 << 20)
static int pem_parse_data_openssh(LIBSSH2_SESSION *session,
const char *passphrase,
const char *b64data, size_t b64datalen,
@@ -546,6 +548,12 @@ static int pem_parse_data_openssh(LIBSSH2_SESSION *session,
goto out;
}
if(rounds > SSH2_KDF_ROUNDS_MAX) {
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
"Too many KDF rounds");
goto out;
}
if(ssh2_bcrypt_pbkdf(passphrase, strlen(passphrase),
salt, salt_len, key,
keylen + ivlen, rounds) < 0) {