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