After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 726353 - Leaking credentials, cursors, principals and GDateTime
Leaking credentials, cursors, principals and GDateTime
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: Kerberos
3.10.x
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-03-14 15:57 UTC by Debarshi Ray
Modified: 2014-03-17 15:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
kerberos: Leaking credentials, cursors, principals and GDateTime (3.67 KB, patch)
2014-03-15 13:39 UTC, Debarshi Ray
needs-work Details | Review
identity: Plug a few leaked strings (2.22 KB, patch)
2014-03-15 14:17 UTC, Debarshi Ray
none Details | Review
kerberos: Leaking credentials, cursors, principals and GDateTime (3.44 KB, patch)
2014-03-15 21:22 UTC, Debarshi Ray
none Details | Review
kerberos: fix leak in register_error_domain (2.52 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: refactor register_error_domain (2.56 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: make enum_class in register_error_domain const (1.79 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: fix leak in add_temporary_account (3.67 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: don't free alarm in set_alarm, free in callers (3.67 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: fix leak in reset_alarms (2.12 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: fix principal leak in identity_renew (2.08 KB, patch)
2014-03-17 14:02 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: consolidate exit path code in identity_renew (2.79 KB, patch)
2014-03-17 14:03 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: fix leak in verify_identity (2.29 KB, patch)
2014-03-17 14:03 UTC, Ray Strode [halfline]
committed Details | Review
kerberos: make sure credential cache sequence is always explicitly ended (2.42 KB, patch)
2014-03-17 14:03 UTC, Ray Strode [halfline]
committed Details | Review

Description Debarshi Ray 2014-03-14 15:57:01 UTC
See the downstream Fedora 20 bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=1046197

It has a patch and valgrind logs.
Comment 1 Debarshi Ray 2014-03-15 13:39:34 UTC
Created attachment 272004 [details] [review]
kerberos: Leaking credentials, cursors, principals and GDateTime

This is a slightly tweaked and more complete version of the patch Michael submitted. However, there is one line that I am not sure about, which I will subsequently point out.
Comment 2 Debarshi Ray 2014-03-15 13:42:35 UTC
Review of attachment 272004 [details] [review]:

::: src/goaidentity/goakerberosidentity.c
@@ +642,3 @@
     }
 
+  krb5_free_cred_contents (self->priv->kerberos_context, &credentials);

Do we really need this line? If we succeeded in getting the next credential, then we are going to free it up in the next iteration of the loop. It appears to me that if we fail to do so, then we don't need to free it up.
Comment 3 Debarshi Ray 2014-03-15 14:17:40 UTC
Created attachment 272008 [details] [review]
identity: Plug a few leaked strings
Comment 4 Debarshi Ray 2014-03-15 14:23:41 UTC
This part of the valgrind logs appear consistent with the reports of leaking file descriptors (most likely timerfds) that we are still getting:

==24607== 64 bytes in 1 blocks are possibly lost in loss record 2,385 of 3,673
==24607==    at 0x4C291D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24607==    by 0xBB73EC6: g_malloc0 (gmem.c:134)
==24607==    by 0xB8E31D4: g_closure_new_simple (gclosure.c:206)
==24607==    by 0xB8FF264: g_source_set_dummy_callback (gsourceclosure.c:319)
==24607==    by 0xB605C8C: g_unix_input_stream_pollable_create_source (gunixinputstream.c:519)
==24607==    by 0x416312: goa_alarm_set_time (goaalarm.c:461)
==24607==    by 0x410700: set_alarm.isra.1 (goakerberosidentity.c:789)
==24607==    by 0x410900: reset_alarms (goakerberosidentity.c:881)
==24607==    by 0x412037: goa_kerberos_identity_update (goakerberosidentity.c:1310)
==24607==    by 0x413F5B: on_job_scheduled (goakerberosidentitymanager.c:426)
==24607==    by 0xB5CBF35: io_job_thread (gioscheduler.c:89)
==24607==    by 0xB5EB864: g_task_thread_pool_thread (gtask.c:1245)

I will take a closer look when I am on a network with Kerberos on it.
Comment 5 Michael Cronenworth 2014-03-15 16:08:01 UTC
(In reply to comment #2)
> Do we really need this line? If we succeeded in getting the next credential,
> then we are going to free it up in the next iteration of the loop. It appears
> to me that if we fail to do so, then we don't need to free it up.

Reviewing this, yes, if krb5_cc_next_cred() doesn't allocate on failure then it is unnecessary.

I was going to submit a git patch this weekend (now) but I see you've already taken this over. Do you still want me to supply a revised patch?
Comment 6 Debarshi Ray 2014-03-15 21:22:17 UTC
Created attachment 272033 [details] [review]
kerberos: Leaking credentials, cursors, principals and GDateTime
Comment 7 Debarshi Ray 2014-03-15 21:23:20 UTC
(In reply to comment #5)
> (In reply to comment #2)
> > Do we really need this line? If we succeeded in getting the next credential,
> > then we are going to free it up in the next iteration of the loop. It appears
> > to me that if we fail to do so, then we don't need to free it up.
> 
> Reviewing this, yes, if krb5_cc_next_cred() doesn't allocate on failure then it
> is unnecessary.

Removed it. Thanks for taking a look.

> I was going to submit a git patch this weekend (now) but I see you've already
> taken this over. Do you still want me to supply a revised patch?

We still need to investigate the GoaAlarms issue.
Comment 8 Ray Strode [halfline] 2014-03-17 14:01:31 UTC
So the patches look fine, but they squish a number of changes together.  I've split them out for readability.  Will attach and push.
Comment 9 Ray Strode [halfline] 2014-03-17 14:02:37 UTC
Created attachment 272156 [details] [review]
kerberos: fix leak in register_error_domain

In the event a type was not known, we were leaking the
type name.
Comment 10 Ray Strode [halfline] 2014-03-17 14:02:40 UTC
Created attachment 272157 [details] [review]
kerberos: refactor register_error_domain

This commit move type class freeing to the
otherside of the "out" label to make the code
robust against potential future changes.
Comment 11 Ray Strode [halfline] 2014-03-17 14:02:44 UTC
Created attachment 272158 [details] [review]
kerberos: make enum_class in register_error_domain const

Just as a defensive programming measure.
Comment 12 Ray Strode [halfline] 2014-03-17 14:02:47 UTC
Created attachment 272159 [details] [review]
kerberos: fix leak in add_temporary_account

The account description was not getting freed.
Comment 13 Ray Strode [halfline] 2014-03-17 14:02:50 UTC
Created attachment 272160 [details] [review]
kerberos: don't free alarm in set_alarm, free in callers

It's a little unexpected that set_alarm "eats" the alarm passed in.
This commit makes it the caller's responsibility to free the alarm
to more closely match typical practice.
Comment 14 Ray Strode [halfline] 2014-03-17 14:02:54 UTC
Created attachment 272161 [details] [review]
kerberos: fix leak in reset_alarms

A GDateTime "now" object wasn't getting cleaned up after use.
Comment 15 Ray Strode [halfline] 2014-03-17 14:02:57 UTC
Created attachment 272162 [details] [review]
kerberos: fix principal leak in identity_renew

The code carefully freed the principal in all error cases, but then
failed to free the principal in the non-error case!
Comment 16 Ray Strode [halfline] 2014-03-17 14:03:01 UTC
Created attachment 272163 [details] [review]
kerberos: consolidate exit path code in identity_renew

the principal is freed in 3 different places.  This commit
consolidates it to one place for clarity and added robustness
against future changes.
Comment 17 Ray Strode [halfline] 2014-03-17 14:03:04 UTC
Created attachment 272164 [details] [review]
kerberos: fix leak in verify_identity

The kerberos API allocates credentials on the heap, when iterating
over a credential collection (for each iteration).

This commit makes sure each of those credentials is freed.
Comment 18 Ray Strode [halfline] 2014-03-17 14:03:07 UTC
Created attachment 272165 [details] [review]
kerberos: make sure credential cache sequence is always explicitly ended

The code currently fails to pair krb5_cc_start_seq_get with krb5_cc_end_seq_get
in an error case.  This can lead the cursor getting leaked.
Comment 19 Ray Strode [halfline] 2014-03-17 14:05:07 UTC
Attachment 272156 [details] pushed as c679b88 - kerberos: fix leak in register_error_domain
Attachment 272157 [details] pushed as 0ab3d27 - kerberos: refactor register_error_domain
Attachment 272158 [details] pushed as 16bcb7c - kerberos: make enum_class in register_error_domain const
Attachment 272159 [details] pushed as c4c47a8 - kerberos: fix leak in add_temporary_account
Attachment 272160 [details] pushed as 3060fdf - kerberos: don't free alarm in set_alarm, free in callers
Attachment 272161 [details] pushed as cc2c0ac - kerberos: fix leak in reset_alarms
Attachment 272162 [details] pushed as 4923d99 - kerberos: fix principal leak in identity_renew
Attachment 272163 [details] pushed as d020a84 - kerberos: consolidate exit path code in identity_renew
Attachment 272164 [details] pushed as 16ed9d4 - kerberos: fix leak in verify_identity
Attachment 272165 [details] pushed as 2e41de2 - kerberos: make sure credential cache sequence is always explicitly ended
Comment 20 Michael Cronenworth 2014-03-17 14:34:09 UTC
Thanks, Ray. Could these be backported to 3-12 and 3-10?
Comment 21 Ray Strode [halfline] 2014-03-17 15:06:40 UTC
To ssh://halfline@git.gnome.org/git/gnome-online-accounts
   91d2059..007d9fd  gnome-3-12 -> gnome-3-12
   0b0c715..30e67d1  gnome-3-10 -> gnome-3-10