[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH -V3 23/32] vritio-9p: Fix chmod bug with directory
From: |
Aneesh Kumar K.V |
Subject: |
[Qemu-devel] [PATCH -V3 23/32] vritio-9p: Fix chmod bug with directory |
Date: |
Thu, 25 Mar 2010 22:13:31 +0530 |
chmod 0777 <dir> fails with EIO.
This is a result of wrong check in server code.
Server code is trying to check if the file type is not being changed by
making sure that fidp->dir is not NULL.
But the fidp->dir is set only on opendir/createdir.
This patch gives proper check to all special files.
Signed-off-by: Venkateswararao Jujjuri <address@hidden>
Signed-off-by: Aneesh Kumar K.V <address@hidden>
---
hw/virtio-9p.c | 56 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 9aa4b72..e519605 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -298,11 +298,12 @@ static int free_fid(V9fsState *s, int32_t fid)
#define P9_STAT_MODE_SETGID 0x00040000
#define P9_STAT_MODE_SETVTX 0x00010000
-#define P9_STAT_MODE_SPECIAL (P9_STAT_MODE_NAMED_PIPE | \
- P9_STAT_MODE_SYMLINK | \
- P9_STAT_MODE_LINK | \
- P9_STAT_MODE_DEVICE)
-
+#define P9_STAT_MODE_TYPE_BITS (P9_STAT_MODE_DIR | \
+ P9_STAT_MODE_SYMLINK | \
+ P9_STAT_MODE_LINK | \
+ P9_STAT_MODE_DEVICE | \
+ P9_STAT_MODE_NAMED_PIPE | \
+ P9_STAT_MODE_SOCKET)
/* This is the algorithm from ufs in spfs */
static void stat_to_qid(const struct stat *stbuf, V9fsQID *qidp)
@@ -1842,6 +1843,7 @@ typedef struct V9fsWstatState
int16_t unused;
V9fsStat v9stat;
V9fsFidState *fidp;
+ struct stat stbuf;
V9fsString nname;
} V9fsWstatState;
@@ -2034,6 +2036,37 @@ static int donttouch_stat(V9fsStat *stat)
return 0;
}
+static void v9fs_wstat_post_lstat(V9fsState *s, V9fsWstatState *vs, int err)
+{
+ uint32_t v9_mode;
+
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
+
+ v9_mode = stat_to_v9mode(&vs->stbuf);
+
+ if ((vs->v9stat.mode & P9_STAT_MODE_TYPE_BITS) !=
+ (v9_mode & P9_STAT_MODE_TYPE_BITS)) {
+ /* Attempting to change the type */
+ err = -EIO;
+ goto out;
+ }
+
+ if (posix_chmod(s, &vs->fidp->path, v9mode_to_mode(vs->v9stat.mode,
+ &vs->v9stat.extension))) {
+ err = -errno;
+ }
+ v9fs_wstat_post_chmod(s, vs, err);
+ return;
+
+out:
+ v9fs_stat_free(&vs->v9stat);
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
{
int32_t fid;
@@ -2060,16 +2093,9 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
}
if (vs->v9stat.mode != -1) {
- if (vs->v9stat.mode & P9_STAT_MODE_DIR && vs->fidp->dir == NULL) {
- err = -EIO;
- goto out;
- }
-
- if (posix_chmod(s, &vs->fidp->path,
- v9mode_to_mode(vs->v9stat.mode,
- &vs->v9stat.extension))) {
- err = -errno;
- }
+ err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
+ v9fs_wstat_post_lstat(s, vs, err);
+ return;
}
v9fs_wstat_post_chmod(s, vs, err);
--
1.7.0.2.323.g0d092
- [Qemu-devel] [PATCH -V3 12/32] virtio-9p: Implement P9_TREMOVE, (continued)
- [Qemu-devel] [PATCH -V3 12/32] virtio-9p: Implement P9_TREMOVE, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 14/32] virtio-9p: Add multiple mount point support, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 16/32] virtio-9p: Add support for hardlink, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 13/32] virtio-9p: Implement P9_TFLUSH, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 17/32] Implement sync support in 9p server, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 15/32] virtio-9p: Use little endian format on virtio, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 18/32] virtio-9p: Fix sg usage in the code, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 19/32] virtio-9p: Get the correct count values from the pdu, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 22/32] virtio-9p: Update existing fid path on rename, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 21/32] virtio-9p: Remove unnecessary definition of fid, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 23/32] vritio-9p: Fix chmod bug with directory,
Aneesh Kumar K.V <=
- [Qemu-devel] [PATCH -V3 20/32] virtio-9p: Remove BUG_ON and add proper error handling, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 24/32] qemu-malloc: Add qemu_asprintf, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 26/32] virtio-9p: Create a commandline option -fsdev, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 25/32] virtio-9p: Move V9fs File system specific options to a separate header file., Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 27/32] virtio-9p: Create qemu_fsdev_opts, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 28/32] virtio-9p: Handle the fsdev command line options., Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 29/32] virtio-9p: Decouple share_path details from virtio-9p-dev, Aneesh Kumar K.V, 2010/03/25
- [Qemu-devel] [PATCH -V3 30/32] virtio-9p: Create a syntactic shortcut for the file-system pass-thru, Aneesh Kumar K.V, 2010/03/25