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 778540 - fd passing on dbus messages may trigger glib warnings
fd passing on dbus messages may trigger glib warnings
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: D-Bus
0.35.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-02-12 22:23 UTC by Carlos Garnacho
Modified: 2018-03-21 16:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdbus: Initialize intermediate variables (2.60 KB, patch)
2017-02-12 22:24 UTC, Carlos Garnacho
committed Details | Review
gdbus: Ensure extracted data from the GVariant is freed on error (1.67 KB, patch)
2017-02-12 22:24 UTC, Carlos Garnacho
committed Details | Review
gdbus: Handle errors when extracting fds from dbus messages (4.92 KB, patch)
2017-02-12 22:24 UTC, Carlos Garnacho
none Details | Review
gdbus: Handle errors when extracting fds from dbus messages (5.14 KB, patch)
2017-02-13 10:00 UTC, Carlos Garnacho
committed Details | Review
tests: Add test for dbus fd passing failures (3.17 KB, patch)
2017-02-18 14:38 UTC, Carlos Garnacho
committed Details | Review
dbus: Account for _reply_message being NULL in error paths (2.22 KB, patch)
2017-02-18 14:38 UTC, Carlos Garnacho
none Details | Review
dbus: Move send_message() call before _error label (3.29 KB, patch)
2017-02-18 15:13 UTC, Carlos Garnacho
committed Details | Review
tests: Add tests around DBus server argument handling (1.05 KB, patch)
2017-03-06 12:35 UTC, Carlos Garnacho
none Details | Review
codegen: Only add _error path if there's parameters that require unref (1.14 KB, patch)
2017-03-06 12:35 UTC, Carlos Garnacho
committed Details | Review
codegen: Avoid early return on sync dbus methods returning an error (1.02 KB, patch)
2017-03-06 12:35 UTC, Carlos Garnacho
committed Details | Review
tests: Add tests around DBus server argument handling (1.79 KB, patch)
2017-03-06 12:41 UTC, Carlos Garnacho
committed Details | Review

Description Carlos Garnacho 2017-02-12 22:23:47 UTC
In tracker there's this test that basically attempts a DOS over tracker-store:

https://git.gnome.org/browse/tracker/tree/tests/libtracker-sparql/tracker-gb-737023.c

It does trigger many asynchronous queries that require fd passing, reaching to a point where tracker-store has more queries open than fds available. The test was introduced as this behavior used to crash tracker-store, but even if this was fixed, the running tracker-store still triggers a bunch of:

(tracker-store:14796): GLib-GIO-CRITICAL **: g_unix_fd_list_get: assertion 'G_IS_UNIX_FD_LIST (list)' failed

(tracker-store:14796): GLib-GIO-CRITICAL **: g_unix_output_stream_new: assertion 'fd != -1' failed

This happens in the vala dbus wrappers, and tracker-store can do nothing to prevent those. I'm attaching some patches adding proper error handling on the dbus wrapper paths involved in fd passing.
Comment 1 Carlos Garnacho 2017-02-12 22:24:26 UTC
Created attachment 345589 [details] [review]
gdbus: Initialize intermediate variables

Those may be left uninitialized after error handling paths are introduced,
so invalid data might be attempted to be freed later on.
Comment 2 Carlos Garnacho 2017-02-12 22:24:33 UTC
Created attachment 345590 [details] [review]
gdbus: Ensure extracted data from the GVariant is freed on error

This will make extracted variables properly freed when extracting those
fails at some point.
Comment 3 Carlos Garnacho 2017-02-12 22:24:38 UTC
Created attachment 345591 [details] [review]
gdbus: Handle errors when extracting fds from dbus messages

On the right situations (eg. fd exhaustion), both
g_dbus_message_get_unix_fd_list() and g_unix_fd_list_get() should be
considered failable here. Add proper error handling to avoid triggering
glib warnings.
Comment 4 Rico Tzschichholz 2017-02-13 07:12:05 UTC
Tracker fails to build with these patches

http://paldo.org:8010/builders/vala-staging/builds/199/steps/tracker/logs/stdio
Comment 5 Carlos Garnacho 2017-02-13 10:00:54 UTC
Created attachment 345607 [details] [review]
gdbus: Handle errors when extracting fds from dbus messages

On the right situations (eg. fd exhaustion), both
g_dbus_message_get_unix_fd_list() and g_unix_fd_list_get() should be
considered failable here. Add proper error handling to avoid triggering
glib warnings.
Comment 6 Carlos Garnacho 2017-02-13 10:02:39 UTC
I apparently didn't delete the vala timestamp files before rebuilding tracker after my last cleanup. This last patch fixes the build error.
Comment 7 Rico Tzschichholz 2017-02-13 11:45:00 UTC
Thanks!

Could you add a small test-case as well? At least to test the changed code-paths.
Comment 8 Carlos Garnacho 2017-02-18 14:38:50 UTC
Created attachment 346130 [details] [review]
tests: Add test for dbus fd passing failures

The server will exhaust all fds before the fd list in the dbus
request is opened. We do expect it to fail in the client.
Comment 9 Carlos Garnacho 2017-02-18 14:38:57 UTC
Created attachment 346131 [details] [review]
dbus: Account for _reply_message being NULL in error paths

Commit 09e6818d01 changed dbus server paths so requests fell back
to freeing allocated memory on errors. However certain kinds of
dbus replies issue a final g_dbus_connection_send_message() there.

In case of errors, _reply_message will be NULL, and the error paths
would have already issued g_dbus_method_invocation_return_gerror(),
so the g_dbus_connection_send_message() call is both unnecessary and
warns on the NULL argument. So add a NULL check for these cases.
Comment 10 Carlos Garnacho 2017-02-18 15:13:16 UTC
Created attachment 346135 [details] [review]
dbus: Move send_message() call before _error label

Commit 09e6818d01 changed dbus server paths so requests fell back
to freeing allocated memory on errors. However certain kinds of
dbus replies issue a final g_dbus_connection_send_message() there.

In case of errors, _reply_message will be NULL, and the error paths
would have already issued g_dbus_method_invocation_return_gerror(),
so the g_dbus_connection_send_message() call is both unnecessary and
warns on the NULL argument. So  move the DBus reply before the _error
label.


--- 
Alternative fix (and IMHO simpler) to attachment 346131 [details] [review].
Comment 11 Carlos Garnacho 2017-03-06 12:35:34 UTC
Created attachment 347303 [details] [review]
tests: Add tests around DBus server argument handling

Commit 09e6818d01e introduced the possibility of inserting _error
labels at the end of functions, which make C compilers angry.
This "test" (no actual tests are run, just compile correctness is
checked here) triggers some of these situations.

the "test3" abstract method is trickier though, it doesn't warn
but produces code with early returns, which in practice means
possible leaks.
Comment 12 Carlos Garnacho 2017-03-06 12:35:43 UTC
Created attachment 347304 [details] [review]
codegen: Only add _error path if there's parameters that require unref

Fixes the _error label from being set at the end of a compound statement
if there are no values to unref.
Comment 13 Carlos Garnacho 2017-03-06 12:35:49 UTC
Created attachment 347305 [details] [review]
codegen: Avoid early return on sync dbus methods returning an error

If there are arguments that need freeing, we need to fall through the
_error label, if there is any.
Comment 14 Carlos Garnacho 2017-03-06 12:41:38 UTC
Created attachment 347308 [details] [review]
tests: Add tests around DBus server argument handling

Commit 09e6818d01e introduced the possibility of inserting _error
labels at the end of functions, which make C compilers angry.
This "test" (no actual tests are run, just compile correctness is
checked here) triggers some of these situations.

the "test3" abstract method is trickier though, it doesn't warn
but produces code with early returns, which in practice means
possible leaks.
Comment 15 Rico Tzschichholz 2017-03-06 14:21:57 UTC
Hopefully for good now.