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
Conversation
|
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. |
|
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(). |
|
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"? |
|
@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. |
|
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: If you prefer this over the function I suggested, I could code this up and document it. Andreas |
|
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. |
|
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. |
|
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. |
|
That's the general idea, yes. |
13f7170
to
aa34bf5
Compare
|
Here we go. |
aa34bf5
to
2cc8d47
Compare
|
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.) |
2cc8d47
to
fbfcfe2
Compare
|
Removed unused variable status. Testing with Samba now ... |
|
Ok, Samba AD is back in a working state with these patches. |
10b9be3
to
abc7a10
Compare
abc7a10
to
82a163b
Compare
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
82a163b
to
87d8d1c
Compare
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
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
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
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
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
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
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>
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
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
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.