wayland/src
Demi Marie Obenour 398e1297ee connection: Do not busy-loop if a message exceeds the buffer size
If the length of a message exceeds the maximum length of the buffer, the
buffer size will reach its maximum value and stay there forever, with no
message ever being successfully processed.  Since libwayland uses
level-triggered epoll, this will cause the compositor to loop forever
and consume CPU time.  In libwayland 1.22 and below, there was an
explicit check that caused messages exceeding 4096 bytes to result in an
EOVERFLOW error, preventing the loop.  However, this check was removed
between d074d52902 ("connection: Dynamically resize connection buffers").

To prevent this problem, always limit the size of messages to 4096 bytes.
Since the default and minimum buffer size is 4096 bytes, this ensures
that a single message will always fit in the buffer.  It would be
possible to allow larger messages if the buffer size was larger, but the
maximum size of a message should not depend on the buffer size chosen by
the compositor.

Rejecting messages that exceed 4092 bytes seems to have the advantage of
reserving 4 bits, not 3, in the size field for future use.  However,
message sizes in the range [0x0, 0x7] are invalid, so one can obtain a
fourth bit by negating the meaning of bit 12 if bits 0 through 11
(inclusive) are 0.  Allowing 4096-byte messages provides the far more
important advantage that regressions compared to 1.22 are impossible
and regressions compared to 1.23 are extremely unlikely.  The only case
where a regression is possible is:

- The receiving side is using libwayland 1.23.
- The sending side is either using libwayland 1.23 or is not using
  libwayland.
- The sender sends a message exceeding 4096 bytes.
- If the sender of the large message is the client, the server has
  increased the buffer size from the default value.

This combination is considered extremely unlikely, as libwayland 1.22
and below would disconnect upon receiving such a large message.
4096-byte messages, however, have always worked, so there was no reason
to avoid sending them.

Fixes: d074d52902 ("connection: Dynamically resize connection buffers").
Fixes: #494
Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
(cherry picked from commit adf84614ca)
2025-06-21 13:42:05 +02:00
..
.gitignore ignore: Add *.dtd.embed 2016-03-10 22:24:20 -08:00
connection.c connection: fix segfault in wl_closure_invoke() 2025-06-08 20:53:38 +02:00
embed.py build: replace assembly embedding with Python script 2021-05-10 22:08:45 +00:00
event-loop.c event-loop: Use timespec utils instead of hand-rolling our own 2025-02-04 14:09:51 +00:00
meson.build build: Add -lm to pkg-config dependencies 2025-02-05 06:52:53 +00:00
scanner.c scanner: use separate guards for validator functions 2025-02-23 23:38:15 +01:00
timespec-util.h timespec: Implement saturating timespec substraction 2025-02-04 14:09:51 +00:00
wayland-client-core.h client: add wl_proxy_get_interface() 2025-05-20 20:31:16 +00:00
wayland-client.c connection: Do not busy-loop if a message exceeds the buffer size 2025-06-21 13:42:05 +02:00
wayland-client.h doc: Formalize file comment in wayland-client.h, wayland-server.h 2016-05-11 11:03:27 -07:00
wayland-os.c build: fix build and provide compat for OpenBSD 2024-02-21 15:46:41 +00:00
wayland-os.h shm: Add mmap+memmove fallback if mremap() does not exist 2021-09-10 11:35:54 +00:00
wayland-private.h connection: Do not busy-loop if a message exceeds the buffer size 2025-06-21 13:42:05 +02:00
wayland-server-core.h server: add wl_resource_get_interface() 2025-05-20 20:31:16 +00:00
wayland-server-private.h Move wl_priv_signal to wayland-server-private.h 2019-11-06 08:24:14 -06:00
wayland-server.c connection: Do not busy-loop if a message exceeds the buffer size 2025-06-21 13:42:05 +02:00
wayland-server.h Put WL_DEPRECATED in front of the function declarations 2024-08-09 20:25:11 +00:00
wayland-shm.c shm: linkify function references in docs 2025-05-20 20:14:52 +00:00
wayland-util.c util: convert macros to inline functions 2024-03-28 17:56:34 +01:00
wayland-util.h connection: Do not busy-loop if a message exceeds the buffer size 2025-06-21 13:42:05 +02:00
wayland-version.h.in src: Update boilerplate from MIT X11 license to MIT Expat license 2015-06-12 15:31:24 -07:00