From patchwork Sat Jun 5 01:08:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 54734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1ABA2B7D12 for ; Sat, 5 Jun 2010 11:16:54 +1000 (EST) Received: from localhost ([127.0.0.1]:47184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKi0I-0000Do-PB for incoming@patchwork.ozlabs.org; Fri, 04 Jun 2010 21:16:50 -0400 Received: from [140.186.70.92] (port=35423 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKhp9-0001ai-4h for qemu-devel@nongnu.org; Fri, 04 Jun 2010 21:05:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKhp5-0006dN-2k for qemu-devel@nongnu.org; Fri, 04 Jun 2010 21:05:18 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:33891) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKhp4-0006cp-Si for qemu-devel@nongnu.org; Fri, 04 Jun 2010 21:05:15 -0400 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e38.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o550wdKp021006 for ; Fri, 4 Jun 2010 18:58:39 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5515C9J104056 for ; Fri, 4 Jun 2010 19:05:13 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5515Cql007903 for ; Fri, 4 Jun 2010 19:05:12 -0600 Received: from localhost.localdomain (elm9m80.beaverton.ibm.com [9.47.81.80]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o55156BF007599; Fri, 4 Jun 2010 19:05:11 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Fri, 4 Jun 2010 18:08:49 -0700 Message-Id: <1275700132-22823-8-git-send-email-jvrao@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1275700132-22823-1-git-send-email-jvrao@linux.vnet.ibm.com> References: <1275700132-22823-1-git-send-email-jvrao@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: v9fs-developer@lists.sourceforge.net, aliguori@us.ibm.com, "Venkateswararao Jujjuri \(JV\)" Subject: [Qemu-devel] [PATCH-V5 07/10] virtio-9p: Security model for mkdir X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Venkateswararao Jujjuri --- 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 3b08204..e0a5f58 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);