qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com,
	"Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH-V6 07/10] virtio-9p: Security model for mkdir
Date: Thu, 10 Jun 2010 13:32:56 -0700	[thread overview]
Message-ID: <1276201979-17825-8-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1276201979-17825-1-git-send-email-jvrao@linux.vnet.ibm.com>

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
---
 hw/file-op-9p.h      |    2 +-
 hw/virtio-9p-local.c |   35 +++++++++++++++++++++++++++++++++--
 hw/virtio-9p.c       |   12 +++++++++---
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index b345189..12223de 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -70,7 +70,7 @@ typedef struct FileOperations
     ssize_t (*readv)(FsContext *, int, const struct iovec *, int);
     ssize_t (*writev)(FsContext *, int, const struct iovec *, int);
     off_t (*lseek)(FsContext *, int, off_t, int);
-    int (*mkdir)(FsContext *, const char *, mode_t);
+    int (*mkdir)(FsContext *, const char *, FsCred *);
     int (*fstat)(FsContext *, int, struct stat *);
     int (*rename)(FsContext *, const char *, const char *);
     int (*truncate)(FsContext *, const char *, off_t);
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index bb5140e..e99eff9 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -207,9 +207,40 @@ static int local_mksock(FsContext *ctx2, const char *path)
     return 0;
 }
 
-static int local_mkdir(FsContext *ctx, const char *path, mode_t mode)
+static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *credp)
 {
-    return mkdir(rpath(ctx, path), mode);
+    int err = -1;
+    int serrno = 0;
+
+    /* Determine the security model */
+    if (fs_ctx->fs_sm == SM_MAPPED) {
+        err = mkdir(rpath(fs_ctx, path), SM_LOCAL_DIR_MODE_BITS);
+        if (err == -1) {
+            return err;
+        }
+        credp->fc_mode = credp->fc_mode|S_IFDIR;
+        err = local_set_xattr(rpath(fs_ctx, path), credp);
+        if (err == -1) {
+            serrno = errno;
+            goto err_end;
+        }
+    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+        err = mkdir(rpath(fs_ctx, path), credp->fc_mode);
+        if (err == -1) {
+            return err;
+        }
+        err = local_post_create_passthrough(fs_ctx, path, credp);
+        if (err == -1) {
+            serrno = errno;
+            goto err_end;
+        }
+    }
+    return err;
+
+err_end:
+    remove(rpath(fs_ctx, path));
+    errno = serrno;
+    return err;
 }
 
 static int local_fstat(FsContext *fs_ctx, int fd, struct stat *stbuf)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 49a3065..005f725 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -170,9 +170,15 @@ static int v9fs_do_mksock(V9fsState *s, V9fsString *path)
     return s->ops->mksock(&s->ctx, path->data);
 }
 
-static int v9fs_do_mkdir(V9fsState *s, V9fsString *path, mode_t mode)
+static int v9fs_do_mkdir(V9fsState *s, V9fsCreateState *vs)
 {
-    return s->ops->mkdir(&s->ctx, path->data, mode);
+    FsCred cred;
+
+    cred_init(&cred);
+    cred.fc_uid = vs->fidp->uid;
+    cred.fc_mode = vs->perm & 0777;
+
+    return s->ops->mkdir(&s->ctx, vs->fullname.data, &cred);
 }
 
 static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
@@ -1776,7 +1782,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err)
     }
 
     if (vs->perm & P9_STAT_MODE_DIR) {
-        err = v9fs_do_mkdir(s, &vs->fullname, vs->perm & 0777);
+        err = v9fs_do_mkdir(s, vs);
         v9fs_create_post_mkdir(s, vs, err);
     } else if (vs->perm & P9_STAT_MODE_SYMLINK) {
         err = v9fs_do_symlink(s, &vs->extension, &vs->fullname);
-- 
1.6.5.2

  parent reply	other threads:[~2010-06-10 20:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-10 20:32 [Qemu-devel] PATCH-V6 0/10] virtio-9p:Introducing security model for VirtFS Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 01/10] virtio-9p: Introduces an option to specify the security model Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 02/10] virtio-9p: Make infrastructure for the new " Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 03/10] virtio-9p: Security model for chmod Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 04/10] virtio-9p: Security model for chown Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 05/10] virtio-9p: Implemented Security model for lstat and fstat Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 06/10] virtio-9p: Security model for create/open2 Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` Venkateswararao Jujjuri (JV) [this message]
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 08/10] virtio-9p: Security model for symlink and readlink Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 09/10] virtio-9p: Implement Security model for mknod Venkateswararao Jujjuri (JV)
2010-06-10 20:32 ` [Qemu-devel] [PATCH-V6 10/10] virtio-9p: Implement Security model for mksock using mknod Venkateswararao Jujjuri (JV)

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=1276201979-17825-8-git-send-email-jvrao@linux.vnet.ibm.com \
    --to=jvrao@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).