summaryrefslogtreecommitdiff
path: root/va/wayland
diff options
context:
space:
mode:
authorU. Artie Eoff <ullysses.a.eoff@intel.com>2017-11-14 09:52:45 -0800
committerXiang, Haihao <haihao.xiang@intel.com>2017-11-16 10:00:22 -0800
commit2ea89fcb5075d090432f1140f863e8a82201ea22 (patch)
tree42d6f3cfe426cf8c65cd594ba7fdcc86002f8b66 /va/wayland
parent4794b9989b91a3326d1819b972ec9d48e4b78139 (diff)
downloadlibva-2ea89fcb5075d090432f1140f863e8a82201ea22.tar.gz
wayland: fix toctou violation when opening drm device
A file's attributes could change between the stat() and the open() operations. Thus, check file attributes on the opened file descriptor instead of the filename. Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Diffstat (limited to 'va/wayland')
-rw-r--r--va/wayland/va_wayland_drm.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/va/wayland/va_wayland_drm.c b/va/wayland/va_wayland_drm.c
index d8c4ec9..8e22695 100644
--- a/va/wayland/va_wayland_drm.c
+++ b/va/wayland/va_wayland_drm.c
@@ -55,25 +55,29 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *device)
struct drm_state * const drm_state = ctx->drm_state;
drm_magic_t magic;
struct stat st;
+ int fd = -1;
- if (stat(device, &st) < 0) {
- va_wayland_error("failed to identify %s: %s (errno %d)",
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ va_wayland_error("failed to open %s: %s (errno %d)",
device, strerror(errno), errno);
return;
}
- if (!S_ISCHR(st.st_mode)) {
- va_wayland_error("%s is not a device", device);
+ if (fstat(fd, &st) < 0) {
+ va_wayland_error("failed to identify %s: %s (errno %d)",
+ device, strerror(errno), errno);
+ close(fd);
return;
}
- drm_state->fd = open(device, O_RDWR);
- if (drm_state->fd < 0) {
- va_wayland_error("failed to open %s: %s (errno %d)",
- device, strerror(errno), errno);
+ if (!S_ISCHR(st.st_mode)) {
+ va_wayland_error("%s is not a device", device);
+ close(fd);
return;
}
+ drm_state->fd = fd;
drmGetMagic(drm_state->fd, &magic);
wl_drm_authenticate(wl_drm_ctx->drm, magic);
}