RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 911147 - krb5_get_init_creds_keytab() leaks memory
Summary: krb5_get_init_creds_keytab() leaks memory
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: krb5
Version: 6.4
Hardware: All
OS: Linux
urgent
high
Target Milestone: rc
: ---
Assignee: Nalin Dahyabhai
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On: 911110
Blocks: 978312
TreeView+ depends on / blocked
 
Reported: 2013-02-14 13:37 UTC by Petr Spacek
Modified: 2018-12-02 18:05 UTC (History)
10 users (show)

Fixed In Version: krb5-1.10.3-11.el6
Doc Type: Bug Fix
Doc Text:
When the application lookup_etypes_for_keytab() function in krb5-libs attempted to use a keytab file to obtain initial credentials from a KDC, as a preliminary step, it enumerated the set of keys in the keytab to determine which types of keys it possessed. While doing so, it leaked memory. This update adds a krb5_kt_free_entry() call in this loop, and memory leaks no longer occur in the described scenario
Clone Of: 911110
Environment:
Last Closed: 2013-11-14 10:47:01 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Petr Spacek 2013-02-14 13:37:20 UTC
+++ This bug was initially created as a clone of Bug #911110 +++
Package version and Valgrind trace was updated to match situation in RHEL 6.4.

Description of problem:
Function lookup_etypes_for_keytab() in krb5-libs leaks memory while working with keytab.


Version-Release number of selected component (if applicable):
krb5-libs-1.10.3-10.el6.x86_64


How reproducible:
100 %


Steps to Reproduce:
1. Create program with krb5_get_init_creds_keytab()
2. Call the program on keytab file with big amount of amount of keys
3. Use valgrind to check your program


Actual results:
Output from Valgrind.
==10215==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==10215==    by 0x742FEA3: krb5_ktfileint_internal_read_entry (kt_file.c:1253)
==10215==    by 0x7431E34: krb5_ktfile_get_next (kt_file.c:1414)
==10215==    by 0x7443CF0: krb5_init_creds_set_keytab (gic_keytab.c:101)
==10215==    by 0x744409D: get_init_creds_keytab (gic_keytab.c:242)
==10215==    by 0x74441B2: krb5_get_init_creds_keytab (gic_keytab.c:284)
==10215==    by 0xAF67D6A: get_krb5_tgt (krb5_helper.c:176)
==10215==    by 0xAF6D148: ldap_connect (ldap_helper.c:2284)
==10215==    by 0xAF759F8: new_ldap_instance (ldap_helper.c:3099)
==10215==    by 0xAF79A1D: manager_create_db_instance (zone_manager.c:152)
==10215==    by 0xAF696AC: dynamic_driver_init (ldap_driver.c:1364)
==10215==    by 0x508FDE5: dns_dynamic_db_load (dynamic_db.c:232)


Expected results:
No leaks :-)


Additional info:
AFAIK the memory leak originates in lookup_etypes_for_keytab() function. File gic_keytab.c:101 contains krb5_kt_next_entry() call in a loop, but there is no krb5_kt_free_entry() call in this loop.

See code example in manual page http://www.unix.com/man-page/all/3/krb5_kt_free_entry/

Comment 2 RHEL Program Management 2013-02-20 06:48:37 UTC
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 3 Nalin Dahyabhai 2013-02-28 20:37:23 UTC
(In reply to comment #0)> AFAIK the memory leak originates in lookup_etypes_for_keytab() function.
> File gic_keytab.c:101 contains krb5_kt_next_entry() call in a loop, but
> there is no krb5_kt_free_entry() call in this loop.

Looks like you're right: there's supposed to be some krb5_free_keytab_entry_contents() action in there.

Comment 11 Karel Srot 2013-06-25 05:24:35 UTC
(In reply to Petr Spacek from comment #0)
> Steps to Reproduce:
> 1. Create program with krb5_get_init_creds_keytab()

Could you please attach such a program? Thank you.

Comment 12 Petr Spacek 2013-06-25 12:25:40 UTC
I guess that any program which works with Kerberos keytab should have this problem.

In my case I hit the bug with BIND/named:
/etc/named.conf contained:
    tkey-gssapi-credential "DNS/ipa1.example.com";
    tkey-domain "EXAMPLE.COM";

You can use FreeIPA server, it will configure named with Kerberos authentication for you.


Also, you can try kinit -kt , but I didn't try it.

Comment 13 Patrik Kis 2013-06-25 16:48:09 UTC
With a simple kinit -k and using a short keytab file I see the following log from valgrind. It looks very similar to the reported one.

Nalin, can you confirm that this is the same error or something else?

# valgrind --leak-check=yes kinit -k
==2330== Memcheck, a memory error detector
==2330== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==2330== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==2330== Command: kinit -k
==2330== 
==2330== 
==2330== HEAP SUMMARY:
==2330==     in use at exit: 728 bytes in 36 blocks
==2330==   total heap usage: 54,259 allocs, 54,223 frees, 4,919,337 bytes allocated
==2330== 
==2330== 104 bytes in 6 blocks are definitely lost in loss record 2 of 5
==2330==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==2330==    by 0x5719273: krb5_ktfileint_internal_read_entry (kt_file.c:1375)
==2330==    by 0x571AE34: krb5_ktfile_get_next (kt_file.c:1414)
==2330==    by 0x572CCF0: krb5_init_creds_set_keytab (gic_keytab.c:101)
==2330==    by 0x572D09D: get_init_creds_keytab (gic_keytab.c:242)
==2330==    by 0x572D1B2: krb5_get_init_creds_keytab (gic_keytab.c:284)
==2330==    by 0x10AAFE: k5_kinit (kinit.c:729)
==2330==    by 0x10B775: main (kinit.c:844)
==2330== 
==2330== 624 (240 direct, 384 indirect) bytes in 6 blocks are definitely lost in loss record 5 of 5
==2330==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==2330==    by 0x5718EA3: krb5_ktfileint_internal_read_entry (kt_file.c:1253)
==2330==    by 0x571AE34: krb5_ktfile_get_next (kt_file.c:1414)
==2330==    by 0x572CCF0: krb5_init_creds_set_keytab (gic_keytab.c:101)
==2330==    by 0x572D09D: get_init_creds_keytab (gic_keytab.c:242)
==2330==    by 0x572D1B2: krb5_get_init_creds_keytab (gic_keytab.c:284)
==2330==    by 0x10AAFE: k5_kinit (kinit.c:729)
==2330==    by 0x10B775: main (kinit.c:844)
==2330== 
==2330== LEAK SUMMARY:
==2330==    definitely lost: 344 bytes in 12 blocks
==2330==    indirectly lost: 384 bytes in 24 blocks
==2330==      possibly lost: 0 bytes in 0 blocks
==2330==    still reachable: 0 bytes in 0 blocks
==2330==         suppressed: 0 bytes in 0 blocks
==2330== 
==2330== For counts of detected and suppressed errors, rerun with: -v
==2330== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 8 from 6)

Comment 14 Nalin Dahyabhai 2013-06-25 21:58:56 UTC
This looks like the same traceback to me.


Note You need to log in before you can comment on or make changes to this bug.