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