Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a free_e_data function pointer to krb5_db_entry #596

Merged
merged 2 commits into from Jan 19, 2017

Conversation

cryptomilk
Copy link
Contributor

There are projects out there which provide kdb modules and use a
different memory allocator than malloc. One example is Samba which uses
talloc. Those projects should to be able to free e_data using their
memory allocation functions.

@cryptomilk
Copy link
Contributor Author

I would need this in 1.15. Currently we allocate memory till the OOM shows up. Implementing it differently would be a bad for performance.

@cryptomilk
Copy link
Contributor Author

It would also be fine to restore the free_principal in the kdb vtable and make it optional.

Then the modules which need it could implement it freeing e_data first and then calling krb5_db_free_principal().

@greghudson
Copy link
Member

greghudson commented Jan 13, 2017

It's not great that the 1.15 changes make life harder for Samba, but 1.15 is released and I'm not sure we can safely make a change of this nature.

How bad for performance is it to use malloc() or krb5_db_alloc() for the e_data pointer? What do you mean by "Currently we allocate memory till the OOM shows up"?

@abbra
Copy link

abbra commented Jan 13, 2017

@greghudson Samba uses its own hierarchical allocator, talloc, which allows to free all memory associated with a context in one go. If krb5 1.15 frees e_data allocated with talloc with conventional free(), then all child allocations of that context are lost. This is what @cryptomilk means "currently we allocate memory till the OOM shows up" as for the lifetime of the krb5kdc/kadmind the child allocations will stay there.

Samba tries to maintain common abstraction for both Heimdal and MIT krb5 backends. In HDB there is a callback to free the entry, set in the entry itself, like @cryptomilk proposes in this patch. Samba's callback handles talloc-based deallocation there.

Ideally, a revert of the commit that went into 1.15 would be welcomed. If that is not possible, adding a per-entry free callback is an option.

@cryptomilk
Copy link
Contributor Author

cryptomilk commented Jan 13, 2017

We do not need to fully revert it. A an optional free_principal callback in the kdb vtable would be fine. Then you could create function like this:

void free_principal(krb5_context ctx, krb5_db_entry *e)
{
   talloc_free(e->e_data);
   e->e_data = NULL;
   krb5_db_free_principal(e);
}

If you prefer this over the function I suggested, I could code this up and document it.

Andreas

@greghudson
Copy link
Member

greghudson commented Jan 14, 2017

I think I understand. e_data points to a multi-part data structure, and the only way to arrange for it to be freed correctly with the new KDB interface would be to marshal it into a single malloc()'d memory region with interior pointers pointing into later parts of the memory buffer.

I will think more about whether the change in this PR is safe for 1.15 or not.

@greghudson
Copy link
Member

greghudson commented Jan 17, 2017

After talking about this issue with Simo and others, I think the conservative fix for 1.15 is to add a DAL function to free the principal e_data pointer (not the whole principal) and increment the minor version. That's probably also a reasonable solution going forward, although it's different from Heimdal's design.

Unfortunately, I don't think we have ever used the kdb_vftabl min_ver field in the past, and kdb5.c:kdb_load_library() isn't set up to use it. I don't think it's reasonable to ask Andreas to figure this out, so I will put it on my short-term todo list.

@cryptomilk
Copy link
Contributor Author

We add a free_principal_e_data function pointer to the vtable to allow to free e_data and call it before krb5_db_free_principal() if e_data is not NULL?

I could code up that part if you want me to.

@greghudson
Copy link
Member

That's the general idea, yes.

@cryptomilk cryptomilk force-pushed the master-kdb_free_entry branch 2 times, most recently from 13f7170 to aa34bf5 Compare January 18, 2017 11:11
@cryptomilk
Copy link
Contributor Author

Here we go.

@greghudson
Copy link
Member

I pushed updated commits. Please test.

(I do not want to expose a KRB5_KDB_DAL_MINOR_VERSION macro. If modules use that in their vtables, we could treat their vtables as having been updated for a minor version bump when they haven't been.)

@cryptomilk
Copy link
Contributor Author

Removed unused variable status. Testing with Samba now ...

@cryptomilk
Copy link
Contributor Author

Ok, Samba AD is back in a working state with these patches.

greghudson and others added 2 commits January 19, 2017 18:27
In preparation for bumping the kdb_vftabl minor version, use explicit
field assignments when copying the module vtable to the internal copy,
so that we can conditionalize assignments for minor versions greater
than 0.

ticket: 8538
Add an optional method to kdb_vftabl to free e_data pointer in a
principal entry, in case it was populated by a module using a more
complex structure than a single memory region.

[ghudson@mit.edu: handled minor version bump; simplified code; rewrote
commit message]

ticket: 8538
target_version: 1.15-next
tags: pullup
@tlyu tlyu merged commit 87d8d1c into krb5:master Jan 19, 2017
abbra added a commit to abbra/freeipa that referenced this pull request Jan 24, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

https://fedorahosted.org/freeipa/ticket/6619
abbra added a commit to abbra/freeipa that referenced this pull request Jan 24, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

https://fedorahosted.org/freeipa/ticket/6619
abbra added a commit to abbra/freeipa that referenced this pull request Feb 6, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

https://fedorahosted.org/freeipa/ticket/6619
abbra added a commit to abbra/freeipa that referenced this pull request Feb 7, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

https://fedorahosted.org/freeipa/ticket/6619
abbra added a commit to abbra/freeipa that referenced this pull request Feb 7, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

Use explicit KDB version dependency in Fedora 26+ via BuildRequires.

With new DAL version, freeipa package will fail to build and
we'll have to add a support for new DAL version explicitly.

https://fedorahosted.org/freeipa/ticket/6619
abbra added a commit to abbra/freeipa that referenced this pull request Feb 13, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

Use explicit KDB version dependency in Fedora 26+ via BuildRequires.

With new DAL version, freeipa package will fail to build and
we'll have to add a support for new DAL version explicitly.

https://fedorahosted.org/freeipa/ticket/6619
tkrizek pushed a commit to tkrizek/freeipa that referenced this pull request Feb 15, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

Use explicit KDB version dependency in Fedora 26+ via BuildRequires.

With new DAL version, freeipa package will fail to build and
we'll have to add a support for new DAL version explicitly.

https://fedorahosted.org/freeipa/ticket/6619

Reviewed-By: Simo Sorce <ssorce@redhat.com>
Reviewed-By: Robbie Harwood <rharwood@redhat.com>
tkrizek pushed a commit to tkrizek/freeipa that referenced this pull request Mar 16, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

Use explicit KDB version dependency in Fedora 26+ via BuildRequires.

With new DAL version, freeipa package will fail to build and
we'll have to add a support for new DAL version explicitly.

https://fedorahosted.org/freeipa/ticket/6619
tkrizek pushed a commit to tkrizek/freeipa that referenced this pull request Mar 17, 2017
DAL version 6.0 removed support for a callback to free principal.
This broke KDB drivers which had complex e_data structure within
the principal structure. As result, FreeIPA KDB driver was leaking
memory with DAL version 6.0 (krb5 1.15).

DAL version 6.1 added a special callback for freeing e_data structure.
See details at krb5/krb5#596

Restructure KDB driver code to provide this callback in case
we are built against DAL version that supports it. For DAL version
prior to 6.0 use this callback in the free_principal callback to
tidy the code.

Use explicit KDB version dependency in Fedora 26+ via BuildRequires.

With new DAL version, freeipa package will fail to build and
we'll have to add a support for new DAL version explicitly.

https://pagure.io/freeipa/issue/6776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants