GNOME Bugzilla – Bug 740772
Use-after-free when adding attachments to events
Last modified: 2014-11-27 11:58:49 UTC
Spillover from another crash bug, I have created this one for an apparently different condition. While using the option to convert a meeting to an appointment in the Outlook calendar, there are occasional crashes, strange meetings popping up that have unprintable characters for the title, etc. Running with Valgrind produced the traceback below. Just a quick glance of the code looks like ews_create_attachments_cb calls ews_cal_modify_object with some callback data, then immediately and unconditionally frees that callback before ews_cal_modify_object_cb has a chance to use it. ==10835== Invalid read of size 1 ==10835== at 0x4C2CB82: strlen (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCBAB012: g_strdup (gstrfuncs.c:355) ==10835== by 0x24893FA4: ews_cal_modify_object_cb (e-cal-backend-ews.c:1813) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xC9029AB: g_cclosure_marshal_generic_va (gclosure.c:1541) ==10835== Address 0x3cf20ee0 is 0 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== ==10835== Invalid read of size 1 ==10835== at 0x4C2CB94: strlen (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCBAB012: g_strdup (gstrfuncs.c:355) ==10835== by 0x24893FA4: ews_cal_modify_object_cb (e-cal-backend-ews.c:1813) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xC9029AB: g_cclosure_marshal_generic_va (gclosure.c:1541) ==10835== Address 0x3cf20ee1 is 1 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== ==10835== Invalid read of size 8 ==10835== at 0x4C2E320: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCBAB02C: UnknownInlinedFun (string3.h:51) ==10835== by 0xCBAB02C: g_strdup (gstrfuncs.c:357) ==10835== by 0x24893FA4: ews_cal_modify_object_cb (e-cal-backend-ews.c:1813) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xC9029AB: g_cclosure_marshal_generic_va (gclosure.c:1541) ==10835== Address 0x3cf20ee0 is 0 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== ==10835== Invalid read of size 8 ==10835== at 0x4C2E32E: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCBAB02C: UnknownInlinedFun (string3.h:51) ==10835== by 0xCBAB02C: g_strdup (gstrfuncs.c:357) ==10835== by 0x24893FA4: ews_cal_modify_object_cb (e-cal-backend-ews.c:1813) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xC9029AB: g_cclosure_marshal_generic_va (gclosure.c:1541) ==10835== Address 0x3cf20ef0 is 16 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== ==10835== Invalid read of size 1 ==10835== at 0x4C2E3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCBAB02C: UnknownInlinedFun (string3.h:51) ==10835== by 0xCBAB02C: g_strdup (gstrfuncs.c:357) ==10835== by 0x24893FA4: ews_cal_modify_object_cb (e-cal-backend-ews.c:1813) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xC9029AB: g_cclosure_marshal_generic_va (gclosure.c:1541) ==10835== Address 0x3cf20f78 is 152 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== ==10835== Invalid free() / delete / delete[] / realloc() ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x24893E83: ews_cal_modify_object_cb (e-cal-backend-ews.c:1822) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835== Address 0x3cf20ee0 is 0 bytes inside a block of size 153 free'd ==10835== at 0x4C2ACE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==10835== by 0xCB927FE: g_free (gmem.c:190) ==10835== by 0x2489131B: e_cal_backend_ews_async_data_free (e-cal-backend-ews.c:342) ==10835== by 0x248976C0: ews_create_attachments_cb (e-cal-backend-ews.c:1395) ==10835== by 0xC5ED806: g_simple_async_result_complete (gsimpleasyncresult.c:763) ==10835== by 0xC5ED868: complete_in_idle_cb (gsimpleasyncresult.c:775) ==10835== by 0xCB8CAEA: g_main_dispatch (gmain.c:3111) ==10835== by 0xCB8CAEA: g_main_context_dispatch (gmain.c:3710) ==10835== by 0xCB8CE87: g_main_context_iterate.isra.29 (gmain.c:3781) ==10835== by 0xCB8D1B1: g_main_loop_run (gmain.c:3975) ==10835== by 0x52E95E1: dbus_server_run_server (e-dbus-server.c:230) ==10835== by 0xDD9CD5F: ffi_call_unix64 (in /usr/lib64/libffi.so.6.0.2) ==10835== by 0xDD9C7D0: ffi_call (in /usr/lib64/libffi.so.6.0.2) ==10835==
Just for a record, the mentioned other bug is bug #701138.
I see what's going on here. There was added an attachment and it was saved first. Then was initiated an actual modify on the item, but with an itemid which was freed right after it was invoked, later causing user-after-free and even later double-free. I also fixed one memory leak in the related code. Created commit c5eb624 in ews master (3.13.9+) [1] Created commit 278fe7e in ews evolution-ews-3-12 (3.12.9+) [1] https://git.gnome.org/browse/evolution-ews/commit/?id=c5eb624