PubkeyAuthOptions without max-pk-ok sets max_pubkey_ok=-1, contradicting documented default of 6
Макс
m88202016 at gmail.com
Fri Nov 13 14:10:25 AEDT 2026
Hi,
I believe I've found a discrepancy between the documented default of
max-pk-ok and its behaviour when PubkeyAuthOptions is set without an
explicit max-pk-ok: argument.
sshd_config.5 (v1.412) documents for PubkeyAuthOptions:
The max-pk-ok option takes a numeric argument separated by a colon
character, e.g. "max-pk-ok:4" to specify the number of public key
query attempts are permitted before the attempts are considered
failed authentications that count against MaxAuthTries.
[...]
The default is 6.
However, servconf.c::process_server_config_line_depth() initialises
value2 to -1 and only overwrites it if max-pk-ok: appears:
case sPubkeyAuthOptions:
intptr = &options->pubkey_auth_options;
value = 0;
value2 = -1;
while ((arg = argv_next(&ac, &av)) != NULL) {
...
else if (strncasecmp(arg, "max-pk-ok:", 10) == 0) {
value2 = strtonum(arg + 10, 0, 255, &errstr);
...
}
...
}
if (*activep && options->pubkey_auth_options == -1) {
options->pubkey_auth_options = value;
options->max_pubkey_ok = value2;
}
fill_default_server_options() only restores the documented default when
pubkey_auth_options itself is untouched:
if (options->pubkey_auth_options == -1) {
options->pubkey_auth_options = 0;
options->max_pubkey_ok = DEFAULT_AUTH_FAIL_MAX; /* 6 */
}
Consequently, with e.g.:
PubkeyAuthOptions touch-required
pubkey_auth_options is set, but max_pubkey_ok stays -1. In
auth2-pubkey.c::userauth_pubkey() the check is:
if (authctxt->pk_ok_failures++ < options.max_pubkey_ok)
authctxt->auth_failure_already_counted = 1;
pk_ok_failures is a signed int (auth.h) starting at 0, so
"0 < -1" is false on every iteration. The PK-OK budget becomes zero
instead of the documented 6, and every public key query is counted as
an authentication failure. Clients with multiple keys in ssh-agent
therefore exhaust MaxAuthTries on PK-OK probes before they get a chance
to present the actual signature, ending with "Too many authentication
failures".
Suggested fix (either):
(a) initialise value2 to DEFAULT_AUTH_FAIL_MAX instead of -1, or
(b) after the while loop, add:
if (value2 == -1)
value2 = DEFAULT_AUTH_FAIL_MAX;
Both make the behaviour with PubkeyAuthOptions touch-required match the
documented default of 6.
I have tested this against the current master (servconf.c, auth2-pubkey.c,
sshd_config.5 all still match the analysis above).
Happy to send a patch if that would help.
Regards,
Max
More information about the openssh-unix-dev
mailing list