From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, Greg Kurz <groug@kaod.org>
Subject: [Qemu-devel] [PULL v2 3/4] 9pfs: local: clarify fchmodat_nofollow() implementation
Date: Tue, 5 Sep 2017 18:00:26 +0200 [thread overview]
Message-ID: <20170905160027.15081-4-groug@kaod.org> (raw)
In-Reply-To: <20170905160027.15081-1-groug@kaod.org>
Since fchmodat(2) on Linux doesn't support AT_SYMLINK_NOFOLLOW, we have to
implement it using workarounds. There are two different ways, depending on
whether the system supports O_PATH or not.
In the case O_PATH is supported, we rely on the behavhior of openat(2)
when passing O_NOFOLLOW | O_PATH and the file is a symbolic link. Even
if openat_file() already adds O_NOFOLLOW to the flags, this patch makes
it explicit that we need both creation flags to obtain the expected
behavior.
This is only cleanup, no functional change.
Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/9pfs/9p-local.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index efb0b79a74bf..e51af87309c6 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;
}
--
2.13.5
next prev parent reply other threads:[~2017-09-05 16:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-05 16:00 [Qemu-devel] [PULL v2 0/4] 9pfs/virtfs patches for 2.11 20170905 Greg Kurz
2017-09-05 16:00 ` [Qemu-devel] [PULL v2 1/4] 9pfs: avoid sign conversion error simplifying the code Greg Kurz
2017-09-05 16:00 ` [Qemu-devel] [PULL v2 2/4] fsdev: fix memory leak in main() Greg Kurz
2017-09-05 16:00 ` Greg Kurz [this message]
2017-09-05 16:00 ` [Qemu-devel] [PULL v2 4/4] virtfs: error out gracefully when mandatory suboptions are missing Greg Kurz
2017-09-05 17:12 ` [Qemu-devel] [PULL v2 0/4] 9pfs/virtfs patches for 2.11 20170905 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170905160027.15081-4-groug@kaod.org \
--to=groug@kaod.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).