Fedora Account System
Red Hat Associate
Red Hat Customer
Disclaimer: Community trackers are created by Red Hat Product Security team on a best effort basis. Package maintainers are required to ascertain if the flaw indeed affects their package, before starting the update process. ProcXTestFakeInput copied DeviceValuator fields into a fixed stack array (MAX_VALUATORS) before checking that the valuator range fits. Enough DeviceValuator events write past that array, which can crash the server or corrupt stack memory. Acknowledgement: Acts1631 <acts1631kjv> * Patch From e142b5228ad656c6476230ec2511ee9c6b82f7a1 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan <ofourdan> Date: Tue, 6 Oct 2026 12:06:03 +0200 Subject: [PATCH xserver 16/16] test/pyxtest: add QueryImageAttributes negative size regression test Query NV12 attributes with overflow dimensions so a negative adaptor size is rejected with BadValue instead of being cast to CARD32. Related to CVE-2026-109903 Signed-off-by: Olivier Fourdan <ofourdan> Assisted-by: AI #+begin_src diff --- test/pyxtest/test_xv.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/pyxtest/test_xv.py b/test/pyxtest/test_xv.py index e95899d89..81439056b 100644 --- a/test/pyxtest/test_xv.py +++ b/test/pyxtest/test_xv.py @@ -197,3 +197,29 @@ class TestXvQueryImageAttributes: assert resp.error_code == BadValue, ( f"Expected BadValue ({BadValue}), got {resp.error_code}" ) + + def test_negative_size(self, xserver, xv_port): + """ + When ddQueryImageAttributes() returns a negative size, the reply + would cast it to CARD32 and report a bogus data_size. + + Reject negative sizes with BadValue. + """ + xclient, opcode, port = xv_port + + xclient.send_request( + xv.QueryImageAttributesRequest( + opcode=opcode, + port=port, + id=xv.FOURCC_NV12, + width=xv.OVERFLOW_WIDTH, + height=xv.OVERFLOW_HEIGHT, + ) + ) + resp = xclient.recv_response(timeout=5.0) + + assert xserver.is_alive, "Server crashed on NV12 QueryImageAttributes" + assert isinstance(resp, X11Error), f"Expected BadValue, got {resp}" + assert resp.error_code == BadValue, ( + f"Expected BadValue ({BadValue}), got {resp.error_code}" + ) -- 2.56.0 #+end_src From f5a128c880029b48361cb64e761ddd65de00dfd0 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan <ofourdan> Date: Tue, 6 Oct 2026 12:03:10 +0200 Subject: [PATCH xserver 06/16] test/pyxtest: add XTestFakeInput valuator range regression test Send DeviceMotionNotify plus enough DeviceValuator events to exceed MAX_VALUATORS. The request must be rejected with BadValue before writing past the stack array. Related to CVE-2026-109093 v2: Make DeviceMotionNotifyEvent a class, fix MORE_EVENTS (Peter Hutterer) v3: Move serialize_event_chain() as a method in FakeInputRequest and simplify to use extend() (Peter Hutterer) Signed-off-by: Olivier Fourdan <ofourdan> Assisted-by: AI #+begin_src diff --- test/pyxtest/meson.build | 1 + test/pyxtest/proto/xtest.py | 139 +++++++++++++++++++++++++++++++++++- test/pyxtest/test_xtest.py | 73 +++++++++++++++++++ 3 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 test/pyxtest/test_xtest.py diff --git a/test/pyxtest/meson.build b/test/pyxtest/meson.build index 835a4df4e..4b1af2127 100644 --- a/test/pyxtest/meson.build +++ b/test/pyxtest/meson.build @@ -71,6 +71,7 @@ if pytest.found() 'test_xi.py', 'test_xkb.py', 'test_xres.py', + 'test_xtest.py', 'test_xv.py', ] diff --git a/test/pyxtest/proto/xtest.py b/test/pyxtest/proto/xtest.py index ef23f8601..4041e3ac8 100644 --- a/test/pyxtest/proto/xtest.py +++ b/test/pyxtest/proto/xtest.py @@ -3,7 +3,7 @@ # XTEST extension protocol request builders for security testing. import struct -from dataclasses import dataclass +from dataclasses import dataclass, field # XTEST minor opcodes XTestGetVersion = 0 @@ -17,6 +17,31 @@ ButtonPress = 4 ButtonRelease = 5 MotionNotify = 6 +# XI1 event offsets relative to the XInput first-event base +XI_DeviceValuator = 0 +XI_DeviceMotionNotify = 5 + +MORE_EVENTS = 0x80 + + +@dataclass +class GetVersionRequest: + """XTestGetVersion request.""" + + opcode: int + major: int = 2 + minor: int = 2 + + def to_bytes(self, byte_order: str = "<") -> bytes: + return struct.pack( + f"{byte_order}BBH BxH", + self.opcode, + XTestGetVersion, + 2, + self.major, + self.minor, + ) + @dataclass class XTestFakeInputRequest: @@ -75,3 +100,115 @@ class XTestFakeInputRequest: 9, # 36 bytes = 9 words ) return header + event + b"\x00" * (36 - 4 - len(event)) + + +@dataclass +class DeviceValuatorEvent: + """32-byte XI DeviceValuator event.""" + + type: int + deviceid: int + first_valuator: int = 0 + num_valuators: int = 1 + valuators: list[int] = field(default_factory=list) + + def to_bytes(self, byte_order: str = "<") -> bytes: + vals = list(self.valuators) + [0] * 6 + return struct.pack( + f"{byte_order}BBH HBB iiiiii", + self.type, + self.deviceid, + 0, # sequence + 0, # device_state + self.num_valuators, + self.first_valuator, + vals[0], + vals[1], + vals[2], + vals[3], + vals[4], + vals[5], + ) + + +@dataclass +class DeviceMotionNotifyEvent: + """32-byte XI DeviceMotionNotify event.""" + + first_event: int + deviceid: int + detail: int = 0 # xFalse → absolute + more_events: bool = False + + def to_bytes(self, byte_order: str = "<") -> bytes: + deviceid = self.deviceid | (MORE_EVENTS if self.more_events else 0) + return struct.pack( + f"{byte_order}BBH IIII hhhh HBB", + self.first_event + XI_DeviceMotionNotify, + self.detail, + 0, # sequence + 0, # time + 0, # root + 0, # event + 0, # child + 0, # root_x + 0, # root_y + 0, # event_x + 0, # event_y + 0, # state + 0, # same_screen + deviceid, + ) + + +@dataclass +class FakeInputRequest: + """XTestFakeInput request. + + The request is an xReq header plus one or more 32-byte xEvents. + ``events`` is a chain of XI event objects; MORE_EVENTS is set on + all but the last when serializing. + """ + + opcode: int + events: list[DeviceMotionNotifyEvent | DeviceValuatorEvent] + + def serialize_event_chain(self, byte_order: str = "<") -> bytes: + """Serialize the XI event chain, setting MORE_EVENTS on all but the last.""" + out = bytearray() + for i, ev in enumerate(self.events): + more = i < len(self.events) - 1 + if isinstance(ev, DeviceMotionNotifyEvent): + ev = DeviceMotionNotifyEvent( + first_event=ev.first_event, + deviceid=ev.deviceid, + detail=ev.detail, + more_events=more, + ) + elif isinstance(ev, DeviceValuatorEvent): + deviceid = ev.deviceid & ~MORE_EVENTS + if more: + deviceid |= MORE_EVENTS + ev = DeviceValuatorEvent( + type=ev.type, + deviceid=deviceid, + first_valuator=ev.first_valuator, + num_valuators=ev.num_valuators, + valuators=ev.valuators, + ) + out.extend(ev.to_bytes(byte_order)) + return bytes(out) + + def to_bytes(self, byte_order: str = "<") -> bytes: + payload = self.serialize_event_chain(byte_order) + assert len(payload) % 32 == 0 + length = 1 + len(payload) // 4 + return ( + struct.pack( + f"{byte_order}BBH", + self.opcode, + XTestFakeInput, + length, + ) + + payload + ) diff --git a/test/pyxtest/test_xtest.py b/test/pyxtest/test_xtest.py new file mode 100644 index 000000000..04de0b82c --- /dev/null +++ b/test/pyxtest/test_xtest.py @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: MIT +# +# Security tests for XTEST extension vulnerabilities. + +import pytest +from proto import xtest +from proto.x11 import BadValue +from xclient import Extension, X11Error, X11Reply + +# Stack array in ProcXTestFakeInput is MAX_VALUATORS (36) ints. +# Each DeviceValuator event can carry at most 6 axes. +MAX_VALUATORS = 36 +VALUATORS_PER_EVENT = 6 + + +@pytest.fixture +def xtest_xclient(xclient): + """Provide an xclient with XTEST and XInput first-event base.""" + xt = xclient.query_extension(Extension.XTEST) + if not xt: + pytest.skip("XTEST extension not available") + + xi = xclient.query_extension(Extension.XI) + if not xi: + pytest.skip("XInput extension not available") + + req = xtest.GetVersionRequest(opcode=xt.opcode) + xclient.send_request(req) + resp = xclient.recv_response(timeout=5.0) + if not isinstance(resp, X11Reply): + pytest.skip("XTestGetVersion failed") + + return xclient, xt.opcode, xi.first_event + + +class TestXTestFakeInput: + def test_valuator_range(self, xserver, xtest_xclient): + """ + XTestFakeInput copied DeviceValuator fields into a fixed stack + array before checking that first + count fit in the device axis + range and in MAX_VALUATORS. A crafted request with enough + valuator events could write past that array. + + Validate the count and range before indexing the stack array. + """ + conn, opcode, first_event = xtest_xclient + deviceid = 2 # Virtual core pointer + + n_records = (MAX_VALUATORS // VALUATORS_PER_EVENT) + 1 + events = [ + xtest.DeviceMotionNotifyEvent( + first_event=first_event, + deviceid=deviceid, + ) + ] + for i in range(n_records): + events.append( + xtest.DeviceValuatorEvent( + type=first_event + xtest.XI_DeviceValuator, + deviceid=deviceid, + first_valuator=i * VALUATORS_PER_EVENT, + num_valuators=VALUATORS_PER_EVENT, + ) + ) + + conn.send_request(xtest.FakeInputRequest(opcode=opcode, events=events)) + resp = conn.recv_response(timeout=5.0) + + assert xserver.is_alive, "Server crashed on XTestFakeInput valuator overflow" + assert isinstance(resp, X11Error), f"Expected BadValue, got {resp}" + assert resp.error_code == BadValue, ( + f"Expected BadValue ({BadValue}), got {resp.error_code}" + ) -- 2.56.0 #+end_src