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 654497 - [dbus] use-after-free in ensure_dbus_connection()
[dbus] use-after-free in ensure_dbus_connection()
Status: RESOLVED FIXED
Product: GConf
Classification: Deprecated
Component: gconf
3.1.x
Other Linux
: Normal normal
: ---
Assigned To: GConf Maintainers
GConf Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-12 18:24 UTC by Simon McVittie
Modified: 2011-07-13 09:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (953 bytes, patch)
2011-07-12 18:25 UTC, Simon McVittie
accepted-commit_now Details | Review

Description Simon McVittie 2011-07-12 18:24:46 UTC
I tried using the D-Bus-using version of GConf under valgrind, with an instrumented version of libdbus which stops trying to be clever about re-using allocated memory [1].

There are several use-after-frees whose backtrace can be simplified to:

==5141== Invalid read of size 1
==5141==    at 0x4836718: strlen (mc_replace_strmem.c:282)
==5141==    by 0x60E7DFB: g_strdup (gstrfuncs.c:101)
==5141==    by 0x600E213: ensure_database (gconf-dbus.c:370)
[... some stuff ...]
==5141==  Address 0x771bd7d is 5 bytes inside a block of size 40 free'd
==5141==    at 0x4834540: free (vg_replace_malloc.c:366)
==5141==    by 0x4BDF633: _dbus_string_free (dbus-string.c:270)
==5141==    by 0x4BAD367: dbus_message_finalize (dbus-message.c:1138)
==5141==    by 0x600E1E3: ensure_database (gconf-dbus.c:557)
[... the same stuff ...]

These are GConf's fault. They exist but aren't visible to valgrind with the
normal libdbus, because libdbus normally recycles messages from a free-list,
without giving them back to the system malloc machinery.

Here is the offending code:

  dbus_message_get_args (reply,
                         NULL,
                         DBUS_TYPE_STRING, &db,
                         DBUS_TYPE_INVALID);

  dbus_message_unref (reply);

  if (db == NULL)
    {
      /* ... handle error ... */
    }

  gconf_engine_set_database (conf, db);

If the last quoted line is reached, @db points into @reply - which has potentially already been freed.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=37286
Comment 1 Simon McVittie 2011-07-12 18:25:46 UTC
Created attachment 191843 [details] [review]
patch
Comment 2 Ross Burton 2011-07-12 20:43:36 UTC
Review of attachment 191843 [details] [review]:

Ooh, hot instrumented DBus action.  Great, thanks, please commit.
Comment 3 Simon McVittie 2011-07-13 09:04:37 UTC
Fixed in master, 408fa0e