CVE-2017-11368: Reachable Assertion (CWE-617)
value: In MIT Kerberos 5 (aka krb5) 1.7 and later, an authenticated attacker can cause a KDC assertion failure by sending invalid S4U2Self or S4U2Proxy requests.
CWE description: The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.
CVSS v3 base score: 6.5
Published: 2017-08-09T18:29Z
Repository: https://github.com/krb5/krb5
Language: C
Files changed: src/kdc/do_as_req.c, src/kdc/do_tgs_req.c, src/kdc/kdc_util.c
Commit date: 2017-07-24 10:40:01 -0400
Commit message: Prevent KDC unset status assertion failures

Assign status values if S4U2Self padata fails to decode, if an
S4U2Proxy request uses invalid KDC options, or if an S4U2Proxy request
uses an evidence ticket which does not match the canonicalized request
server principal name.  Reported by Samuel Cabrero.

If a status value is not assigned during KDC processing, default to
"UNKNOWN_REASON" rather than failing an assertion.  This change will
prevent future denial of service bugs due to similar mistakes, and
will allow us to omit assigning status values for unlikely errors such
as small memory allocation failures.

CVE-2017-11368:

In MIT krb5 1.7 and later, an authenticated attacker can cause an
assertion failure in krb5kdc by sending an invalid S4U2Self or
S4U2Proxy request.

  CVSSv3 Vector: AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H/E:H/RL:O/RC:C

ticket: 8599 (new)
target_version: 1.15-next
target_version: 1.14-next
tags: pullup

Diff: diff --git a/src/kdc/do_as_req.c b/src/kdc/do_as_req.c
index 2d3ad134d0b..9b256c87646 100644
--- a/src/kdc/do_as_req.c
+++ b/src/kdc/do_as_req.c
@@ -364,12 +364,12 @@ finish_process_as_req(struct as_req_state *state, krb5_error_code errcode)
                state->request, &state->reply, state->client, state->cname,
                state->server, state->sname, state->authtime, 0, 0, 0);
     did_log = 1;
 
 egress:
-    if (errcode != 0)
-        assert (state->status != 0);
+    if (errcode != 0 && state->status == NULL)
+        state->status = "UNKNOWN_REASON";
 
     au_state->status = state->status;
     au_state->reply = &state->reply;
     kau_as_req(kdc_context,
               (errcode || state->preauth_err) ? FALSE : TRUE, au_state);
diff --git a/src/kdc/do_tgs_req.c b/src/kdc/do_tgs_req.c
index cdc79ad2f1b..d8d67199b9d 100644
--- a/src/kdc/do_tgs_req.c
+++ b/src/kdc/do_tgs_req.c
@@ -821,11 +821,12 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt,
     memset(reply.enc_part.ciphertext.data, 0,
            reply.enc_part.ciphertext.length);
     free(reply.enc_part.ciphertext.data);
 
 cleanup:
-    assert(status != NULL);
+    if (status == NULL)
+        status = "UNKNOWN_REASON";
     if (reply_key)
         krb5_free_keyblock(kdc_context, reply_key);
     if (errcode)
         emsg = krb5_get_error_message (kdc_context, errcode);
 
diff --git a/src/kdc/kdc_util.c b/src/kdc/kdc_util.c
index 778a629e52a..b710aefe4c7 100644
--- a/src/kdc/kdc_util.c
+++ b/src/kdc/kdc_util.c
@@ -1218,12 +1218,14 @@ kdc_process_for_user(kdc_realm_t *kdc_active_realm,
 
     req_data.length = pa_data->length;
     req_data.data = (char *)pa_data->contents;
 
     code = decode_krb5_pa_for_user(&req_data, &for_user);
-    if (code)
+    if (code) {
+        *status = "DECODE_PA_FOR_USER";
         return code;
+    }
 
     code = verify_for_user_checksum(kdc_context, tgs_session, for_user);
     if (code) {
         *status = "INVALID_S4U2SELF_CHECKSUM";
         krb5_free_pa_for_user(kdc_context, for_user);
@@ -1318,12 +1320,14 @@ kdc_process_s4u_x509_user(krb5_context context,
 
     req_data.length = pa_data->length;
     req_data.data = (char *)pa_data->contents;
 
     code = decode_krb5_pa_s4u_x509_user(&req_data, s4u_x509_user);
-    if (code)
+    if (code) {
+        *status = "DECODE_PA_S4U_X509_USER";
         return code;
+    }
 
     code = verify_s4u_x509_user_checksum(context,
                                          tgs_subkey ? tgs_subkey :
                                          tgs_session,
                                          &req_data,
@@ -1622,17 +1626,19 @@ kdc_process_s4u2proxy_req(kdc_realm_t *kdc_active_realm,
      * Constrained delegation is mutually exclusive with renew/forward/etc.
      * We can assert from this check that the header ticket was a TGT, as
      * that is validated previously in validate_tgs_request().
      */
     if (request->kdc_options & (NON_TGT_OPTION | KDC_OPT_ENC_TKT_IN_SKEY)) {
+        *status = "INVALID_S4U2PROXY_OPTIONS";
         return KRB5KDC_ERR_BADOPTION;
     }
 
     /* Ensure that evidence ticket server matches TGT client */
     if (!krb5_principal_compare(kdc_context,
                                 server->princ, /* after canon */
                                 server_princ)) {
+        *status = "EVIDENCE_TICKET_MISMATCH";
         return KRB5KDC_ERR_SERVER_NOMATCH;
     }
 
     if (!isflagset(t2enc->flags, TKT_FLG_FORWARDABLE)) {
         *status = "EVIDENCE_TKT_NOT_FORWARDABLE";

Vulnerable code:     if (errcode != 0)
        assert (state->status != 0);
    assert(status != NULL);
    if (code)
    if (code)
Fixed code:     if (errcode != 0 && state->status == NULL)
        state->status = "UNKNOWN_REASON";
    if (status == NULL)
        status = "UNKNOWN_REASON";
    if (code) {
        *status = "DECODE_PA_FOR_USER";
    }
    if (code) {
        *status = "DECODE_PA_S4U_X509_USER";
    }
        *status = "INVALID_S4U2PROXY_OPTIONS";
        *status = "EVIDENCE_TICKET_MISMATCH";