krb5_child: fix enterprise principal parsing in keep-alive sessions#8351
krb5_child: fix enterprise principal parsing in keep-alive sessions#8351alexey-tikhonov merged 1 commit intoSSSD:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request aims to fix enterprise principal parsing in keep-alive sessions by re-parsing principals when settings are updated. The overall approach is correct, but the implementation introduces several critical use-after-free vulnerabilities. In multiple places, memory is freed but the corresponding pointers are not nullified. If a subsequent operation fails, these dangling pointers can be freed again in a later call, leading to a crash. I've provided specific comments and suggestions to fix these issues.
1e56bc9 to
a06b02e
Compare
a06b02e to
388d902
Compare
388d902 to
d5799c5
Compare
|
@aplopez do you mind taking another look? |
Looking better now. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the issue of enterprise principal parsing inconsistencies in keep-alive sessions. By ensuring that krb5_req settings, including use_enterprise_princ, validate, posix_domain, and send_pac, are correctly updated between commands, and by re-parsing the principal with appropriate flags when necessary, the changes fix UPN handling in complex AD environments. The introduction of a conditional update logic for kr->princ and proper management of kr->creds and kr->name contribute to the correctness and robustness of the Kerberos child process.
| /* Update settings that may change between commands */ | ||
| dest->use_enterprise_princ = src->use_enterprise_princ; | ||
| dest->validate = src->validate; | ||
| dest->posix_domain = src->posix_domain; | ||
| dest->send_pac = src->send_pac; |
There was a problem hiding this comment.
The update of use_enterprise_princ, validate, posix_domain, and send_pac in krb5_req_update is critical for ensuring that subsequent Kerberos operations in a keep-alive session use the correct configuration. Without this, the principal parsing logic in k5c_setup might operate with stale flags, leading to incorrect behavior, especially in dynamic AD environments.
| kerr = sss_krb5_parse_name_flags(kr->ctx, kr->upn, parse_flags, &princ); | ||
| if (kerr != 0) { | ||
| KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr); | ||
| return kerr; |
There was a problem hiding this comment.
The introduction of a temporary princ and the subsequent comparison with kr->princ before updating is a robust way to handle changes in the principal. This prevents unnecessary re-initialization if the principal remains the same and correctly updates it when needed, which is vital for the PR's objective.
| ret = k5c_setup(kr, offline); | ||
| if (ret != EOK) { | ||
| DEBUG(SSSDBG_CRIT_FAILURE, "k5c_setup failed during keep-alive [%d]: %s\n", | ||
| ret, sss_strerror(ret)); | ||
| goto done; |
There was a problem hiding this comment.
| if (kr->princ == NULL || !krb5_principal_compare(kr->ctx, kr->princ, princ)) { | ||
| DEBUG(SSSDBG_TRACE_FUNC, "Updating principal\n"); | ||
| if (kr->princ != NULL) { | ||
| krb5_free_principal(kr->ctx, kr->princ); | ||
| } | ||
| kr->princ = princ; | ||
| } else { | ||
| DEBUG(SSSDBG_TRACE_FUNC, "Principal unchanged, keeping existing\n"); | ||
| krb5_free_principal(kr->ctx, princ); | ||
| } |
| if (kr->princ_orig == NULL) { | ||
| kerr = krb5_parse_name(kr->ctx, kr->upn, &kr->princ_orig); | ||
| if (kerr != 0) { | ||
| KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr); | ||
| return kerr; | ||
| } | ||
| } |
| sss_krb5_free_unparsed_name(kr->ctx, kr->name); | ||
| kr->name = NULL; |
| if (kr->creds != NULL) { | ||
| krb5_free_cred_contents(kr->ctx, kr->creds); | ||
| } else { | ||
| kr->creds = calloc(1, sizeof(krb5_creds)); | ||
| if (kr->creds == NULL) { | ||
| DEBUG(SSSDBG_CRIT_FAILURE, "calloc failed.\n"); | ||
| return ENOMEM; | ||
| } | ||
| } |
sumit-bose
left a comment
There was a problem hiding this comment.
Hi,
thank you for the patch, ACK
bye,
Sumit
When keep-alive sessions transition between command types (e.g., from SSS_PAM_PREAUTH to SSS_PAM_AUTHENTICATE), enterprise principal settings were not being updated, causing parsing inconsistencies in complex AD environments. This change ensures that when the backend sends updated enterprise principal settings for different command types, the principals are correctly re-parsed with the appropriate flags, fixing UPN handling in multi-domain AD environments. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com> Reviewed-by: Alejandro López <allopez@redhat.com> Reviewed-by: Sumit Bose <sbose@redhat.com>
d5799c5 to
cc649a0
Compare
When keep-alive sessions transition between command types (e.g., from SSS_PAM_PREAUTH to SSS_PAM_AUTHENTICATE), enterprise principal settings were not being updated, causing parsing inconsistencies in complex AD environments.
This change ensures that when the backend sends updated enterprise principal settings for different command types, the principals are correctly re-parsed with the appropriate flags, fixing UPN handling in multi-domain AD environments.