diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2018-02-08 17:20:55 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2018-02-08 17:20:55 +0000 |
commit | 5c7e4e0e05b37e038c9047e9d6cae118799f6ad2 (patch) | |
tree | f33cca721abf09ba92221874d2c4481674a91e77 | |
parent | 2d6af9e736c38a0f3dea89c448190ccbedfbcc13 (diff) |
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 <imirkin@alum.mit.edu>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/intel_device.c | 10 |
1 files 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); } |