qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PULL] VirtFS update
Date: Wed, 29 May 2013 17:03:23 +0530	[thread overview]
Message-ID: <87zjvevx4s.fsf@linux.vnet.ibm.com> (raw)


The following changes since commit 371386fb60961e0afc02f03c817dff79633e323e:

  Update version for 1.5.0 release. (2013-05-20 08:20:08 -0500)

are available in the git repository at:

  git://github.com/kvaneesh/qemu.git for-upstream

for you to fetch changes up to db431f6adc881a0758512cd765b3108209013512:

  hw/9pfs: Be robust against paths without FS_IOC_GETVERSION (2013-05-28 15:23:12 +0530)

----------------------------------------------------------------
Aneesh Kumar K.V (3):
      hw/9pfs: Fix segfault with 9p2000.u
      hw/9pfs: use O_NOFOLLOW for mapped readlink operation
      hw/9pfs: Use O_NOFOLLOW when opening files on server

Gabriel de Perthuis (1):
      hw/9pfs: Be robust against paths without FS_IOC_GETVERSION

 hw/9pfs/cofile.c          |  4 ++++
 hw/9pfs/virtio-9p-local.c | 50 +++++++++++++++++++++++++++++++++++++++--------
 hw/9pfs/virtio-9p.c       |  2 +-
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 2efebf3..194c130 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -38,6 +38,10 @@ int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
             });
         v9fs_path_unlock(s);
     }
+    /* The ioctl may not be supported depending on the path */
+    if (err == -ENOTTY) {
+        err = 0;
+    }
     return err;
 }
 
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index 6ece6f7..fc93e9e 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -59,6 +59,33 @@ static const char *local_mapped_attr_path(FsContext *ctx,
     return buffer;
 }
 
+static FILE *local_fopen(const char *path, const char *mode)
+{
+    int fd, o_mode = 0;
+    FILE *fp;
+    int flags = O_NOFOLLOW;
+    /*
+     * only supports two modes
+     */
+    if (mode[0] == 'r') {
+        flags |= O_RDONLY;
+    } else if (mode[0] == 'w') {
+        flags |= O_WRONLY | O_TRUNC | O_CREAT;
+        o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+    } else {
+        return NULL;
+    }
+    fd = open(path, flags, o_mode);
+    if (fd == -1) {
+        return NULL;
+    }
+    fp = fdopen(fd, mode);
+    if (!fp) {
+        close(fd);
+    }
+    return fp;
+}
+
 #define ATTR_MAX 100
 static void local_mapped_file_attr(FsContext *ctx, const char *path,
                                    struct stat *stbuf)
@@ -68,7 +95,7 @@ static void local_mapped_file_attr(FsContext *ctx, const char *path,
     char attr_path[PATH_MAX];
 
     local_mapped_attr_path(ctx, path, attr_path);
-    fp = fopen(attr_path, "r");
+    fp = local_fopen(attr_path, "r");
     if (!fp) {
         return;
     }
@@ -152,7 +179,7 @@ static int local_set_mapped_file_attr(FsContext *ctx,
     char attr_path[PATH_MAX];
     int uid = -1, gid = -1, mode = -1, rdev = -1;
 
-    fp = fopen(local_mapped_attr_path(ctx, path, attr_path), "r");
+    fp = local_fopen(local_mapped_attr_path(ctx, path, attr_path), "r");
     if (!fp) {
         goto create_map_file;
     }
@@ -179,7 +206,7 @@ create_map_file:
     }
 
 update_map_file:
-    fp = fopen(attr_path, "w");
+    fp = local_fopen(attr_path, "w");
     if (!fp) {
         ret = -1;
         goto err_out;
@@ -284,7 +311,7 @@ static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
     if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
         (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
         int fd;
-        fd = open(rpath(fs_ctx, path, buffer), O_RDONLY);
+        fd = open(rpath(fs_ctx, path, buffer), O_RDONLY | O_NOFOLLOW);
         if (fd == -1) {
             return -1;
         }
@@ -316,7 +343,7 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path,
     char buffer[PATH_MAX];
     char *path = fs_path->data;
 
-    fs->fd = open(rpath(ctx, path, buffer), flags);
+    fs->fd = open(rpath(ctx, path, buffer), flags | O_NOFOLLOW);
     return fs->fd;
 }
 
@@ -601,6 +628,11 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
     V9fsString fullname;
     char buffer[PATH_MAX];
 
+    /*
+     * Mark all the open to not follow symlinks
+     */
+    flags |= O_NOFOLLOW;
+
     v9fs_string_init(&fullname);
     v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
     path = fullname.data;
@@ -676,8 +708,9 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
         int fd;
         ssize_t oldpath_size, write_size;
-        fd = open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL|O_RDWR,
-                SM_LOCAL_MODE_BITS);
+        fd = open(rpath(fs_ctx, newpath, buffer),
+                  O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW,
+                  SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -705,7 +738,8 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
         int fd;
         ssize_t oldpath_size, write_size;
-        fd = open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL|O_RDWR,
+        fd = open(rpath(fs_ctx, newpath, buffer),
+                  O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW,
                   SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 296f66f..8cbb8ae 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -658,7 +658,7 @@ static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)
         ret |= S_IFIFO;
     }
     if (mode & P9_STAT_MODE_DEVICE) {
-        if (extension && extension->data[0] == 'c') {
+        if (extension->size && extension->data[0] == 'c') {
             ret |= S_IFCHR;
         } else {
             ret |= S_IFBLK;

             reply	other threads:[~2013-05-29 11:33 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 11:33 Aneesh Kumar K.V [this message]
2013-05-31 18:48 ` [Qemu-devel] [PULL] VirtFS update Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2015-06-16 15:29 Aneesh Kumar K.V
2015-06-17 11:26 ` Peter Maydell
2015-03-16 10:09 Aneesh Kumar K.V
2015-03-16 13:55 ` Peter Maydell
2014-09-04 16:01 Aneesh Kumar K.V
2014-09-04 18:21 ` Peter Maydell
2014-03-07 15:16 Aneesh Kumar K.V
2014-03-08 12:52 ` Peter Maydell
2014-02-05  7:14 Aneesh Kumar K.V
2014-02-05  7:58 ` Aneesh Kumar K.V
2014-02-10 18:48 ` Peter Maydell
2014-02-10 19:21 ` Andreas Färber
2014-02-10 19:43   ` Peter Maydell
2014-02-10 19:48     ` Andreas Färber
2014-02-10 19:51       ` Peter Maydell
2012-12-05 16:37 Aneesh Kumar K.V
2012-12-10 16:58 ` Anthony Liguori
2012-07-31 17:27 Aneesh Kumar K.V
2012-08-03 20:45 ` Anthony Liguori
2012-02-26 17:44 Aneesh Kumar K.V
2012-02-28 15:33 ` Anthony Liguori
2012-01-30 16:14 Aneesh Kumar K.V
2012-02-07 12:36 ` Aneesh Kumar K.V
2012-01-23 13:02 Aneesh Kumar K.V
2012-01-23 17:05 ` Anthony Liguori
2012-01-23 18:25   ` Aneesh Kumar K.V
2011-12-21  7:57 Aneesh Kumar K.V
2011-12-27 16:36 ` Anthony Liguori
2011-12-17 13:31 Aneesh Kumar K.V
2011-12-05  9:04 Aneesh Kumar K.V
2011-11-02 10:22 [Qemu-devel] [PULL] Virtfs update Aneesh Kumar K.V
2011-11-02 12:42 ` Anthony Liguori
2011-11-02 14:09   ` Aneesh Kumar K.V
2011-11-03 13:09     ` Anthony Liguori
2011-11-02 15:55   ` Markus Armbruster
2011-09-27  9:11 [Qemu-devel] [PULL] VirtFS update Aneesh Kumar K.V
2011-09-29 20:05 ` Anthony Liguori
2011-09-13 13:27 Aneesh Kumar K.V
2011-09-15 19:10 ` Anthony Liguori

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=87zjvevx4s.fsf@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --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).