From 5d27ee28ed8dbfa0846c5b9da65f2d35ea48f7d7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 6 Oct 2026 18:00:50 +0200 Subject: [PATCH] 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 https://github.com/openssh/openssh-portable/commit/f938c78d490cb7556aa8ca1625e9b9bd1f963ed3 OpenBSD-Commit-ID: 843ff37b066b2879f4579a784e42a3c9d22b2ddc Reported-by: QcN3ep Fixes GHSA-vc97-vgww-qggv Closes #2657 --- src/pem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pem.c b/src/pem.c index a3d212fd..18c091b5 100644 --- a/src/pem.c +++ b/src/pem.c @@ -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) {