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