NULL Dereference via Unvalidated field_present_flags in RAIL Window Orders
This was originally raised as a vulnerability by @the-denis, but after some discussion it has been reclassified as an issue, as the resulting SEGV appears to be unexploitable.
Root Cause
xrdp_orders_send_window_new_update() treats the caller-supplied flags word as a trustworthy description of which fields of struct rail_window_state_order are populated, but the two are set independently.
xrdp_mm_process_rail_show_window() zero-initializes rwso and populates only show_state, while taking flags verbatim from the chansrv IPC stream. Because field_present_flags is formed with a bitwise OR and never masked to the set of fields the caller actually filled in, a WINDOW_ORDER_FIELD_TITLE bit drives an unconditional strlen(window_state->title_info) on a NULL pointer. Neither xrdp_orders_get_unicode_bytes() nor xrdp_orders_send_as_unicode() has a NULL guard.
This is not dependent on any bounds bug — a 24-byte, fully in-bounds message triggers it.
Vulnerable Code
No NULL check before strlen() (libxrdp/xrdp_orders_rail.c:256-263, and identically at 245-248):
static int
xrdp_orders_get_unicode_bytes(const char *text)
{
unsigned int text_len = strlen(text); /* VULNERABILITY: no NULL check */
/* Add 1 to word size to include length ([MS-RDPERP] 2.2.1.2.1) */
return (utf8_as_utf16_word_count(text, text_len) + 1) * 2;
}Flags OR'd, never masked; the TITLE branch is at top level of the function — not nested inside any WINDOW_ORDER_STATE_NEW / WINDOW_ORDER_TYPE_WINDOW gate (libxrdp/xrdp_orders_rail.c:279-305):
order_size = 11;
field_present_flags = flags | WINDOW_ORDER_TYPE_WINDOW; /* bare OR, no sanitization */
...
if (field_present_flags & WINDOW_ORDER_FIELD_TITLE)
{
/* titleInfo */
order_size += xrdp_orders_get_unicode_bytes(window_state->title_info); /* CRASH */
}A second unguarded use exists in the serialization half at lines 443-446, reached only if the size pass at 305 did not already crash.
WINDOW_ORDER_FIELD_TITLE is 0x00000004 (common/xrdp_rail.h:48).
The producer (xrdp/xrdp_mm.c:735-744) — title_info zeroed and never assigned, flags straight off the wire:
g_memset(&rwso, 0, sizeof(rwso));
in_uint32_le(s, window_id);
in_uint32_le(s, flags); /* attacker-controlled, no validation */
in_uint32_le(s, rwso.show_state);
...
rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);libxrdp_window_new_update (libxrdp/libxrdp.c:1644-1650) forwards flags verbatim as field_present_flags — no masking.
Impact
Immediate SIGSEGV in the xrdp daemon. With the shipped default fork=true (xrdp/xrdp.ini:6) and xrdp_listen_fork() (xrdp/xrdp_listen.c:685-699) forking one child per inbound connection, the crash terminates only the child serving the attacking session — effectively self-DoS, since the malicious chansrv already belongs to that session. If an administrator sets fork=false, the single-process daemon dies and every concurrent RDP session is dropped.
There is no memory corruption and no information disclosure: strlen on address 0 faults on the first byte, and the crash occurs during the size-computation pass before any bytes are emitted.
No remote-client escalation. The legitimate producer sesman/chansrv/rail.c:1331-1341 hardcodes flags = WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_FIELD_SHOW and never sets the TITLE bit; no RDP-client-supplied data reaches that word. A malicious RDP client cannot trigger this through an unmodified chansrv — it genuinely requires code execution as the session user.
Exploitation / Attack Path
- Attacker obtains code execution as the session user (a compromised session application, or anything able to write the
xrdp_chansrv_socket_$dnamepeer connection to the xrdp daemon). - Craft an IPC message on
chan_trans: headerid = 10(RAIL alternate secondary drawing orders),size = 8 + 4 + 12 = 24. - Payload:
order_type = 6(show_window), thenwindow_id = <any>,flags = 0x00000004(WINDOW_ORDER_FIELD_TITLE),show_state = <any>. This is a completely well-formed, correctly sized message. xrdp_mm_chan_process_msg()(line 2496) →xrdp_mm_process_rail_drawing_orders()(line 827) →xrdp_mm_process_rail_show_window()(line 744).libxrdp_window_new_update()→xrdp_orders_send_window_new_update()computesfield_present_flags = 0x4 | 0x01000000.- Line 305 calls
xrdp_orders_get_unicode_bytes(NULL)→strlen(NULL)at line 260 → SIGSEGV in the xrdp daemon child.
Second reachable instance: xrdp_mm_process_rail_create_window() populates title_info only when title_bytes > 0 (line 564). With title_bytes = 0 plus the TITLE bit in flags (read at line 610, also unvalidated), title_info stays NULL and line 614 reaches the identical strlen(NULL).
Fields checked and ruled out: window_rects / visibility_rects are not exploitable. In show_window both counts are 0 from the g_memset, so the size pass adds 8 * 0 (lines 364, 379) and the serialization loops (556-562, 585-591) execute zero iterations. In create_window the counts and allocations are always set together (lines 582-609), so a non-zero count implies a non-NULL array. xrdp_mm_process_rail_update_window_text() always allocates title_info (line 782) — no hazard. xrdp_mm_process_rail_configure_window() is inside #if 0.
Recommended Fix
Defence in depth at both layers. Primary — make the serializer robust to a flag bit whose backing field is absent (libxrdp/xrdp_orders_rail.c):
static int
xrdp_orders_get_unicode_bytes(const char *text)
{
unsigned int text_len;
if (text == NULL)
{
/* Length field only ([MS-RDPERP] 2.2.1.2.1) */
return 2;
}
text_len = strlen(text);
return (utf8_as_utf16_word_count(text, text_len) + 1) * 2;
}
static int
xrdp_orders_send_as_unicode(struct stream *s, const char *text)
{
unsigned int text_len;
int i32;
if (text == NULL)
{
out_uint16_le(s, 0);
return 0;
}
text_len = strlen(text);
...
}Secondary — never let an untrusted flags word claim a field the caller did not populate (libxrdp/xrdp_orders_rail.c:280):
field_present_flags = flags | WINDOW_ORDER_TYPE_WINDOW;
/* An untrusted producer must not be able to assert a field the caller
did not actually populate. */
if (window_state->title_info == NULL)
{
field_present_flags &= ~WINDOW_ORDER_FIELD_TITLE;
}
if (window_state->window_rects == NULL)
{
field_present_flags &= ~WINDOW_ORDER_FIELD_WND_RECTS;
}
if (window_state->visibility_rects == NULL)
{
field_present_flags &= ~WINDOW_ORDER_FIELD_VISIBILITY;
}Tertiary — constrain what chansrv may assert (xrdp/xrdp_mm.c:737):
in_uint32_le(s, flags);
/* show_window carries only a show state; no other field is populated */
flags &= (WINDOW_ORDER_TYPE_WINDOW | WINDOW_ORDER_STATE_NEW |
WINDOW_ORDER_FIELD_SHOW);This matches exactly what the legitimate producer sends (sesman/chansrv/rail.c:1340), so it breaks nothing.
Disclaimer: Generated using an LLM-assisted vulnerability research pipeline. Reviewed by Denis Skvortsov
Source: neutrinolabs/xrdp