|
| 1 | +Origin: upstream, https://github.com/openssh/openssh-portable/commit/5d04ca6af739b82fd30d84d2783ca802ebfa1192 |
| 2 | +Backport notes: |
| 3 | +- Only the "version identifier/RCS ID" in the header has been updated |
| 4 | + to reflect our current base file. |
| 5 | + |
| 6 | +From 5d04ca6af739b82fd30d84d2783ca802ebfa1192 Mon Sep 17 00:00:00 2001 |
| 7 | +From: "djm@openbsd.org" <djm@openbsd.org> |
| 8 | +Date: Mon, 6 Jul 2026 07:53:30 +0000 |
| 9 | +Subject: [PATCH] upstream: Fix multiple RFC 4462 (GSSAPIAuthentication) |
| 10 | + compliance |
| 11 | + |
| 12 | +problems |
| 13 | + |
| 14 | +1) Remove an early failure return for GSSAPI authentication attempts |
| 15 | +made for invalid accounts that yielded different behaviour for |
| 16 | +valid vs invalid accounts. |
| 17 | + |
| 18 | +2) Fix a situation where some GSSAPI requestes were not correctly |
| 19 | +subjected to MaxAuthTries. |
| 20 | + |
| 21 | +3) Fix a moderate pre-authentication resource DoS related to #2. |
| 22 | + |
| 23 | +Add missing logging for error cases. |
| 24 | + |
| 25 | +Report and fixes from Manfred Kaiser, milCERT AT |
| 26 | + |
| 27 | +OpenBSD-Commit-ID: ca0acdd64eea435d6f89534538a9eb404a5629d3 |
| 28 | +Backported-by: Lucas Ravagnier <lucas.ravagnier@vates.tech> |
| 29 | +--- |
| 30 | + auth2-gss.c | 53 ++++++++++++++++++++++++----------------------------- |
| 31 | + 1 file changed, 24 insertions(+), 29 deletions(-) |
| 32 | + |
| 33 | +diff --git a/auth2-gss.c b/auth2-gss.c |
| 34 | +index 901ba52..9c25ab2 100644 |
| 35 | +--- a/auth2-gss.c |
| 36 | ++++ b/auth2-gss.c |
| 37 | +@@ -154,12 +154,6 @@ userauth_gssapi(struct ssh *ssh, const char *method) |
| 38 | + return (0); |
| 39 | + } |
| 40 | + |
| 41 | +- if (!authctxt->valid || authctxt->user == NULL) { |
| 42 | +- debug2_f("disabled because of invalid user"); |
| 43 | +- free(doid); |
| 44 | +- return (0); |
| 45 | +- } |
| 46 | +- |
| 47 | + if (GSS_ERROR(mm_ssh_gssapi_server_ctx(&ctxt, &goid))) { |
| 48 | + if (ctxt != NULL) |
| 49 | + ssh_gssapi_delete_ctx(&ctxt); |
| 50 | +@@ -221,8 +215,14 @@ input_gssapi_token(int type, u_int32_t plen, struct ssh *ssh) |
| 51 | + (r = sshpkt_send(ssh)) != 0) |
| 52 | + fatal_fr(r, "send ERRTOK packet"); |
| 53 | + } |
| 54 | ++ logit("Failed gssapi-with-mic for %s%.100s " |
| 55 | ++ "from %.200s port %d ssh2", |
| 56 | ++ authctxt->valid ? "" : "invalid user ", |
| 57 | ++ authctxt->user, |
| 58 | ++ ssh_remote_ipaddr(ssh), ssh_remote_port(ssh)); |
| 59 | + authctxt->postponed = 0; |
| 60 | + ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 61 | ++ ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL); |
| 62 | + userauth_finish(ssh, 0, "gssapi-with-mic", NULL); |
| 63 | + } else { |
| 64 | + if (send_tok.length != 0) { |
| 65 | +@@ -234,14 +234,18 @@ input_gssapi_token(int type, u_int32_t plen, struct ssh *ssh) |
| 66 | + fatal_fr(r, "send TOKEN packet"); |
| 67 | + } |
| 68 | + if (maj_status == GSS_S_COMPLETE) { |
| 69 | +- ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 70 | +- if (flags & GSS_C_INTEG_FLAG) |
| 71 | +- ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_MIC, |
| 72 | ++ ssh_dispatch_set(ssh, |
| 73 | ++ SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 74 | ++ /* note: keep ERRTOK handler as per RFC 4462 s3.4 */ |
| 75 | ++ if (flags & GSS_C_INTEG_FLAG) { |
| 76 | ++ ssh_dispatch_set(ssh, |
| 77 | ++ SSH2_MSG_USERAUTH_GSSAPI_MIC, |
| 78 | + &input_gssapi_mic); |
| 79 | +- else |
| 80 | ++ } else { |
| 81 | + ssh_dispatch_set(ssh, |
| 82 | + SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, |
| 83 | + &input_gssapi_exchange_complete); |
| 84 | ++ } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | +@@ -253,10 +257,6 @@ static int |
| 89 | + input_gssapi_errtok(int type, u_int32_t plen, struct ssh *ssh) |
| 90 | + { |
| 91 | + Authctxt *authctxt = ssh->authctxt; |
| 92 | +- Gssctxt *gssctxt; |
| 93 | +- gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; |
| 94 | +- gss_buffer_desc recv_tok; |
| 95 | +- OM_uint32 maj_status; |
| 96 | + int r; |
| 97 | + u_char *p; |
| 98 | + size_t len; |
| 99 | +@@ -264,26 +264,21 @@ input_gssapi_errtok(int type, u_int32_t plen, struct ssh *ssh) |
| 100 | + if (authctxt == NULL) |
| 101 | + fatal("No authentication or GSSAPI context"); |
| 102 | + |
| 103 | +- gssctxt = authctxt->methoddata; |
| 104 | +- if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 || |
| 105 | ++ /* Minimal error handling - just cancel auth and return FAILURE */ |
| 106 | ++ if ((r = sshpkt_get_string_direct(ssh, NULL, NULL)) != 0 || |
| 107 | + (r = sshpkt_get_end(ssh)) != 0) |
| 108 | + fatal_fr(r, "parse packet"); |
| 109 | +- recv_tok.value = p; |
| 110 | +- recv_tok.length = len; |
| 111 | +- |
| 112 | +- /* Push the error token into GSSAPI to see what it says */ |
| 113 | +- maj_status = mm_ssh_gssapi_accept_ctx(gssctxt, &recv_tok, |
| 114 | +- &send_tok, NULL); |
| 115 | +- |
| 116 | +- free(recv_tok.value); |
| 117 | + |
| 118 | +- /* We can't return anything to the client, even if we wanted to */ |
| 119 | ++ logit("Failed gssapi-with-mic for %s%.100s from %.200s port %d ssh2", |
| 120 | ++ authctxt->valid ? "" : "invalid user ", |
| 121 | ++ authctxt->user, |
| 122 | ++ ssh_remote_ipaddr(ssh), ssh_remote_port(ssh)); |
| 123 | ++ authctxt->postponed = 0; |
| 124 | + ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 125 | + ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL); |
| 126 | +- |
| 127 | +- /* The client will have already moved on to the next auth */ |
| 128 | +- |
| 129 | +- gss_release_buffer(&maj_status, &send_tok); |
| 130 | ++ ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_MIC, NULL); |
| 131 | ++ ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL); |
| 132 | ++ userauth_finish(ssh, 0, "gssapi-with-mic", NULL); |
| 133 | + return 0; |
| 134 | + } |
| 135 | + |
| 136 | +-- |
| 137 | +2.54.0 |
| 138 | + |
0 commit comments