gp_creds: fix use-after-free in gp_count_tickets() - #133
Open
prabhakarpujeri wants to merge 1 commit into
Open
Conversation
simo5
requested changes
Sep 2, 2026
| } | ||
|
|
||
| do { | ||
| for (;;) { |
Member
There was a problem hiding this comment.
if we are going to switch to a for loop, then please use:
for (err = 0; err == 0;
err = krb5_cc_next_cred(context, ccache, &cursor, &creds)) {
Member
There was a problem hiding this comment.
in fact we can actually write this as:
for (err = 0; err == 0;
err = krb5_cc_next_cred(context, ccache, &cursor, &creds)) {
if (err == 0) {
krb5_free_cred_contents(context, &creds);
(*ccsum)++;
}
}
if (err != KRB5_CC_END) {
ret_min = err;
ret_maj = GSS_S_FAILURE;
goto done;
}
^ This is my preferred and more understandable form.
prabhakarpujeri
force-pushed
the
fixes
branch
from
September 3, 2026 03:39
aeaedb7 to
e45faca
Compare
The loop over the ccache calls krb5_free_cred_contents() and increments the counter even when krb5_cc_next_cred() has already returned KRB5_CC_END. On an empty cache this frees an uninitialised krb5_creds, and after N tickets it frees the last credential's contents a second time and counts one entry too many. Only free and count on a successful fetch, and leave the loop when the end of the cache is reached. Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
Author
|
Thanks Simo — applied exactly that form in e45faca (amended): the loop initializer/step drives |
Member
|
Looks like this change still has some issues, please test locally |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The counting loop in
gp_count_tickets()callskrb5_free_cred_contents(&creds)and increments the counter even whenkrb5_cc_next_cred()has already failed — includingKRB5_CC_END, where it then continues iterating.krb5_creds.*ccsumcomes out one too high.Only free and count after a successful fetch, and leave the loop at
KRB5_CC_END.Built clean with
--disable-public-librariesetc. default options (-Wall -Wextraquiet), and the counting behavior was traced for the empty-ccache, zero-ticket and multi-ticket cases against the MIT Kerberos semantics ofkrb5_cc_next_cred()(KRB5_CC_END is the normal end-of-cache signal and must not count nor free).