Wayland: a keymap that fills its last page without a NUL, sent with a size past its file's end, crashes keyboard_keymap with SIGBUS #206
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#206
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Device::keyboard_keymaphands the mapped keymap toxkb_keymap_new_from_string, which reads up to the first NUL, not up to thesizethe compositor sent.wl_keyboard.keymappromises "a null-terminated string", so this takes a compositor that breaks the promise. Since #167's fix the handler ignores any other keymap it cannot load, but it does not survive this one. Line numbers refer to148ed01.Details
implementations/Crafter.Graphics-Device.cpp:693:mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0), with the size the compositor gave.:706:xkb_keymap_new_from_string(xkb_context, static_cast<const char*>(map), ...). Nothing bounds the read bysize, and nothing comparessizewith the size of the file.sizeis larger than the file, the next page of the mapping lies past the end of the file, and reading it raises SIGBUS. When it is not, the read runs past the end of the mapping, into whatever is mapped there (not tried).Concrete case
The handler's two calls in a standalone program, on a memfd, with libxkbcommon 1.13.2 on Linux 7.2.11: 4096 bytes of
xwith no NUL, mapped with a size of 8192, die of signal 7 (SIGBUS) inxkb_keymap_new_from_string; 100 bytes ofxwith no NUL, mapped with a size of 100, return null. Not run through the library or against a compositor.Suggested fix
Bound the read:
xkb_keymap_new_from_buffer(xkb_context, text, strnlen(text, size), ...), after anfstatof the fd that ignores a keymap whosesizeis past the end of its file.