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 783002 - Server-side async methods do not keep arrays alive until the call completes
Server-side async methods do not keep arrays alive until the call completes
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: D-Bus
unspecified
Other All
: Normal critical
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-05-23 15:31 UTC by Ole André Vadla Ravnås
Modified: 2018-04-15 17:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase (1.88 KB, patch)
2017-05-23 22:09 UTC, Ole André Vadla Ravnås
none Details | Review
codegen: Keep arrays alive during async server method calls (12.76 KB, patch)
2017-05-24 00:48 UTC, Ole André Vadla Ravnås
none Details | Review
codegen: Keep arrays alive during async server method calls (12.89 KB, patch)
2017-05-24 01:15 UTC, Ole André Vadla Ravnås
none Details | Review
codegen: Keep arrays alive during async server method calls (13.15 KB, patch)
2018-03-28 17:22 UTC, Rico Tzschichholz
committed Details | Review

Description Ole André Vadla Ravnås 2017-05-23 15:31:21 UTC
This results in use-after-free.

I'm working on a patch fixing this.
Comment 1 Daniel Espinosa 2017-05-23 20:55:32 UTC
I would like to get more details.

Because, if you talk about a Server and asynchronous, may we need to talk about to keep user status data alive in different ways, like a cookie at client side, a temporary file at server or in a database. There are plenty of examples.

Now this bug can be reproduced in a simple program, without​ a server environment?
Comment 2 Ole André Vadla Ravnås 2017-05-23 22:09:35 UTC
Created attachment 352461 [details] [review]
Testcase

Daniel: Sorry for the brief explanation. This test-case should hopefully make
things a bit clearer.
Comment 3 Ole André Vadla Ravnås 2017-05-24 00:48:24 UTC
Created attachment 352463 [details] [review]
codegen: Keep arrays alive during async server method calls

When calling a co-routine it is the caller's responsibility to ensure
that arrays stay alive for the duration of the call. The GDBus server
code emitted did not do this, resulting in use-after-free.
Comment 4 Daniel Espinosa 2017-05-24 00:58:58 UTC
This example is a little complicate.

I assume your problem is over array argument lifetime, after yield.

In other asynchronous methods I have, yield makes no other Variables goes out of scope.

If an array is going out of scope and is correct because arrays' memory management, then valac should warn.

My obvious solution here is use a reference counting objects to save memory an copy processing.
Comment 5 Ole André Vadla Ravnås 2017-05-24 01:08:56 UTC
(In reply to Daniel Espinosa from comment #4)
> This example is a little complicate.
> 
> I assume your problem is over array argument lifetime, after yield.
> 
> In other asynchronous methods I have, yield makes no other Variables goes
> out of scope.
> 
> If an array is going out of scope and is correct because arrays' memory
> management, then valac should warn.
> 
> My obvious solution here is use a reference counting objects to save memory
> an copy processing.

Arrays are special in co-routines, Vala will not make a copy of them. It
used to do this, but this made it impossible to implement GIO APIs where
a co-routine is given an array and asked to write into it.

Because of this it is the caller's responsibility to keep arrays alive
while an async call is still in progress. In the case of Vala-generated
GDBus server code, the code it generates is such a caller whenever dealing
with a co-routine. So this means the code it generates needs to keep arrays
alive until the call completes. This is only an issue if the co-routine
actually uses the array argument after the first yield.
Comment 6 Ole André Vadla Ravnås 2017-05-24 01:15:40 UTC
Created attachment 352465 [details] [review]
codegen: Keep arrays alive during async server method calls

Fixed handling of out parameters. All tests green.
Comment 7 Rico Tzschichholz 2018-03-28 17:22:56 UTC
Created attachment 370254 [details] [review]
codegen: Keep arrays alive during async server method calls

When calling a co-routine it is the caller's responsibility to ensure
that arrays stay alive for the duration of the call. The GDBus server
code emitted did not do this, resulting in use-after-free.
Comment 8 Rico Tzschichholz 2018-04-15 17:45:01 UTC
Attachment 370254 [details] pushed as 650415b - codegen: Keep arrays alive during async server method calls