aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs/9p-local.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/9pfs/9p-local.c')
-rw-r--r--hw/9pfs/9p-local.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index efb0b79a74..e51af87309 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -349,11 +349,11 @@ static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
return -1;
}
- /* Access modes are ignored when O_PATH is supported. We try O_RDONLY and
- * O_WRONLY for old-systems that don't support O_PATH.
- */
- fd = openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL, 0);
+ fd = openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL | O_NOFOLLOW, 0);
#if O_PATH_9P_UTIL == 0
+ /* Fallback for systems that don't support O_PATH: we depend on the file
+ * being readable or writable.
+ */
if (fd == -1) {
/* In case the file is writable-only and isn't a directory. */
if (errno == EACCES) {
@@ -368,6 +368,10 @@ static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
}
ret = fchmod(fd, mode);
#else
+ /* Access modes are ignored when O_PATH is supported. If name is a symbolic
+ * link, O_PATH | O_NOFOLLOW causes openat(2) to return a file descriptor
+ * referring to the symbolic link.
+ */
if (fd == -1) {
return -1;
}