From 5c7e4e0e05b37e038c9047e9d6cae118799f6ad2 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 8 Feb 2018 17:20:55 +0000 Subject: intel: Only check file type bits not mode when searching for rendernodes Before checking st_rdev, we first need to validate that the file is a device node, but we only want to check the file type bits and not compare the permissions. Reported-by: Ilia Mirkin Signed-off-by: Chris Wilson --- src/intel_device.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/intel_device.c b/src/intel_device.c index c4910cd8..21955073 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -467,7 +467,7 @@ static char *find_master_node(int fd) sprintf(buf, "/dev/dri/card%d", (int)(st.st_rdev & 0x7f)); if (stat(buf, &master) == 0 && - st.st_mode == master.st_mode && + S_ISCHR(master.st_mode) && (st.st_rdev & 0x7f) == master.st_rdev) return strdup(buf); @@ -478,10 +478,10 @@ static char *find_master_node(int fd) static int is_render_node(int fd, struct stat *st) { if (fstat(fd, st)) - return 0; + return -1; if (!S_ISCHR(st->st_mode)) - return 0; + return -1; return st->st_rdev & 0x80; } @@ -498,7 +498,7 @@ static char *find_render_node(int fd) sprintf(buf, "/dev/dri/renderD%d", (int)((master.st_rdev | 0x80) & 0xbf)); if (stat(buf, &render) == 0 && - master.st_mode == render.st_mode && + S_ISCHR(render.st_mode) && render.st_rdev == (master.st_rdev | 0x80)) return strdup(buf); @@ -506,7 +506,7 @@ static char *find_render_node(int fd) for (i = 0; i < 16; i++) { sprintf(buf, "/dev/dri/renderD%d", i + 128); if (stat(buf, &render) == 0 && - master.st_mode == render.st_mode && + S_ISCHR(render.st_mode) && render.st_rdev == (master.st_rdev | 0x80)) return strdup(buf); } -- cgit v1.2.3