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 795193 - Race in _kqsub_cancel() leads to a segfault
Race in _kqsub_cancel() leads to a segfault
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other OpenBSD
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-04-12 10:17 UTC by Martin Pieuchot
Modified: 2018-04-23 19:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix a race in _kqsub_cancel() (1.86 KB, patch)
2018-04-12 10:17 UTC, Martin Pieuchot
committed Details | Review

Description Martin Pieuchot 2018-04-12 10:17:53 UTC
Created attachment 370840 [details] [review]
Fix a race in _kqsub_cancel()

The kqueue(2) rewrite commited in aa39a0557c679fc345b0ba72a87c33152eb8ebcd introduced an obvious race reported on bugs@openbsd.org:
  https://marc.info/?l=openbsd-bugs&m=152331924527698&w=2

The problem is that the current order of operations in _kqsub_cancel() is incorrect.  _km_remove() must be called before freeing `sub->deps' otherwise
the timeout might modify the list while it is beeing freed.

While here we should remove the event from the kqueue(2) and close the file
descriptor first.  Because that what remove pending events from the queue.
Here's what the kevent(2) manual says:
  
   "Calling close() on a file descriptor will remove any kevents that
    reference the descriptor."

The attached patch do that and prevent the segfault reported above.  It is
also committed in OpenBSD's port tree.
Comment 1 Antoine Jacoutot 2018-04-23 17:01:45 UTC
I can confirm this fixes the sefgault I've been seeing on OpenBSD.
Thanks Martin.
Can we get an OK^LGTM for pushing this?
Thanks :-)
Comment 2 Philip Withnall 2018-04-23 19:07:30 UTC
Review of attachment 370840 [details] [review]:

Sure. Thanks for reviewing and testing it.
Comment 3 Philip Withnall 2018-04-23 19:09:18 UTC
Pushed to master.
Comment 4 Philip Withnall 2018-04-23 19:10:43 UTC
git-bz is not behaving. Pushed as:

ab179184b (HEAD -> master, origin/master, origin/HEAD) Reorder operations in _kqsub_cancel() to prevent races.