Don't attempt namec_from from non-O_PATH FDs
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 21 Dec 2016 16:12:50 +0000 (11:12 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 10 Jan 2017 00:01:40 +0000 (19:01 -0500)
If you tried this, you'd panic later on.  It's a user error to do this, not
a kernel bug.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/ns/sysfile.c

index 0011513..dd1d77a 100644 (file)
@@ -522,6 +522,8 @@ int sysopenat(int fromfd, char *path, int vfs_flags)
                 * and give us something new for c.  On error, namec_from will cclose
                 * from. */
                from = fdtochan(&current->open_files, fromfd, -1, FALSE, TRUE);
+               if (!(from->flag & O_PATH))
+                       error(EINVAL, "Cannot openat from a non-O_PATH FD");
                c = namec_from(from, path, Aopen, vfs_flags, 0);
        }
        fd = newfd(c, vfs_flags);