Skip to content

Commit e603d4a

Browse files
authored
[Xwayland] Add Xwayland byte-swapped clients support (#738)
* [Wayland] Add Xwayland byte-swapped clients support Recent versions of Xwayland can allow or disallow X11 clients from different endianess to connect. Add a setting to configure this feature from Muffin, who spawns Xwayland. Disabled by default, since this feature have potential security issues. * Use args for Xwayland and explicit disable byte swapped clients * Typo
1 parent 07aabf5 commit e603d4a

File tree

6 files changed

+114
-27
lines changed

6 files changed

+114
-27
lines changed

config.h.meson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@
7070

7171
/* Whether Xwayland has -initfd option */
7272
#mesondefine HAVE_XWAYLAND_INITFD
73+
74+
/* Whether the Xwayland supports +/-byteswappedclients */
75+
#mesondefine HAVE_XWAYLAND_BYTE_SWAPPED_CLIENTS

data/org.cinnamon.muffin.wayland.gschema.xml.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@
103103
</description>
104104
</key>
105105

106+
<key name="xwayland-allow-byte-swapped-clients" type="b">
107+
<default>false</default>
108+
<summary>Allow X11 clients with a different endianess to connect to Xwayland</summary>
109+
<description>
110+
Allow connections from clients with an endianess different to that
111+
of Xwayland.
112+
113+
The X server byte-swapping code is a huge attack surface, much of
114+
that code in Xwayland is prone to security issues.
115+
116+
The use-case of byte-swapped clients is very niche, and disabled by
117+
default in Xwayland.
118+
119+
Enable this option to instruct Xwayland to accept connections from
120+
X11 clients with a different endianess.
121+
122+
This option has no effect if Xwayland does not support the command
123+
line option +byteswappedclients/-byteswappedclients to control that
124+
setting.
125+
126+
Xwayland needs to be restarted for this setting to take effect.
127+
</description>
128+
</key>
129+
106130
</schema>
107131

108132
</schemalist>

meson.build

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ if cc.has_header_symbol('sys/prctl.h', 'prctl')
376376
endif
377377

378378
have_xwayland_initfd = false
379+
have_xwayland_byte_swapped_clients = false
379380
if have_wayland
380381
xwayland_dep = dependency('xwayland', required: false)
381382

@@ -416,6 +417,16 @@ if have_wayland
416417
if (have_xwayland_initfd)
417418
cdata.set('HAVE_XWAYLAND_INITFD', 1)
418419
endif
420+
421+
# For Xwayland +/-byteswappedclients usage
422+
if xwayland_dep.found()
423+
have_xwayland_byte_swapped_clients = xwayland_dep.get_variable('have_byteswappedclients',
424+
default_value: 'false') == 'true'
425+
endif
426+
427+
if (have_xwayland_byte_swapped_clients)
428+
cdata.set('HAVE_XWAYLAND_BYTE_SWAPPED_CLIENTS', 1)
429+
endif
419430
endif
420431

421432
#xwayland_grab_default_access_rules = get_option('xwayland_grab_default_access_rules')
@@ -465,19 +476,20 @@ output = [
465476
'',
466477
' Options:',
467478
'',
468-
' Wayland.................. ' + have_wayland.to_string(),
469-
' Wayland EGLStream........ ' + have_wayland_eglstream.to_string(),
470-
' Native Backend........... ' + have_native_backend.to_string(),
471-
' EGL Device............... ' + have_egl_device.to_string(),
472-
' Default driver........... ' + default_driver,
473-
' Remote desktop........... ' + have_remote_desktop.to_string(),
474-
' gudev.................... ' + have_libgudev.to_string(),
475-
' Wacom.................... ' + have_libwacom.to_string(),
476-
' SM....................... ' + have_sm.to_string(),
477-
' Startup notification..... ' + have_startup_notification.to_string(),
478-
' Introspection............ ' + have_introspection.to_string(),
479-
' Profiler................. ' + have_profiler.to_string(),
480-
' Xwayland initfd.......... ' + have_xwayland_initfd.to_string(),
479+
' Wayland.......................... ' + have_wayland.to_string(),
480+
' Wayland EGLStream................ ' + have_wayland_eglstream.to_string(),
481+
' Native Backend................... ' + have_native_backend.to_string(),
482+
' EGL Device....................... ' + have_egl_device.to_string(),
483+
' Default driver................... ' + default_driver,
484+
' Remote desktop................... ' + have_remote_desktop.to_string(),
485+
' gudev............................ ' + have_libgudev.to_string(),
486+
' Wacom............................ ' + have_libwacom.to_string(),
487+
' SM............................... ' + have_sm.to_string(),
488+
' Startup notification............. ' + have_startup_notification.to_string(),
489+
' Introspection.................... ' + have_introspection.to_string(),
490+
' Profiler......................... ' + have_profiler.to_string(),
491+
' Xwayland initfd.................. ' + have_xwayland_initfd.to_string(),
492+
' Xwayland byte-swapped clients.... ' + have_xwayland_byte_swapped_clients.to_string(),
481493
'',
482494
' Tests:',
483495
'',

src/backends/meta-settings-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ void meta_settings_get_xwayland_grab_patterns (MetaSettings *settings,
7979

8080
gboolean meta_settings_are_xwayland_grabs_allowed (MetaSettings *settings);
8181

82+
gboolean meta_settings_are_xwayland_byte_swapped_clients_allowed (MetaSettings *settings);
83+
8284
MetaX11ScaleMode meta_settings_get_x11_scale_mode (MetaSettings *settings);
8385

8486
void meta_settings_enable_x11_fractional_scaling (MetaSettings *settings,

src/backends/meta-settings.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct _MetaSettings
7272
GPtrArray *xwayland_grab_blacklist_patterns;
7373

7474
MetaX11ScaleMode x11_scale_mode;
75+
76+
/* Whether Xwayland should allow X11 clients from different endianess */
77+
gboolean xwayland_allow_byte_swapped_clients;
7578
};
7679

7780
G_DEFINE_TYPE (MetaSettings, meta_settings, G_TYPE_OBJECT)
@@ -498,6 +501,15 @@ update_xwayland_allow_grabs (MetaSettings *settings)
498501
"xwayland-allow-grabs");
499502
}
500503

504+
static void
505+
update_xwayland_allow_byte_swapped_clients (MetaSettings *settings)
506+
{
507+
508+
settings->xwayland_allow_byte_swapped_clients =
509+
g_settings_get_flags (settings->wayland_settings,
510+
"xwayland-allow-byte-swapped-clients");
511+
}
512+
501513
static void
502514
wayland_settings_changed (GSettings *wayland_settings,
503515
gchar *key,
@@ -512,6 +524,10 @@ wayland_settings_changed (GSettings *wayland_settings,
512524
{
513525
update_xwayland_grab_access_rules (settings);
514526
}
527+
else if (g_str_equal (key, "xwayland-allow-byte-swapped-clients"))
528+
{
529+
update_xwayland_allow_byte_swapped_clients (settings);
530+
}
515531
}
516532

517533
static void
@@ -541,6 +557,12 @@ meta_settings_are_xwayland_grabs_allowed (MetaSettings *settings)
541557
return (settings->xwayland_allow_grabs);
542558
}
543559

560+
gboolean
561+
meta_settings_are_xwayland_byte_swapped_clients_allowed (MetaSettings *settings)
562+
{
563+
return settings->xwayland_allow_byte_swapped_clients;
564+
}
565+
544566
MetaX11ScaleMode
545567
meta_settings_get_x11_scale_mode (MetaSettings *settings)
546568
{

src/wayland/meta-xwayland.c

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager,
580580
GSubprocessFlags flags;
581581
GError *error = NULL;
582582
g_autoptr (GTask) task = NULL;
583+
MetaBackend *backend;
584+
MetaSettings *settings;
585+
const char *args[32];
586+
int i;
583587

584588
task = g_task_new (NULL, cancellable, callback, user_data);
585589
g_task_set_source_tag (task, meta_xwayland_start_xserver);
@@ -614,6 +618,9 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager,
614618
flags |= G_SUBPROCESS_FLAGS_STDERR_SILENCE;
615619
}
616620

621+
backend = meta_get_backend ();
622+
settings = meta_backend_get_settings (backend);
623+
617624
launcher = g_subprocess_launcher_new (flags);
618625

619626
g_subprocess_launcher_take_fd (launcher, xwayland_client_fd[1], 3);
@@ -624,23 +631,40 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager,
624631

625632
g_subprocess_launcher_setenv (launcher, "WAYLAND_SOCKET", "3", TRUE);
626633

627-
manager->proc = g_subprocess_launcher_spawn (launcher, &error,
628-
XWAYLAND_PATH,
629-
manager->public_connection.name,
630-
"-rootless",
631-
"-noreset",
632-
"-accessx",
633-
"-core",
634-
"-auth", manager->auth_file,
635-
"-listen", "4",
636-
"-listen", "5",
637-
"-displayfd", "6",
634+
i = 0;
635+
args[i++] = XWAYLAND_PATH;
636+
args[i++] = manager->public_connection.name;
637+
args[i++] = "-rootless";
638+
args[i++] = "-noreset";
639+
args[i++] = "-accessx";
640+
args[i++] = "-core";
641+
args[i++] = "-auth";
642+
args[i++] = manager->auth_file;
643+
args[i++] = "-listen";
644+
args[i++] = "4";
645+
args[i++] = "-listen";
646+
args[i++] = "5";
647+
args[i++] = "-displayfd";
648+
args[i++] = "6";
638649
#ifdef HAVE_XWAYLAND_INITFD
639-
"-initfd", "7",
650+
args[i++] = "-initfd";
651+
args[i++] = "7";
640652
#else
641-
"-listen", "7",
653+
args[i++] = "-listen";
654+
args[i++] = "7";
655+
#endif
656+
657+
#ifdef HAVE_XWAYLAND_BYTE_SWAPPED_CLIENTS
658+
if (meta_settings_are_xwayland_byte_swapped_clients_allowed (settings))
659+
args[i++] = "+byteswappedclients";
660+
else
661+
args[i++] = "-byteswappedclients";
642662
#endif
643-
NULL);
663+
664+
/* Terminator */
665+
args[i++] = NULL;
666+
667+
manager->proc = g_subprocess_launcher_spawnv (launcher, args, &error);
644668

645669
if (!manager->proc)
646670
{

0 commit comments

Comments
 (0)