mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-07-10 00:06:08 -04:00
security_context_v1: set CLOEXEC for client FDs
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/work_items/3949
(cherry picked from commit 327f000532)
This commit is contained in:
parent
eb02e65df4
commit
d9cd649551
7 changed files with 39 additions and 19 deletions
8
include/util/fd.h
Normal file
8
include/util/fd.h
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef UTIL_FD_H
|
||||||
|
#define UTIL_FD_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool set_cloexec(int fd, bool cloexec);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wlr/types/wlr_security_context_v1.h>
|
#include <wlr/types/wlr_security_context_v1.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "security-context-v1-protocol.h"
|
#include "security-context-v1-protocol.h"
|
||||||
|
#include "util/fd.h"
|
||||||
|
|
||||||
#define SECURITY_CONTEXT_MANAGER_V1_VERSION 1
|
#define SECURITY_CONTEXT_MANAGER_V1_VERSION 1
|
||||||
|
|
||||||
|
|
@ -129,6 +130,11 @@ static int security_context_handle_listen_fd_event(int listen_fd, uint32_t mask,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!set_cloexec(client_fd, true)) {
|
||||||
|
close(client_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_security_context_v1_client *security_context_client =
|
struct wlr_security_context_v1_client *security_context_client =
|
||||||
calloc(1, sizeof(*security_context_client));
|
calloc(1, sizeof(*security_context_client));
|
||||||
if (security_context_client == NULL) {
|
if (security_context_client == NULL) {
|
||||||
|
|
|
||||||
22
util/fd.c
Normal file
22
util/fd.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
#include "util/fd.h"
|
||||||
|
|
||||||
|
bool set_cloexec(int fd, bool cloexec) {
|
||||||
|
int flags = fcntl(fd, F_GETFD);
|
||||||
|
if (flags == -1) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "fcntl failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (cloexec) {
|
||||||
|
flags = flags | FD_CLOEXEC;
|
||||||
|
} else {
|
||||||
|
flags = flags & ~FD_CLOEXEC;
|
||||||
|
}
|
||||||
|
if (fcntl(fd, F_SETFD, flags) == -1) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "fcntl failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ wlr_files += files(
|
||||||
'array.c',
|
'array.c',
|
||||||
'box.c',
|
'box.c',
|
||||||
'env.c',
|
'env.c',
|
||||||
|
'fd.c',
|
||||||
'global.c',
|
'global.c',
|
||||||
'log.c',
|
'log.c',
|
||||||
'matrix.c',
|
'matrix.c',
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include <wlr/xwayland.h>
|
#include <wlr/xwayland.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
|
#include "util/fd.h"
|
||||||
|
|
||||||
static void safe_close(int fd) {
|
static void safe_close(int fd) {
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
|
#include "util/fd.h"
|
||||||
|
|
||||||
static const char lock_fmt[] = "/tmp/.X%d-lock";
|
static const char lock_fmt[] = "/tmp/.X%d-lock";
|
||||||
static const char socket_dir[] = "/tmp/.X11-unix";
|
static const char socket_dir[] = "/tmp/.X11-unix";
|
||||||
|
|
@ -22,24 +23,6 @@ static const char socket_fmt[] = "/tmp/.X11-unix/X%d";
|
||||||
static const char socket_fmt2[] = "/tmp/.X11-unix/X%d_";
|
static const char socket_fmt2[] = "/tmp/.X11-unix/X%d_";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool set_cloexec(int fd, bool cloexec) {
|
|
||||||
int flags = fcntl(fd, F_GETFD);
|
|
||||||
if (flags == -1) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "fcntl failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (cloexec) {
|
|
||||||
flags = flags | FD_CLOEXEC;
|
|
||||||
} else {
|
|
||||||
flags = flags & ~FD_CLOEXEC;
|
|
||||||
}
|
|
||||||
if (fcntl(fd, F_SETFD, flags) == -1) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "fcntl failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int open_socket(struct sockaddr_un *addr, size_t path_size) {
|
static int open_socket(struct sockaddr_un *addr, size_t path_size) {
|
||||||
int fd, rc;
|
int fd, rc;
|
||||||
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
bool set_cloexec(int fd, bool cloexec);
|
|
||||||
void unlink_display_sockets(int display);
|
void unlink_display_sockets(int display);
|
||||||
int open_display_sockets(int socks[2]);
|
int open_display_sockets(int socks[2]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue