b7b64b
From 7d93bda31ce0b4e0e22c6e464c9138800dcf8b1c Mon Sep 17 00:00:00 2001
b7b64b
From: Alexander Bokovoy <abokovoy@redhat.com>
b7b64b
Date: Fri, 26 Nov 2021 11:13:51 +0200
b7b64b
Subject: [PATCH] ipa-kdb: fix requester SID check according to MS-KILE and
b7b64b
 MS-SFU updates
b7b64b
b7b64b
New versions of MS-KILE and MS-SFU after Windows Server November 2021
b7b64b
security updates add PAC_REQUESTER_SID buffer check behavior:
b7b64b
b7b64b
 - PAC_REQUESTER_SID should only be added for TGT requests
b7b64b
b7b64b
 - if PAC_REQUESTER_SID is present, KDC must verify that the cname on
b7b64b
   the ticket resolves to the account with the same SID as the
b7b64b
   PAC_REQUESTER_SID. If it doesn't KDC must respond with
b7b64b
   KDC_ERR_TKT_REVOKED
b7b64b
b7b64b
Change requester SID check to skip exact check for non-local
b7b64b
PAC_REQUESTER_SID but harden to ensure it comes from the trusted domains
b7b64b
we know about.
b7b64b
b7b64b
If requester SID is the same as in PAC, we already do cname vs PAC SID
b7b64b
verification.
b7b64b
b7b64b
With these changes FreeIPA works against Windows Server 2019 with
b7b64b
November 2021 security fixes in cross-realm S4U2Self operations.
b7b64b
b7b64b
Fixes: https://pagure.io/freeipa/issue/9031
b7b64b
b7b64b
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
b7b64b
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
b7b64b
---
b7b64b
 daemons/ipa-kdb/ipa_kdb_mspac.c | 47 ++++++++++++++++++++++++---------
b7b64b
 1 file changed, 34 insertions(+), 13 deletions(-)
b7b64b
b7b64b
diff --git a/daemons/ipa-kdb/ipa_kdb_mspac.c b/daemons/ipa-kdb/ipa_kdb_mspac.c
b7b64b
index 538cfbba9..1b972c167 100644
b7b64b
--- a/daemons/ipa-kdb/ipa_kdb_mspac.c
b7b64b
+++ b/daemons/ipa-kdb/ipa_kdb_mspac.c
b7b64b
@@ -1697,7 +1697,7 @@ static krb5_error_code check_logon_info_consistent(krb5_context context,
b7b64b
                                       "local [%s], PAC [%s]",
b7b64b
                                       dom ? dom : "<failed to display>",
b7b64b
                                       sid ? sid : "<failed to display>");
b7b64b
-            return KRB5KDC_ERR_POLICY;
b7b64b
+            return KRB5KDC_ERR_TGT_REVOKED;
b7b64b
         }
b7b64b
     }
b7b64b
 
b7b64b
@@ -1709,7 +1709,7 @@ static krb5_error_code check_logon_info_consistent(krb5_context context,
b7b64b
     kerr = ipadb_get_principal(context, client_princ, flags, &client_actual);
b7b64b
     if (kerr != 0) {
b7b64b
         krb5_klog_syslog(LOG_ERR, "PAC issue: ipadb_get_principal failed.");
b7b64b
-        return KRB5KDC_ERR_POLICY;
b7b64b
+        return KRB5KDC_ERR_TGT_REVOKED;
b7b64b
     }
b7b64b
 
b7b64b
     ied = (struct ipadb_e_data *)client_actual->e_data;
b7b64b
@@ -1743,7 +1743,7 @@ static krb5_error_code check_logon_info_consistent(krb5_context context,
b7b64b
                                   "local [%s] vs PAC [%s]",
b7b64b
                                   local_sid ? local_sid : "<failed to display>",
b7b64b
                                   pac_sid ? pac_sid : "<failed to display>");
b7b64b
-        kerr = KRB5KDC_ERR_POLICY;
b7b64b
+        kerr = KRB5KDC_ERR_TGT_REVOKED;
b7b64b
         goto done;
b7b64b
     }
b7b64b
 
b7b64b
@@ -2005,22 +2005,43 @@ static krb5_error_code ipadb_check_logon_info(krb5_context context,
b7b64b
     /* Check that requester SID is the same as in the PAC entry */
b7b64b
     if (requester_sid != NULL) {
b7b64b
         struct dom_sid client_sid;
b7b64b
+        bool is_from_trusted_domain = false;
b7b64b
         kerr = ipadb_get_sid_from_pac(tmpctx, info.info, &client_sid);
b7b64b
         if (kerr) {
b7b64b
             goto done;
b7b64b
         }
b7b64b
         result = dom_sid_check(&client_sid, requester_sid, true);
b7b64b
         if (!result) {
b7b64b
-            /* memctx is freed by the caller */
b7b64b
-            char *pac_sid = dom_sid_string(tmpctx, &client_sid);
b7b64b
-            char *req_sid = dom_sid_string(tmpctx, requester_sid);
b7b64b
-            krb5_klog_syslog(LOG_ERR, "PAC issue: PAC has a SID "
b7b64b
-                                      "different from what PAC requester claims. "
b7b64b
-                                      "PAC [%s] vs PAC requester [%s]",
b7b64b
-                                      pac_sid ? pac_sid : "<failed to display>",
b7b64b
-                                      req_sid ? req_sid : "<failed to display>");
b7b64b
-            kerr = KRB5KDC_ERR_POLICY;
b7b64b
-            goto done;
b7b64b
+            struct ipadb_context *ipactx = ipadb_get_context(context);
b7b64b
+            if (!ipactx || !ipactx->mspac) {
b7b64b
+                return KRB5_KDB_DBNOTINITED;
b7b64b
+            }
b7b64b
+            /* In S4U case we might be dealing with the PAC issued by the trusted domain */
b7b64b
+            if (is_s4u && (ipactx->mspac->trusts != NULL)) {
b7b64b
+                /* Iterate through list of trusts and check if this SID belongs to
b7b64b
+                * one of the domains we trust */
b7b64b
+                for(int i = 0 ; i < ipactx->mspac->num_trusts ; i++) {
b7b64b
+                    result = dom_sid_check(&ipactx->mspac->trusts[i].domsid,
b7b64b
+                                           requester_sid, false);
b7b64b
+                    if (result) {
b7b64b
+                        is_from_trusted_domain = true;
b7b64b
+                        break;
b7b64b
+                    }
b7b64b
+                }
b7b64b
+            }
b7b64b
+
b7b64b
+            if (!is_from_trusted_domain) {
b7b64b
+                /* memctx is freed by the caller */
b7b64b
+                char *pac_sid = dom_sid_string(tmpctx, &client_sid);
b7b64b
+                char *req_sid = dom_sid_string(tmpctx, requester_sid);
b7b64b
+                krb5_klog_syslog(LOG_ERR, "PAC issue: PAC has a SID "
b7b64b
+                                        "different from what PAC requester claims. "
b7b64b
+                                        "PAC [%s] vs PAC requester [%s]",
b7b64b
+                                        pac_sid ? pac_sid : "<failed to display>",
b7b64b
+                                        req_sid ? req_sid : "<failed to display>");
b7b64b
+                kerr = KRB5KDC_ERR_TGT_REVOKED;
b7b64b
+                goto done;
b7b64b
+            }
b7b64b
         }
b7b64b
     }
b7b64b
 
b7b64b
-- 
b7b64b
2.31.1
b7b64b