From 3acc448dbc549931c369203e02e6427857247381 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 25 Apr 2024 12:03:16 +0200 Subject: [PATCH] xwayland: make X11 socket dir world-writable The X11 socket dir must be world-writable, or else xhost usage is broken [1]. Ensure that the umask doesn't drop some permission bits from the mode we pass to mkdir(). We opt against saving/restoring umask because it's per-process global state. [1]: https://gitlab.gnome.org/GNOME/mutter/-/issues/1468 --- xwayland/sockets.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/xwayland/sockets.c b/xwayland/sockets.c index a91e049e0..f1ab752fa 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -63,18 +63,35 @@ static bool check_socket_dir(void) { return true; } -static int open_socket(int display) { - if (mkdir(socket_dir, 0755) == 0) { - wlr_log(WLR_INFO, "Created %s ourselves -- other users will " - "be unable to create X11 UNIX sockets of their own", - socket_dir); - } else if (errno != EEXIST) { +static bool setup_socket_dir(void) { + mode_t dir_mode = 01777; + + if (mkdir(socket_dir, dir_mode) != 0) { + if (errno == EEXIST) { + return check_socket_dir(); + } wlr_log_errno(WLR_ERROR, "Unable to mkdir %s", socket_dir); return false; - } else if (!check_socket_dir()) { + } + + wlr_log(WLR_INFO, "Created %s ourselves -- other users will " + "be unable to create X11 UNIX sockets of their own", + socket_dir); + + // The mode passed to mkdir() is affected by umask, so set it again + if (chmod(socket_dir, dir_mode) != 0) { + wlr_log_errno(WLR_ERROR, "Failed to chmod %s", socket_dir); return false; } + return true; +} + +static int open_socket(int display) { + if (!setup_socket_dir()) { + return -1; + } + struct sockaddr_un addr = { .sun_family = AF_UNIX }; size_t path_size = snprintf(addr.sun_path, sizeof(addr.sun_path), socket_fmt, display);