CVE-2020-25718 s4-rpc_server: Obtain the user tokenGroups earlier
authorAndrew Bartlett <abartlet@samba.org>
Thu, 30 Sep 2021 22:09:48 +0000 (11:09 +1300)
committerJule Anger <janger@samba.org>
Mon, 8 Nov 2021 09:46:45 +0000 (10:46 +0100)
This will allow the creation of a common helper routine that
takes the token SID list (from tokenGroups or struct auth_user_info_dc)
and returns the allowed/denied result.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14558

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
source4/rpc_server/drsuapi/getncchanges.c
source4/rpc_server/netlogon/dcerpc_netlogon.c

index c7d2addd104d21a00012bd26cf4d62d6ac86df58..bc30e73e06bf4c511a5a1105ed9cc66365c4274c 100644 (file)
@@ -1282,6 +1282,20 @@ static WERROR getncchanges_repl_secret(struct drsuapi_bind_state *b_state,
                goto allowed;
        }
 
+       /*
+        * The SID list needs to include itself as well as the tokenGroups.
+        *
+        * TODO determine if sIDHistory is required for this check
+        */
+       werr = samdb_result_sid_array_ndr(b_state->sam_ctx_system, obj_res->msgs[0],
+                                         mem_ctx, "tokenGroups",
+                                         &num_token_sids,
+                                         &token_sids,
+                                         object_sid, 1);
+       if (!W_ERROR_IS_OK(werr) || token_sids==NULL) {
+               goto denied;
+       }
+
        /* but it isn't allowed to get anyone elses krbtgt secrets */
        if (samdb_result_dn(b_state->sam_ctx_system, mem_ctx,
                            obj_res->msgs[0], "msDS-KrbTgtLinkBL", NULL)) {
@@ -1310,20 +1324,6 @@ static WERROR getncchanges_repl_secret(struct drsuapi_bind_state *b_state,
                goto denied;
        }
 
-       /*
-        * The SID list needs to include itself as well as the tokenGroups.
-        *
-        * TODO determine if sIDHistory is required for this check
-        */
-       werr = samdb_result_sid_array_ndr(b_state->sam_ctx_system, obj_res->msgs[0],
-                                         mem_ctx, "tokenGroups",
-                                         &num_token_sids,
-                                         &token_sids,
-                                         object_sid, 1);
-       if (!W_ERROR_IS_OK(werr) || token_sids==NULL) {
-               goto denied;
-       }
-
        if (never_reveal_sids &&
            sid_list_match(num_token_sids,
                           token_sids,
index d82a05d58690ec0c490916080af208fe504d3242..4da28c887cfb818c85c09f8655708e65d858ff61 100644 (file)
@@ -2874,6 +2874,20 @@ static bool sam_rodc_access_check(struct ldb_context *sam_ctx,
                goto denied;
        }
 
+       /*
+        * The SID list needs to include itself as well as the tokenGroups.
+        *
+        * TODO determine if sIDHistory is required for this check
+        */
+       werr = samdb_result_sid_array_ndr(sam_ctx, obj_res->msgs[0],
+                                         mem_ctx, "tokenGroups",
+                                         &num_token_sids,
+                                         &token_sids,
+                                         object_sid, 1);
+       if (!W_ERROR_IS_OK(werr) || token_sids==NULL) {
+               goto denied;
+       }
+
        werr = samdb_result_sid_array_dn(sam_ctx, rodc_res->msgs[0],
                                         mem_ctx, "msDS-NeverRevealGroup",
                                         &num_never_reveal_sids,
@@ -2890,20 +2904,6 @@ static bool sam_rodc_access_check(struct ldb_context *sam_ctx,
                goto denied;
        }
 
-       /*
-        * The SID list needs to include itself as well as the tokenGroups.
-        *
-        * TODO determine if sIDHistory is required for this check
-        */
-       werr = samdb_result_sid_array_ndr(sam_ctx, obj_res->msgs[0],
-                                         mem_ctx, "tokenGroups",
-                                         &num_token_sids,
-                                         &token_sids,
-                                         object_sid, 1);
-       if (!W_ERROR_IS_OK(werr) || token_sids==NULL) {
-               goto denied;
-       }
-
        if (never_reveal_sids &&
            sid_list_match(num_token_sids,
                           token_sids,