summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2023-06-22 17:06:10 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2023-06-22 17:06:10 +0200
commit0c97c1b42fdf4525793f9aa6db477e65b1f1e6a5 (patch)
treee29ac222631b9371c2674b041f07a89970bfab98
parentHide xwayland_shell_v1 from regular clients (diff)
downloadsway-archive/20230705T044900Z/github/security-context.tar.gz
sway-archive/20230705T044900Z/github/security-context.tar.zst
sway-archive/20230705T044900Z/github/security-context.zip
Add support for security-context-v1archive/20230705T044900Z/github/security-context
As a first step, deny access to privileged protocols to sandboxed apps. References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3589
-rw-r--r--include/sway/server.h4
-rw-r--r--sway/server.c34
2 files changed, 34 insertions, 4 deletions
diff --git a/include/sway/server.h b/include/sway/server.h
index aaa8781b..4d5db6be 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -114,6 +114,10 @@ struct sway_server {
114 struct wlr_text_input_manager_v3 *text_input; 114 struct wlr_text_input_manager_v3 *text_input;
115 struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; 115 struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
116 struct wlr_content_type_manager_v1 *content_type_manager_v1; 116 struct wlr_content_type_manager_v1 *content_type_manager_v1;
117 struct wlr_data_control_manager_v1 *data_control_manager_v1;
118 struct wlr_screencopy_manager_v1 *screencopy_manager_v1;
119 struct wlr_export_dmabuf_manager_v1 *export_dmabuf_manager_v1;
120 struct wlr_security_context_manager_v1 *security_context_manager_v1;
117 121
118 struct wlr_xdg_activation_v1 *xdg_activation_v1; 122 struct wlr_xdg_activation_v1 *xdg_activation_v1;
119 struct wl_listener xdg_activation_v1_request_activate; 123 struct wl_listener xdg_activation_v1_request_activate;
diff --git a/sway/server.c b/sway/server.c
index 2c6a799e..19dc8c6e 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -24,8 +24,9 @@
24#include <wlr/types/wlr_primary_selection_v1.h> 24#include <wlr/types/wlr_primary_selection_v1.h>
25#include <wlr/types/wlr_relative_pointer_v1.h> 25#include <wlr/types/wlr_relative_pointer_v1.h>
26#include <wlr/types/wlr_screencopy_v1.h> 26#include <wlr/types/wlr_screencopy_v1.h>
27#include <wlr/types/wlr_single_pixel_buffer_v1.h> 27#include <wlr/types/wlr_security_context_v1.h>
28#include <wlr/types/wlr_server_decoration.h> 28#include <wlr/types/wlr_server_decoration.h>
29#include <wlr/types/wlr_single_pixel_buffer_v1.h>
29#include <wlr/types/wlr_subcompositor.h> 30#include <wlr/types/wlr_subcompositor.h>
30#include <wlr/types/wlr_tablet_v2.h> 31#include <wlr/types/wlr_tablet_v2.h>
31#include <wlr/types/wlr_viewporter.h> 32#include <wlr/types/wlr_viewporter.h>
@@ -72,6 +73,21 @@ static void handle_drm_lease_request(struct wl_listener *listener, void *data) {
72} 73}
73#endif 74#endif
74 75
76static bool is_privileged(const struct wl_global *global) {
77 return
78 global == server.output_manager_v1->global ||
79 global == server.output_power_manager_v1->global ||
80 global == server.input_method->global ||
81 global == server.foreign_toplevel_manager->global ||
82 global == server.data_control_manager_v1->global ||
83 global == server.screencopy_manager_v1->global ||
84 global == server.export_dmabuf_manager_v1->global ||
85 global == server.security_context_manager_v1->global ||
86 global == server.gamma_control_manager_v1->global ||
87 global == server.layer_shell->global ||
88 global == server.session_lock.manager->global;
89}
90
75static bool filter_global(const struct wl_client *client, 91static bool filter_global(const struct wl_client *client,
76 const struct wl_global *global, void *data) { 92 const struct wl_global *global, void *data) {
77#if HAVE_XWAYLAND 93#if HAVE_XWAYLAND
@@ -81,6 +97,15 @@ static bool filter_global(const struct wl_client *client,
81 } 97 }
82#endif 98#endif
83 99
100 // Restrict usage of privileged protocols to unsandboxed clients
101 // TODO: add a way for users to configure an allow-list
102 const struct wlr_security_context_v1_state *security_context =
103 wlr_security_context_manager_v1_lookup_client(
104 server.security_context_manager_v1, (struct wl_client *)client);
105 if (is_privileged(global)) {
106 return security_context == NULL;
107 }
108
84 return true; 109 return true;
85} 110}
86 111
@@ -227,9 +252,10 @@ bool server_init(struct sway_server *server) {
227 } 252 }
228#endif 253#endif
229 254
230 wlr_export_dmabuf_manager_v1_create(server->wl_display); 255 server->export_dmabuf_manager_v1 = wlr_export_dmabuf_manager_v1_create(server->wl_display);
231 wlr_screencopy_manager_v1_create(server->wl_display); 256 server->screencopy_manager_v1 = wlr_screencopy_manager_v1_create(server->wl_display);
232 wlr_data_control_manager_v1_create(server->wl_display); 257 server->data_control_manager_v1 = wlr_data_control_manager_v1_create(server->wl_display);
258 server->security_context_manager_v1 = wlr_security_context_manager_v1_create(server->wl_display);
233 wlr_viewporter_create(server->wl_display); 259 wlr_viewporter_create(server->wl_display);
234 wlr_single_pixel_buffer_manager_v1_create(server->wl_display); 260 wlr_single_pixel_buffer_manager_v1_create(server->wl_display);
235 server->content_type_manager_v1 = 261 server->content_type_manager_v1 =