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 <jvrao@linux.vnet.ibm.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -V5 21/28] virtio-9p: Add SM_NONE security model
Date: Thu,  2 Sep 2010 12:39:41 -0700	[thread overview]
Message-ID: <1283456388-13083-22-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1283456388-13083-1-git-send-email-jvrao@linux.vnet.ibm.com>

From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

This is equivalent to SM_PASSTHROUGH security model.
The only exception is, failure of privilige operation like chown
are ignored. This makes a passthrough like security model usable
for people who runs kvm as non root

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
---
 hw/file-op-9p.h      |   15 +++++++++++++--
 hw/virtio-9p-local.c |   40 ++++++++++++++++++++++++++++++----------
 hw/virtio-9p.c       |   12 +++++++++---
 qemu-options.hx      |    4 ++--
 vl.c                 |    2 +-
 5 files changed, 55 insertions(+), 18 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index e54f358..017183d 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -24,8 +24,19 @@
 
 typedef enum
 {
-    SM_PASSTHROUGH = 1, /* uid/gid set on fileserver files */
-    SM_MAPPED,  /* uid/gid part of xattr */
+    /*
+     * Server will try to set uid/gid.
+     * On failure ignore the error.
+     */
+    SM_NONE = 0,
+    /*
+     * uid/gid set on fileserver files
+     */
+    SM_PASSTHROUGH = 1,
+    /*
+     * uid/gid part of xattr
+     */
+    SM_MAPPED,
 } SecModel;
 
 typedef struct FsCred
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 3fc1712..58e7647 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -102,7 +102,13 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
         return -1;
     }
     if (chown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid) < 0) {
-        return -1;
+        /*
+         * If we fail to change ownership and if we are
+         * using security model none. Ignore the error
+         */
+        if (fs_ctx->fs_sm != SM_NONE) {
+            return -1;
+        }
     }
     return 0;
 }
@@ -122,7 +128,8 @@ static ssize_t local_readlink(FsContext *fs_ctx, const char *path,
         } while (tsize == -1 && errno == EINTR);
         close(fd);
         return tsize;
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         tsize = readlink(rpath(fs_ctx, path), buf, bufsz);
     }
     return tsize;
@@ -189,7 +196,8 @@ static int local_chmod(FsContext *fs_ctx, const char *path, FsCred *credp)
 {
     if (fs_ctx->fs_sm == SM_MAPPED) {
         return local_set_xattr(rpath(fs_ctx, path), credp);
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         return chmod(rpath(fs_ctx, path), credp->fc_mode);
     }
     return -1;
@@ -211,7 +219,8 @@ static int local_mknod(FsContext *fs_ctx, const char *path, FsCred *credp)
             serrno = errno;
             goto err_end;
         }
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         err = mknod(rpath(fs_ctx, path), credp->fc_mode, credp->fc_rdev);
         if (err == -1) {
             return err;
@@ -247,7 +256,8 @@ static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *credp)
             serrno = errno;
             goto err_end;
         }
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         err = mkdir(rpath(fs_ctx, path), credp->fc_mode);
         if (err == -1) {
             return err;
@@ -316,7 +326,8 @@ static int local_open2(FsContext *fs_ctx, const char *path, int flags,
             serrno = errno;
             goto err_end;
         }
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         fd = open(rpath(fs_ctx, path), flags, credp->fc_mode);
         if (fd == -1) {
             return fd;
@@ -372,15 +383,23 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
             serrno = errno;
             goto err_end;
         }
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         err = symlink(oldpath, rpath(fs_ctx, newpath));
         if (err) {
             return err;
         }
         err = lchown(rpath(fs_ctx, newpath), credp->fc_uid, credp->fc_gid);
         if (err == -1) {
-            serrno = errno;
-            goto err_end;
+            /*
+             * If we fail to change ownership and if we are
+             * using security model none. Ignore the error
+             */
+            if (fs_ctx->fs_sm != SM_NONE) {
+                serrno = errno;
+                goto err_end;
+            } else
+                err = 0;
         }
     }
     return err;
@@ -447,7 +466,8 @@ static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp)
         return lchown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid);
     } else if (fs_ctx->fs_sm == SM_MAPPED) {
         return local_set_xattr(rpath(fs_ctx, path), credp);
-    } else if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
+    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
+               (fs_ctx->fs_sm == SM_NONE)) {
         return lchown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid);
     }
     return -1;
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index a2ca422..4127439 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -3546,12 +3546,18 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
          * Client user credentials are saved in extended attributes.
          */
         s->ctx.fs_sm = SM_MAPPED;
+    } else if (!strcmp(fse->security_model, "none")) {
+        /*
+         * Files on the fileserver are set to QEMU credentials.
+         */
+        s->ctx.fs_sm = SM_NONE;
+
     } else {
-        /* user haven't specified a correct security option */
-        fprintf(stderr, "one of the following must be specified as the"
+        fprintf(stderr, "Default to security_model=none. You may want"
+                " enable advanced security model using "
                 "security option:\n\t security_model=passthrough \n\t "
                 "security_model=mapped\n");
-        return NULL;
+        s->ctx.fs_sm = SM_NONE;
     }
 
     if (lstat(fse->path, &stat)) {
diff --git a/qemu-options.hx b/qemu-options.hx
index 453f129..368bf96 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -485,7 +485,7 @@ ETEXI
 DEFHEADING(File system options:)
 
 DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
-    "-fsdev local,id=id,path=path,security_model=[mapped|passthrough]\n",
+    "-fsdev local,id=id,path=path,security_model=[mapped|passthrough|none]\n",
     QEMU_ARCH_ALL)
 
 STEXI
@@ -518,7 +518,7 @@ ETEXI
 DEFHEADING(Virtual File system pass-through options:)
 
 DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
-    "-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough]\n",
+    "-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n",
     QEMU_ARCH_ALL)
 
 STEXI
diff --git a/vl.c b/vl.c
index bd05e39..9f7358e 100644
--- a/vl.c
+++ b/vl.c
@@ -2320,7 +2320,7 @@ int main(int argc, char **argv, char **envp)
                         qemu_opt_get(opts, "path") == NULL ||
                         qemu_opt_get(opts, "security_model") == NULL) {
                     fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
-                            "security_model=[mapped|passthrough],"
+                            "security_model=[mapped|passthrough|none],"
                             "mnt_tag=tag.\n");
                     exit(1);
                 }
-- 
1.6.5.2

  parent reply	other threads:[~2010-09-02 19:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-02 19:39 [Qemu-devel] [PATCH-V5 00/28] Consolidated VirtFS work Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 01/28] qemu: virtio-9p: Recognize 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 02/28] qemu: virtio-9p: Implement statfs support in server Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 03/28] virtio-9p: Return correct error from v9fs_remove Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 04/28] [V4] virtio-9p: readdir implementation for 9p2000.L Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 05/28] virtio-9p: Compute iounit based on host filesystem block size Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 06/28] virtio-9p: getattr server implementation for 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 07/28] virtio-9p: Do not reset atime Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 08/28] [virtio-9p] Make v9fs_do_utimensat accept timespec structures instead of v9stat Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 09/28] virtio-9p: Implement server side of setattr for 9P2000.L protocol Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 10/28] [virtio-9p] Implement TLINK for 9P2000.L Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 11/28] [virtio-9p] Define and implement TSYMLINK " Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 12/28] [virtio-9p] This patch implements TLCREATE for 9p2000.L protocol Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 13/28] qemu: virtio-9p: Implement TMKNOD Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 14/28] qemu: virtio-9p: Implement TMKDIR Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 15/28] rename - change name of file or directory Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 16/28] [virtio-9p] qemu: virtio-9p: Implement LOPEN Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 17/28] virtio-9p: Add fidtype so that we can do type specific operation Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 18/28] virtio-9p: Implement TXATTRWALK Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 19/28] virtio-9p: Implement TXATTRCREATE Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 20/28] virtio-9p: Hide user.virtfs xattr in case of mapped security Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` Venkateswararao Jujjuri (JV) [this message]
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 22/28] virtio-9p: Use lchown which won't follow symlink Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 23/28] virtio-9p: Fix the memset usage Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 24/28] virtio-9p: Add support for removing xattr Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 25/28] virtio-9p: Make sure -virtfs option works correctly Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 26/28] [virtio-9p] Remove all instances of unnecessary dotu variable Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 27/28] [virtio-9p] This patch implements TLERROR/RLERROR on the qemu 9P server Venkateswararao Jujjuri (JV)
2010-09-02 19:39 ` [Qemu-devel] [PATCH -V5 28/28] virtio-9p: Change handling of flags in open() path for 9P2000.L 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=1283456388-13083-22-git-send-email-jvrao@linux.vnet.ibm.com \
    --to=jvrao@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=aneesh.kumar@linux.vnet.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).