From: Eric Blake <eblake@redhat.com>
To: Greg Kurz <groug@kaod.org>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PULL 07/31] 9pfs: introduce relative_openat_nofollow() helper
Date: Mon, 27 Feb 2017 17:37:56 -0600 [thread overview]
Message-ID: <0bbb5051-c3ad-bdbc-fb20-38f16de840da@redhat.com> (raw)
In-Reply-To: <1488236421-30983-8-git-send-email-groug@kaod.org>
[-- Attachment #1: Type: text/plain, Size: 2413 bytes --]
On 02/27/2017 04:59 PM, Greg Kurz wrote:
> When using the passthrough security mode, symbolic links created by the
> guest are actual symbolic links on the host file system.
>
Hmm, I just barely started reviewing the series, and see a pull request.
At this point, anything I point out can probably be done as followup
patches rather than forcing a respin of the pull (and soft freeze is
appropriate for that).
> Suggested-by: Jann Horn <jannh@google.com>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> (renamed openat_nofollow() to relative_openat_nofollow(),
> assert path is relative, Greg Kurz)
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> +int relative_openat_nofollow(int dirfd, const char *path, int flags,
> + mode_t mode)
> +{
> + int fd;
> +
> + assert(path[0] != '/');
If you move this assert...
> +
> + fd = dup(dirfd);
> + if (fd == -1) {
> + return -1;
> + }
> +
> + while (*path) {
> + const char *c;
> + int next_fd;
> + char *head;
...here, you can make sure there are no 'a//b' issues to worry about.
> +
> + head = g_strdup(path);
> + c = strchr(path, '/');
> + if (c) {
> + head[c - path] = 0;
> + next_fd = openat_dir(fd, head);
> + } else {
> + next_fd = openat_file(fd, head, flags, mode);
> + }
> + g_free(head);
> + if (next_fd == -1) {
> + close_preserve_errno(fd);
> + return -1;
> + }
> + close(fd);
> + fd = next_fd;
> +
> + if (!c) {
> + break;
> + }
> + path = c + 1;
or else add an assert here.
> +static inline int openat_file(int dirfd, const char *name, int flags,
> + mode_t mode)
> +{
> + int fd, serrno;
> +
> + fd = openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK,
> + mode);
> + if (fd == -1) {
> + return -1;
> + }
> +
> + serrno = errno;
> + /* O_NONBLOCK was only needed to open the file. Let's drop it. */
> + assert(!fcntl(fd, F_SETFL, flags));
Ewww. Side effect inside an assert(). :(
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2017-02-27 23:38 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 22:59 [Qemu-devel] [PULL 00/31] 9p patches 2017-02-27 for 2.9 soft freeze Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 01/31] 9pfs: fix v9fs_lock error case Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 02/31] fsdev: add IO throttle support to fsdev devices Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 03/31] throttle: factor out duplicate code Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 04/31] 9pfs: local: move xattr security ops to 9p-xattr.c Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 05/31] 9pfs: remove side-effects in local_init() Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 06/31] 9pfs: remove side-effects in local_open() and local_opendir() Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 07/31] 9pfs: introduce relative_openat_nofollow() helper Greg Kurz
2017-02-27 23:37 ` Eric Blake [this message]
2017-02-28 0:33 ` Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 08/31] 9pfs: local: keep a file descriptor on the shared folder Greg Kurz
2017-02-27 22:59 ` [Qemu-devel] [PULL 09/31] 9pfs: local: open/opendir: don't follow symlinks Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 10/31] 9pfs: local: lgetxattr: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 11/31] 9pfs: local: llistxattr: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 12/31] 9pfs: local: lsetxattr: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 13/31] 9pfs: local: lremovexattr: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 14/31] 9pfs: local: unlinkat: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 15/31] 9pfs: local: remove: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 16/31] 9pfs: local: utimensat: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 17/31] 9pfs: local: statfs: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 18/31] 9pfs: local: truncate: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 19/31] 9pfs: local: readlink: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 20/31] 9pfs: local: lstat: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 21/31] 9pfs: local: renameat: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 22/31] 9pfs: local: rename: use renameat Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 23/31] 9pfs: local: improve error handling in link op Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 24/31] 9pfs: local: link: don't follow symlinks Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 25/31] 9pfs: local: chmod: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 26/31] 9pfs: local: chown: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 27/31] 9pfs: local: symlink: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 28/31] 9pfs: local: mknod: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 29/31] 9pfs: local: mkdir: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 30/31] 9pfs: local: open2: " Greg Kurz
2017-02-27 23:00 ` [Qemu-devel] [PULL 31/31] 9pfs: local: drop unused code Greg Kurz
2017-02-27 23:41 ` [Qemu-devel] [PULL 00/31] 9p patches 2017-02-27 for 2.9 soft freeze no-reply
2017-02-28 0:00 ` no-reply
2017-02-28 0:36 ` Greg Kurz
2017-02-28 0:37 ` Greg Kurz
2017-02-28 5:58 ` Michael Tokarev
2017-02-28 7:31 ` Greg Kurz
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=0bbb5051-c3ad-bdbc-fb20-38f16de840da@redhat.com \
--to=eblake@redhat.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=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).