From nobody Tue Apr 30 06:05:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497882850602953.149407507372; Mon, 19 Jun 2017 07:34:10 -0700 (PDT) Received: from localhost ([::1]:42956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMxkl-0000hM-9R for importer@patchew.org; Mon, 19 Jun 2017 10:34:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMxiT-0007qA-QF for qemu-devel@nongnu.org; Mon, 19 Jun 2017 10:31:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMxiS-0005tE-Ga for qemu-devel@nongnu.org; Mon, 19 Jun 2017 10:31:45 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMxiS-0005sT-6u for qemu-devel@nongnu.org; Mon, 19 Jun 2017 10:31:44 -0400 Received: by mail-wr0-x243.google.com with SMTP id z45so13883935wrb.2 for ; Mon, 19 Jun 2017 07:31:44 -0700 (PDT) Received: from localhost.localdomain ([2a02:8108:17c0:1500:2bd4:ef21:bc80:a853]) by smtp.gmail.com with ESMTPSA id p87sm15587267wma.2.2017.06.19.07.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 07:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CTqmOYrWXQpTrOEdMhMNIBPkgXiPmFnQOf6E03Gs1rQ=; b=hrYwPru1Ejrx9GE3MN4X9b3kW7/mzD9rq/cMPKHQ17IYVV95x18nrdq0pZ51RX7IWa 6t4bsQnX4twBe4KCLVDZ1oA+GdghzRg4YkGmcn6IV8JbOcHTCBSvq/ERdAn0/qRrgPC1 QNGRhOT3UtUp2hOp1oAzT0MHVKQNM9I5tbZYQYJMdyTWL/GuYjGP4NvHNrICbUHE6EWC zwZUdNw7CYIUCaPCyb+sCtpdREEduh19W69yAF9T7Bq3GnqS8zHYn6E1uKHyaxHyzMVc d1KRhb7GjZAbeVZB+1T5zXfjxQb8ebaOPx3CN0cOVXqbUyGgO9wvTO3AooBu0T/78QEr HYOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CTqmOYrWXQpTrOEdMhMNIBPkgXiPmFnQOf6E03Gs1rQ=; b=cBM+tmYsPu9hTwUk3sY/chJTEeGRKHk6nCTl+dSvanpQ1ncneLPTQC0MXEEjpTTfxG iG5tYzBOU9touB33ZXFnvDk2OhqLZu6M5/FFTJmiNZn5SJqRRmIHum8NnA4nVacNL0TF xCYZkeypj7YAmH2f1DnWdk9CuuhWr8cbMMjvi3qOGZtK+2Wf7WOS+HFkb0iBM+V+7Fg6 ba/xzZKVAqLTinflIWKvfBM9gvxQTLP9xerzxJLzWOzD0or/EogesA/oxboLn5qCis76 auIHAdS9VKot/eUiPyjfc3B7OFQZOCJrjeVY9HA+7J3pTFc3eYYZcoSsOzJxtXV3fIgT 8wnQ== X-Gm-Message-State: AKS2vOyZn7be9XeFC4lnsFnfYcbSLbzXnpd23y4N2YDxrtfaTfFqnap8 LeKVJovXKscZZrG79no= X-Received: by 10.223.163.92 with SMTP id d28mr2750321wrb.98.1497882702597; Mon, 19 Jun 2017 07:31:42 -0700 (PDT) From: Tobias Schramm To: qemu-devel@nongnu.org Date: Mon, 19 Jun 2017 16:28:48 +0200 Message-Id: <20170619142848.14258-2-tobleminer@gmail.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170619142848.14258-1-tobleminer@gmail.com> References: <20170619142848.14258-1-tobleminer@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v4 1/1] 9pfs: local: Add support for custom fmode/dmode in 9ps mapped security modes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: el13635@mail.ntua.gr, Tobias Schramm , aneesh.kumar@linux.vnet.ibm.com, groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tobias Schramm --- v4: Use OPT_NUMBER for file mode arguments, fix back to front naming, fix resource leak and add sanity checking for fmode/dmode arguments v3: Use unsigned types for umask v2: Adjust patch to QEMU code style fsdev/file-op-9p.h | 4 ++++ fsdev/qemu-fsdev-opts.c | 12 ++++++++++++ hw/9pfs/9p-local.c | 34 +++++++++++++++++++++++++--------- hw/9pfs/9p.c | 3 +++ qemu-options.hx | 20 ++++++++++++++++---- 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 0844a403dc..474c79d003 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -76,6 +76,8 @@ typedef struct FsDriverEntry { int export_flags; FileOperations *ops; FsThrottle fst; + mode_t fmode; + mode_t dmode; } FsDriverEntry; =20 typedef struct FsContext @@ -88,6 +90,8 @@ typedef struct FsContext FsThrottle *fst; /* fs driver specific data */ void *private; + mode_t fmode; + mode_t dmode; } FsContext; =20 typedef struct V9fsPath { diff --git a/fsdev/qemu-fsdev-opts.c b/fsdev/qemu-fsdev-opts.c index bf5713008a..7c31ffffaf 100644 --- a/fsdev/qemu-fsdev-opts.c +++ b/fsdev/qemu-fsdev-opts.c @@ -38,6 +38,12 @@ static QemuOptsList qemu_fsdev_opts =3D { }, { .name =3D "sock_fd", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "fmode", + .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "dmode", + .type =3D QEMU_OPT_NUMBER, }, =20 THROTTLE_OPTS, @@ -75,6 +81,12 @@ static QemuOptsList qemu_virtfs_opts =3D { }, { .name =3D "sock_fd", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "fmode", + .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "dmode", + .type =3D QEMU_OPT_NUMBER, }, =20 { /*End of list */ } diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 1e78b7c9e9..696e2b75dc 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -633,7 +633,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir= _path, =20 if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =3D mknodat(dirfd, name, SM_LOCAL_MODE_BITS | S_IFREG, 0); + err =3D mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0); if (err =3D=3D -1) { goto out; } @@ -685,7 +685,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir= _path, =20 if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =3D mkdirat(dirfd, name, SM_LOCAL_DIR_MODE_BITS); + err =3D mkdirat(dirfd, name, fs_ctx->dmode); if (err =3D=3D -1) { goto out; } @@ -786,7 +786,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir= _path, const char *name, /* Determine the security model */ if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - fd =3D openat_file(dirfd, name, flags, SM_LOCAL_MODE_BITS); + fd =3D openat_file(dirfd, name, flags, fs_ctx->fmode); if (fd =3D=3D -1) { goto out; } @@ -849,7 +849,7 @@ static int local_symlink(FsContext *fs_ctx, const char = *oldpath, ssize_t oldpath_size, write_size; =20 fd =3D openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR, - SM_LOCAL_MODE_BITS); + fs_ctx->fmode); if (fd =3D=3D -1) { goto out; } @@ -1431,6 +1431,8 @@ static int local_parse_opts(QemuOpts *opts, struct Fs= DriverEntry *fse) { const char *sec_model =3D qemu_opt_get(opts, "security_model"); const char *path =3D qemu_opt_get(opts, "path"); + uint64_t fmode =3D qemu_opt_get_number(opts, "fmode", SM_LOCAL_MODE_BI= TS); + uint64_t dmode =3D qemu_opt_get_number(opts, "dmode", SM_LOCAL_DIR_MOD= E_BITS); Error *err =3D NULL; =20 if (!sec_model) { @@ -1456,17 +1458,31 @@ static int local_parse_opts(QemuOpts *opts, struct = FsDriverEntry *fse) return -1; } =20 - if (!path) { - error_report("fsdev: No path specified"); - return -1; - } - fsdev_throttle_parse_opts(opts, &fse->fst, &err); if (err) { error_reportf_err(err, "Throttle configuration is not valid: "); return -1; } =20 + if (!(fse->export_flags & (V9FS_SM_MAPPED | V9FS_SM_MAPPED_FILE))) { + if (qemu_opt_find(opts, "fmode")) { + error_report("fmode is only valid for mapped 9p modes"); + return -1; + } + if (qemu_opt_find(opts, "dmode")) { + error_report("dmode is only valid for mapped 9p modes"); + return -1; + } + } + + fse->fmode =3D ((mode_t)fmode) & 0777; + fse->dmode =3D ((mode_t)dmode) & 0777; + + if (!path) { + error_report("fsdev: No path specified"); + return -1; + } + fse->path =3D g_strdup(path); =20 return 0; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 96d2683348..a0ae98f7ca 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3533,6 +3533,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **= errp) =20 s->ops =3D fse->ops; =20 + s->ctx.fmode =3D fse->fmode; + s->ctx.dmode =3D fse->dmode; + s->fid_list =3D NULL; qemu_co_rwlock_init(&s->rename_lock); =20 diff --git a/qemu-options.hx b/qemu-options.hx index 30c4f9850f..5999719720 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -847,7 +847,7 @@ ETEXI =20 DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, "-fsdev fsdriver,id=3Did[,path=3Dpath,][security_model=3D{mapped-xattr= |mapped-file|passthrough|none}]\n" - " [,writeout=3Dimmediate][,readonly][,socket=3Dsocket|sock_fd=3Dsock_f= d]\n" + " [,writeout=3Dimmediate][,readonly][,socket=3Dsocket|sock_fd=3Dsock_f= d][,fmode=3Dfmode][,dmode=3Ddmode]\n" " [[,throttling.bps-total=3Db]|[[,throttling.bps-read=3Dr][,throttling= .bps-write=3Dw]]]\n" " [[,throttling.iops-total=3Di]|[[,throttling.iops-read=3Dr][,throttli= ng.iops-write=3Dw]]]\n" " [[,throttling.bps-total-max=3Dbm]|[[,throttling.bps-read-max=3Drm][,= throttling.bps-write-max=3Dwm]]]\n" @@ -857,7 +857,7 @@ DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, =20 STEXI =20 -@item -fsdev @var{fsdriver},id=3D@var{id},path=3D@var{path},[security_mode= l=3D@var{security_model}][,writeout=3D@var{writeout}][,readonly][,socket=3D= @var{socket}|sock_fd=3D@var{sock_fd}] +@item -fsdev @var{fsdriver},id=3D@var{id},path=3D@var{path},[security_mode= l=3D@var{security_model}][,writeout=3D@var{writeout}][,readonly][,socket=3D= @var{socket}|sock_fd=3D@var{sock_fd}][,fmode=3D@var{fmode}][,dmode=3D@var{d= mode}] @findex -fsdev Define a new file system device. Valid options are: @table @option @@ -898,6 +898,12 @@ with virtfs-proxy-helper Enables proxy filesystem driver to use passed socket descriptor for communicating with virtfs-proxy-helper. Usually a helper like libvirt will create socketpair and pass one of the fds as sock_fd +@item fmode=3D@var{fmode} +Specifies the default mode for newly created files on the host. Works only +with security models "mapped-xattr" and "mapped-file". +@item dmode=3D@var{dmode} +Specifies the default mode for newly created directories on the host. Works +only with security models "mapped-xattr" and "mapped-file". @end table =20 -fsdev option is used along with -device driver "virtio-9p-pci". @@ -914,12 +920,12 @@ ETEXI =20 DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, "-virtfs local,path=3Dpath,mount_tag=3Dtag,security_model=3D[mapped-xa= ttr|mapped-file|passthrough|none]\n" - " [,id=3Did][,writeout=3Dimmediate][,readonly][,socket=3Dsocket= |sock_fd=3Dsock_fd]\n", + " [,id=3Did][,writeout=3Dimmediate][,readonly][,socket=3Dsocket= |sock_fd=3Dsock_fd][,fmode=3Dfmode][,dmode=3Ddmode]\n", QEMU_ARCH_ALL) =20 STEXI =20 -@item -virtfs @var{fsdriver}[,path=3D@var{path}],mount_tag=3D@var{mount_ta= g}[,security_model=3D@var{security_model}][,writeout=3D@var{writeout}][,rea= donly][,socket=3D@var{socket}|sock_fd=3D@var{sock_fd}] +@item -virtfs @var{fsdriver}[,path=3D@var{path}],mount_tag=3D@var{mount_ta= g}[,security_model=3D@var{security_model}][,writeout=3D@var{writeout}][,rea= donly][,socket=3D@var{socket}|sock_fd=3D@var{sock_fd}][,fmode=3D@var{fmode}= ][,dmode=3D@var{dmode}] @findex -virtfs =20 The general form of a Virtual File system pass-through options are: @@ -961,6 +967,12 @@ will create socketpair and pass one of the fds as sock= _fd @item sock_fd Enables proxy filesystem driver to use passed 'sock_fd' as the socket descriptor for interfacing with virtfs-proxy-helper +@item fmode=3D@var{fmode} +Specifies the default mode for newly created files on the host. Works only +with security models "mapped-xattr" and "mapped-file". +@item dmode=3D@var{dmode} +Specifies the default mode for newly created directories on the host. Works +only with security models "mapped-xattr" and "mapped-file". @end table ETEXI =20 --=20 2.13.1