Tomas Bzatek 6b698a
From d205057296957d6064825252a3d3377e809d6fed Mon Sep 17 00:00:00 2001
Tomas Bzatek 6b698a
From: Tomas Bzatek <tbzatek@redhat.com>
Tomas Bzatek 6b698a
Date: Wed, 6 Oct 2021 17:12:13 +0200
Tomas Bzatek 6b698a
Subject: [PATCH] udiskslinuxmountoptions: Do not free static daemon resources
Tomas Bzatek 6b698a
Tomas Bzatek 6b698a
The GResource instance returned from udisks_daemon_resources_get_resource()
Tomas Bzatek 6b698a
that calls g_static_resource_get_resource() internally is marked as
Tomas Bzatek 6b698a
'(transfer none)' and should not be freed. In fact that causes double
Tomas Bzatek 6b698a
free inside the g_static_resource_fini() atexit handler leading
Tomas Bzatek 6b698a
to memory corruption causing random failures of further atexit
Tomas Bzatek 6b698a
handlers such as cryptsetup and openssl destructors.
Tomas Bzatek 6b698a
Tomas Bzatek 6b698a
 Invalid read of size 4
Tomas Bzatek 6b698a
    at 0x4BB03A4: g_resource_unref (gresource.c:527)
Tomas Bzatek 6b698a
    by 0x4BB2150: g_static_resource_fini (gresource.c:1449)
Tomas Bzatek 6b698a
    by 0x4010ADB: _dl_fini (dl-fini.c:139)
Tomas Bzatek 6b698a
    by 0x4EF0DF4: __run_exit_handlers (exit.c:113)
Tomas Bzatek 6b698a
    by 0x4EF0F6F: exit (exit.c:143)
Tomas Bzatek 6b698a
    by 0x4ED9566: __libc_start_call_main (libc_start_call_main.h:74)
Tomas Bzatek 6b698a
    by 0x4ED960B: __libc_start_main@@GLIBC_2.34 (libc-start.c:409)
Tomas Bzatek 6b698a
    by 0x128774: (below main) (in udisks/src/.libs/udisksd)
Tomas Bzatek 6b698a
  Address 0x5cc5fc0 is 0 bytes inside a block of size 16 free'd
Tomas Bzatek 6b698a
    at 0x48430E4: free (vg_replace_malloc.c:755)
Tomas Bzatek 6b698a
    by 0x4DB10BC: g_free (gmem.c:199)
Tomas Bzatek 6b698a
    by 0x4BB2148: g_static_resource_fini (gresource.c:1448)
Tomas Bzatek 6b698a
    by 0x4010ADB: _dl_fini (dl-fini.c:139)
Tomas Bzatek 6b698a
    by 0x4EF0DF4: __run_exit_handlers (exit.c:113)
Tomas Bzatek 6b698a
    by 0x4EF0F6F: exit (exit.c:143)
Tomas Bzatek 6b698a
    by 0x4ED9566: __libc_start_call_main (libc_start_call_main.h:74)
Tomas Bzatek 6b698a
    by 0x4ED960B: __libc_start_main@@GLIBC_2.34 (libc-start.c:409)
Tomas Bzatek 6b698a
    by 0x128774: (below main) (in udisks/src/.libs/udisksd)
Tomas Bzatek 6b698a
  Block was alloc'd at
Tomas Bzatek 6b698a
    at 0x484086F: malloc (vg_replace_malloc.c:380)
Tomas Bzatek 6b698a
    by 0x4DB47A8: g_malloc (gmem.c:106)
Tomas Bzatek 6b698a
    by 0x4BB19C7: UnknownInlinedFun (gresource.c:545)
Tomas Bzatek 6b698a
    by 0x4BB19C7: g_resource_new_from_data (gresource.c:613)
Tomas Bzatek 6b698a
    by 0x4BB1A88: register_lazy_static_resources_unlocked (gresource.c:1374)
Tomas Bzatek 6b698a
    by 0x4BB218C: UnknownInlinedFun (gresource.c:1393)
Tomas Bzatek 6b698a
    by 0x4BB218C: UnknownInlinedFun (gresource.c:1387)
Tomas Bzatek 6b698a
    by 0x4BB218C: g_static_resource_get_resource (gresource.c:1472)
Tomas Bzatek 6b698a
    by 0x14F6A3: UnknownInlinedFun (udisks-daemon-resources.c:284)
Tomas Bzatek 6b698a
    by 0x14F6A3: udisks_linux_mount_options_get_builtin (udiskslinuxmountoptions.c:612)
Tomas Bzatek 6b698a
    by 0x12CC6E: udisks_daemon_constructed (udisksdaemon.c:441)
Tomas Bzatek 6b698a
    by 0x4D1ED96: g_object_new_internal (gobject.c:1985)
Tomas Bzatek 6b698a
    by 0x4D20227: g_object_new_valist (gobject.c:2288)
Tomas Bzatek 6b698a
    by 0x4D2075C: g_object_new (gobject.c:1788)
Tomas Bzatek 6b698a
    by 0x129A5F: udisks_daemon_new (udisksdaemon.c:619)
Tomas Bzatek 6b698a
    by 0x129AD5: on_bus_acquired (main.c:63)
Tomas Bzatek 6b698a
    by 0x4C35C95: connection_get_cb.lto_priv.0 (gdbusnameowning.c:504)
Tomas Bzatek 6b698a
    by 0x4BD3F99: g_task_return_now (gtask.c:1219)
Tomas Bzatek 6b698a
    by 0x4BD419A: UnknownInlinedFun (gtask.c:1289)
Tomas Bzatek 6b698a
    by 0x4BD419A: g_task_return (gtask.c:1245)
Tomas Bzatek 6b698a
    by 0x4C31D51: bus_get_async_initable_cb (gdbusconnection.c:7433)
Tomas Bzatek 6b698a
    by 0x4BD3F99: g_task_return_now (gtask.c:1219)
Tomas Bzatek 6b698a
    by 0x4BD3FDC: complete_in_idle_cb (gtask.c:1233)
Tomas Bzatek 6b698a
    by 0x4DA852A: g_idle_dispatch (gmain.c:5897)
Tomas Bzatek 6b698a
    by 0x4DAC33E: UnknownInlinedFun (gmain.c:3381)
Tomas Bzatek 6b698a
    by 0x4DAC33E: g_main_context_dispatch (gmain.c:4099)
Tomas Bzatek 6b698a
---
Tomas Bzatek 6b698a
 src/udiskslinuxmountoptions.c | 1 -
Tomas Bzatek 6b698a
 1 file changed, 1 deletion(-)
Tomas Bzatek 6b698a
Tomas Bzatek 6b698a
diff --git a/src/udiskslinuxmountoptions.c b/src/udiskslinuxmountoptions.c
Tomas Bzatek 6b698a
index 7729d4015..819c9ba96 100644
Tomas Bzatek 6b698a
--- a/src/udiskslinuxmountoptions.c
Tomas Bzatek 6b698a
+++ b/src/udiskslinuxmountoptions.c
Tomas Bzatek 6b698a
@@ -614,7 +614,6 @@ udisks_linux_mount_options_get_builtin (void)
Tomas Bzatek 6b698a
                                                "/org/freedesktop/UDisks2/data/builtin_mount_options.conf",
Tomas Bzatek 6b698a
                                                G_RESOURCE_LOOKUP_FLAGS_NONE,
Tomas Bzatek 6b698a
                                                &error);
Tomas Bzatek 6b698a
-  g_resource_unref (daemon_resource);
Tomas Bzatek 6b698a
 
Tomas Bzatek 6b698a
   if (builtin_opts_bytes == NULL)
Tomas Bzatek 6b698a
     {