Skip to content

libkadm5clnt: leak and/or use-after-free of ccache #1331

Description

@riastradh

Describe the bug
The API contract for kadm5_init_with_creds and kadm5_init_with_creds_ctx is unclear on whether the kadm5 handle or the caller owns the given ccache.

  • If the kadm5 handle owns the ccache, then krb5_cc_close is missing from kadm5_c_destroy and it will leak:

    free(context->realm);
    free(context->readonly_admin_server);
    free(context->admin_server);
    if (context->sock != rk_INVALID_SOCKET)
    rk_closesocket(context->sock);
    if (context->client_name)
    free(context->client_name);
    if (context->service_name)
    free(context->service_name);
    if (context->ac != NULL)
    krb5_auth_con_free(context->context, context->ac);
    if(context->my_context)
    krb5_free_context(context->context);
    free(context);

  • If the caller owns the ccache, then _kadm5_connect -> kadm_connect may free it, leading the caller to use-after-free:

    krb5_cc_close(context, cc);

To Reproduce

  1. Adapt kadmin(8) to krb5_cc_resolve and krb5_cc_close in an attempt to address kadmin(8) ignores existing ccache #1328.
  2. Observe SIGSEGV in krb5_cc_close because libkadm5clnt already did it.

Expected behavior
Either the kadm5 handle owns the ccache, or the caller owns the ccache, and the system is clear on which is which.

Screenshots
N/A

Desktop (please complete the following information):
NetBSD 9

Smartphone (please complete the following information):
N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions