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 724402 - memory corruption in mutter keybinding name causes segfault
memory corruption in mutter keybinding name causes segfault
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
3.10.x
Other Linux
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2014-02-15 08:13 UTC by Tim Cuthbertson
Modified: 2014-12-29 09:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
valgrind log (6.20 KB, text/plain)
2014-02-25 21:50 UTC, Tim Cuthbertson
  Details
valgrind log (111.91 KB, text/plain)
2014-02-25 23:13 UTC, Tim Cuthbertson
  Details
keybindings: fix invalid read after a keybinding is removed (2.70 KB, patch)
2014-02-25 23:48 UTC, Giovanni Campagna
committed Details | Review

Description Tim Cuthbertson 2014-02-15 08:13:49 UTC
After a change to shellshape (my gnome-shell extension), I started getting segfaults in gnome-shell sometimes when using shellshape keybindings (it adds a bunch of global keyboard shortcuts to control window tiling). I would occasionally see errors like:

(gnome-shell:24457): Gjs-WARNING **: JS ERROR: InternalError: buffer too small
WindowManager<._filterKeybinding@/usr/share/gnome-shell/js/ui/windowManager.js:930

And:

(gnome-shell:9979): Gjs-WARNING **: JS ERROR: TypeError: malformed UTF-8 character sequence at offset 0
WindowManager<._filterKeybinding@/usr/share/gnome-shell/js/ui/windowManager.js:930

After enabling debug messaging for the keybinding mutter topic, I saw the following output when I reproduced the crash:

(gnome-shell:9979): Gjs-WARNING **: JS ERROR: TypeError: malformed UTF-8 character sequence at offset 0
WindowManager<._filterKeybinding@/usr/share/gnome-shell/js/ui/windowManager.js:930
KEYBINDINGS: Binding keycode 0x34 mask 0x40 matches event 0x34 state 0x40
KEYBINDINGS: Running handler for �\

(the name above was printed as "<unprintable>/<unprintable>" in my terminal originally, which is why I assume this is a memory issue - perhaps the keybinding structure is being kept around after its name is freed).


The change that I made in shellshape to uncover this issue has to do with how the extension is enabled / disabled. Previously, I cleaned up everything nicely on disable() and basically had a fresh start on enable(). But because screen lock disables and re-enables all extensions[0], I've had to keep much of the extension's state around in memory even after a disable(). I'm still removing all keybindings on disable() and re-adding them on enable(), so I can't see why this would cause this bug. But it does, quite reproducably.

The code which causes the issue is at [1] - the commit that uncovered the problem is [2]. I'm afraid I was unable to create a smaller test case that reproduces the problem.

[0] https://github.com/gfxmonk/shellshape/issues/107
[1] https://github.com/gfxmonk/shellshape/tree/lock-persist
[2] https://github.com/gfxmonk/shellshape/commit/232216d55332997e301d8dd05f19687890cfd546
Comment 1 Tim Cuthbertson 2014-02-15 08:15:40 UTC
Oh, also: the crash only ever seems to happen after returning from a screen lock. Disabling and re-enabling the extension (with gnome-tweak-tool) continues to work fine.
Comment 2 Giovanni Campagna 2014-02-24 16:14:58 UTC
Can you at least run the shell under valgrind and see where you start getting memory errors?
Comment 3 Tim Cuthbertson 2014-02-25 21:49:32 UTC
I'm afraid not - I tried, but it doesn't get so far as drawing the screen once (i.e no windows decorations ever appear) when running under valgrind - it gets an error about an unknown instruction. I've attached the valgrind log in case that's any use.
Comment 4 Tim Cuthbertson 2014-02-25 21:50:03 UTC
Created attachment 270329 [details]
valgrind log
Comment 5 Giovanni Campagna 2014-02-25 22:01:32 UTC
(In reply to comment #3)
> I'm afraid not - I tried, but it doesn't get so far as drawing the screen once
> (i.e no windows decorations ever appear) when running under valgrind - it gets
> an error about an unknown instruction. I've attached the valgrind log in case
> that's any use.

Mh, you can probably try to run with GJS_DISABLE_JIT=1, which will disable code generation.
Comment 6 Tim Cuthbertson 2014-02-25 23:13:17 UTC
Created attachment 270334 [details]
valgrind log
Comment 7 Tim Cuthbertson 2014-02-25 23:15:50 UTC
(In reply to comment #5)
> Mh, you can probably try to run with GJS_DISABLE_JIT=1, which will disable code
> generation.

Thanks, that worked. I've updated valgrind.log with a successful run. I couldn't get it to crash, presumably because valgrind handles memory differently. I did get memory errors reported in `change_binding_keygrabs` though, which sounds relevant. Hopefully someone more familiar with the code and/or valgrind can make better sense of this than I can...
Comment 8 Giovanni Campagna 2014-02-25 23:48:45 UTC
Created attachment 270336 [details] [review]
keybindings: fix invalid read after a keybinding is removed

The handler pointer is dangling in MetaKeyBinding until
rebuild_key_binding_table() is run, so we can't dereference it.
Because we only need the flags at ungrab time, store a copy
in the MetaKeyBinding structure.
Comment 9 Giovanni Campagna 2014-02-25 23:49:34 UTC
This is what I see from valgrind as invalid read. I don't see how that could cause a segfault, though...
Comment 10 Rui Matos 2014-02-26 14:13:26 UTC
Review of attachment 270336 [details] [review]:

Indeed, makes sense. I'm re-working keybindings.c a bit for wayland right now, but this is self-contained enough that I can easily rebase.
Comment 11 Giovanni Campagna 2014-02-26 14:18:49 UTC
Attachment 270336 [details] pushed as 682d6f9 - keybindings: fix invalid read after a keybinding is removed
Comment 12 Tim Cuthbertson 2014-02-27 09:30:36 UTC
Hi,

Thanks for the patch Giovanni. I applied & tested it today, and you're right, it wasn't the cause of the segfault (i.e I am still getting the crash).

I tried a number of times to reproduce the issue under valgrind with this patch, but couldn't, so I'm afraid I still can't provide any additional details. I can  provide information on how to install the broken branch of shellshape, if that helps others reproduce the issue?
Comment 13 Jasper St. Pierre (not reading bugmail) 2014-12-29 05:43:39 UTC
Are you still seeing this? I do remember fixing a memory corruption in keybindings.c over the summer.
Comment 14 Tim Cuthbertson 2014-12-29 09:37:52 UTC
Thanks for the reminder Jasper, I've had this code re-enabled in shellshape for ~6 months now[0], and haven't seen any of these crashes. So it definitely sounds like you've fixed it - thanks!

[0]: https://github.com/gfxmonk/shellshape/issues/107#issuecomment-46961165