Proxy FS driver for VirtFS
PATCH 1/13 hw/9pfs: Move opt validation to FsDriver callback
In reply to M. Mohan KumarFrom: "Aneesh Kumar K.V" <[email protected]>
This remove all conditional code from common code path and make opt validation a FSDriver callback.
--- fsdev/file-op-9p.h | 15 +++++++++++++-- fsdev/qemu-fsdev.c | 44 ++++++-------------------------------------- fsdev/qemu-fsdev.h | 10 ---------- hw/9pfs/virtio-9p-device.c | 13 ++++++++----- hw/9pfs/virtio-9p-handle.c | 20 ++++++++++++++++++++ hw/9pfs/virtio-9p-local.c | 34 ++++++++++++++++++++++++++++++++++ vl.c | 8 ++------ 7 files changed, 83 insertions(+), 61 deletions(-)
fsdev/file-op-9p.h +13 -2
@@ -61,6 +61,16 @@ typedef struct extended_ops {#define V9FS_SEC_MASK 0x0000001C +typedef struct FileOperations FileOperations ; +/* +* Structure to store the various fsdev's passed through command line. +*/ +typedef struct FsDriverEntry { +char *fsdev_id; +char *path; +int export_flags; +FileOperations *ops; +}FsDriverEntry ; typedef struct FsContext {
@@ -82,8 +92,9 @@ typedef union V9fsFidOpenState V9fsFidOpenState;void cred_init (FsCred *); -typedef struct FileOperations +struct FileOperations { +int (*parse_opts)(QemuOpts *,struct FsDriverEntry *);int (*init)(struct FsContext *);int (*lstat)(FsContext *,V9fsPath *,struct stat *);ssize_t (*readlink)(FsContext *,V9fsPath *,char *,size_t );
@@ -128,6 +139,6 @@ typedef struct FileOperations V9fsPath *newdir, const char *new_name);int (*unlinkat)(FsContext *ctx,V9fsPath *dir,const char *name,int flags); void *opaque; -} FileOperations; +};#endif
fsdev/qemu-fsdev.c +6 -38
69 lines not on this page · raw message
fsdev/qemu-fsdev.h +0 -10
@@ -34,16 +34,6 @@ typedef struct FsDriverTable {FileOperations *ops; } FsDriverTable; -/* -* Structure to store the various fsdev's passed through command line. -*/ -typedef struct FsDriverEntry { -char *fsdev_id; -char *path; -int export_flags; -FileOperations *ops; -}FsDriverEntry ; - typedef struct FsDriverListEntry { FsDriverEntry fse; QTAILQ_ENTRY(FsDriverListEntry) next;
hw/9pfs/virtio-9p-device.c +8 -5
@@ -75,16 +75,19 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)exit (1 ); } -if (!fse->path || !conf->tag) { -/* we haven't specified a mount_tag or the path */ -fprintf (stderr,"fsdev with id %s needs path " -"and Virtio-9p device needs mount_tag arguments\n" , +if (!conf->tag) { +/* we haven't specified a mount_tag */ +fprintf (stderr,"fsdev with id %s needs mount_tag arguments\n" , conf->fsdev_id);exit (1 ); } s->ctx.export_flags = fse->export_flags; - s->ctx.fs_root =g_strdup (fse->path); +if (fse->path) { + s->ctx.fs_root =g_strdup (fse->path); + }else { + s->ctx.fs_root =NULL ; + } s->ctx.exops.get_st_gen =NULL ;if (fse->export_flags &V9FS_SM_PASSTHROUGH ) {
hw/9pfs/virtio-9p-handle.c +20 -0
@@ -647,7 +647,27 @@ out:return ret; } +static int handle_parse_opts (QemuOpts *opts,struct FsDriverEntry *fse) +{ +const char *sec_model =qemu_opt_get (opts,"security_model" ); +const char *path =qemu_opt_get (opts,"path" ); + +if (sec_model) { +fprintf (stderr,"Invalid argument security_model specified with handle fsdriver\n" ); +return -1 ; + } + +if (!path) { +fprintf (stderr,"fsdev: No path specified.\n" ); +return -1 ; + } + fse->path =g_strdup (path); +return 0 ; + +} +FileOperations handle_ops = { + .parse_opts = handle_parse_opts, .init = handle_init, .lstat = handle_lstat, .readlink = handle_readlink,
hw/9pfs/virtio-9p-local.c +34 -0
@@ -732,7 +732,41 @@ static int local_init(FsContext *ctx)return err; } +static int local_parse_opts (QemuOpts *opts,struct FsDriverEntry *fse) +{ +const char *sec_model =qemu_opt_get (opts,"security_model" ); +const char *path =qemu_opt_get (opts,"path" ); + +if (!sec_model) { +fprintf (stderr,"security model not specified, " +"local fs needs security model\nvalid options are:" +"\tsecurity_model=[passthrough|mapped|none]\n" ); +return -1 ; + } + +if (!strcmp (sec_model,"passthrough" )) { + fse->export_flags |=V9FS_SM_PASSTHROUGH ; + }else if (!strcmp (sec_model,"mapped" )) { + fse->export_flags |=V9FS_SM_MAPPED ; + }else if (!strcmp (sec_model,"none" )) { + fse->export_flags |=V9FS_SM_NONE ; + }else { +fprintf (stderr,"Invalid security model %s specified, valid options are" +"\n\t [passthrough|mapped|none]\n" , sec_model); +return -1 ; + } + +if (!path) { +fprintf (stderr,"fsdev: No path specified.\n" ); +return -1 ; + } + fse->path =g_strdup (path); + +return 0 ; +} +FileOperations local_ops = { + .parse_opts = local_parse_opts, .init = local_init, .lstat = local_lstat, .readlink = local_readlink,
vl.c +2 -6
@@ -2677,11 +2677,8 @@ int main(int argc, char **argv, char **envp) }if (qemu_opt_get (opts,"fsdriver" ) ==NULL || -qemu_opt_get (opts,"mount_tag" ) ==NULL || -qemu_opt_get (opts,"path" ) ==NULL ) { -fprintf (stderr,"Usage: -virtfs fsdriver,path=/share_path/," -"[security_model={mapped|passthrough|none}]," -"mount_tag=tag.\n" ); +qemu_opt_get (opts,"mount_tag" ) ==NULL ) { +fprintf (stderr,"Usage: -virtfs fsdriver,mount_tag=tag.\n" );exit (1 ); } fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
@@ -2727,7 +2724,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }qemu_opt_set (fsdev,"fsdriver" ,"synth" ); -qemu_opt_set (fsdev,"path" ,"/" );/* ignored */ device =qemu_opts_create (qemu_find_opts ("device" ),NULL ,0 );qemu_opt_set (device,"driver" ,"virtio-9p-pci" );
Signature · 1 line
1.7.6
PATCH 4/13 hw/9pfs: File system helper process for qemu 9p proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Provide root privilege access to QEMU 9p proxy filesystem using socket communication.
Proxy helper is started by root user as:
~ # virtfs-proxy-helper
{{-s|--socket <socketname> -u|--uid -g|--gid}|{-f|--fd <socket descriptor>}}
-p <path-to-share> [-r <runasuid> -t <runasgid>]
Where uid:gid gives socket access to uid:gid, -r:t combination drops the privilege to given uid:gid
--- Makefile | 2 + configure | 25 ++++ hw/9pfs/proxy.h | 6 + hw/9pfs/virtfs-proxy-helper.c | 262 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 295 insertions(+), 0 deletions(-) create mode 100644 hw/9pfs/virtfs-proxy-helper.c
Makefile +2 -0
@@ -153,6 +153,8 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) +hw/9pfs/virtfs-proxy-helper$(EXESUF): LIBS+=$(LIBS_PROXY) + qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $@")
configure +25 -0
@@ -1866,6 +1866,23 @@ else fi ########################################## +# libcap probe + +if test "$cap" != "no" ; then + cat > $TMPC <<EOF +#include <stdio.h> +#include <sys/capability.h> +int main(void) { cap_t caps; caps = cap_init(); } +EOF + if compile_prog "" "-lcap" ; then + cap=yes + libs_proxy="-lcap" + else + cap=no + fi +fi + +########################################## # pthread probe PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
@@ -2636,6 +2653,9 @@ confdir=$sysconfdir$confsuffix tools= if test "$softmmu" = yes ; then tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools" +if test "$cap" = yes; then + tools="$tools hw/9pfs/virtfs-proxy-helper\$(EXESUF)" +fi if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) $tools" if [ "$guest_agent" = "yes" ]; then
@@ -3068,6 +3088,10 @@ if test "$linux_magic_h" = "yes" ; then echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak fi +if test "$cap" = "yes" ; then + echo "CONFIG_CAPABILITY=y" >> $config_host_mak +fi + # USB host support case "$usb" in linux)
@@ -3143,6 +3167,7 @@ echo "LIBS+=$LIBS" >> $config_host_mak echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak echo "LIBS_QGA+=$libs_qga" >> $config_host_mak +echo "LIBS_PROXY+=$libs_proxy" >> $config_host_mak # generate list of library paths for linker script
hw/9pfs/proxy.h +6 -0
@@ -2,6 +2,12 @@#define __PROXY_HELP_H#define BUFF_SZ (4 * 1024) +#define V9FS_FD_VALID INT_MAX + +union MsgControl { +struct cmsghdr cmsg; +char control[CMSG_SPACE (sizeof (int ))]; +}; typedef struct { int type;
hw/9pfs/virtfs-proxy-helper.c new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
1.7.6
cover Proxy FS driver for VirtFS
From: "M. Mohan Kumar" <[email protected]>
Pass-through security model in QEMU 9p server needs root privilege to do few file operations (like chown, chmod to any mode/uid:gid). There are two issues in pass-through security model
1) TOCTTOU vulnerability: Following symbolic links in the server could provide access to files beyond 9p export path.
2) Running QEMU with root privilege could be a security issue.
To overcome above issues, following approach is used: A new filesytem type 'proxy' is introduced. Proxy FS uses chroot + socket combination for securing the vulnerability known with following symbolic links. Intention of adding a new filesystem type is to allow qemu to run in non-root mode, but doing privileged operations using socket IO.
Proxy helper(a stand alone binary part of qemu) is invoked with root privileges. Proxy helper chroots into 9p export path and creates a socket pair or a named socket based on the command line parameter. Qemu and proxy helper communicate using this socket. QEMU proxy fs driver sends filesystem request to proxy helper and receives the response from it.
Proxy helper is designed so that it can drop the root privilege but retaining capbilities that are needed for doing filesystem operations (like CAP_DAC_OVERRIDE, CAP_FOWNER etc)
Aneesh Kumar K.V (1):
hw/9pfs: Move opt validation to FsDriver callback
M. Mohan Kumar (12):
hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file hw/9pfs: Add new proxy filesystem driver
hw/9pfs: File system helper process for qemu 9p proxy FS hw/9pfs: Add support to use named socket for proxy FS hw/9pfs: Open and create files
hw/9pfs: Create other filesystem objects
hw/9pfs: Add stat/readlink/statfs for proxy FS hw/9pfs: File ownership and others
hw/9pfs: xattr interfaces in proxy filesystem driver hw/9pfs: Proxy getversion
hw/9pfs: Documentation changes related to proxy fs hw/9pfs: man page for proxy helper
Makefile | 16 +- Makefile.objs | 3 +- configure | 26 + fsdev/file-op-9p.h | 15 +- fsdev/qemu-fsdev.c | 45 +-- fsdev/qemu-fsdev.h | 11 +- hw/9pfs/proxy.h | 40 ++ hw/9pfs/virtfs-proxy-helper.c | 792 +++++++++++++++++++++++++++++++ hw/9pfs/virtfs-proxy-helper.texi | 63 +++ hw/9pfs/virtio-9p-device.c | 13 +- hw/9pfs/virtio-9p-handle.c | 20 + hw/9pfs/virtio-9p-local.c | 34 ++ hw/9pfs/virtio-9p-marshal.c | 269 +++++++++++ hw/9pfs/virtio-9p-proxy.c | 974 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p.c | 270 +----------- hw/9pfs/virtio-9p.h | 12 + qemu-config.c | 13 + qemu-options.hx | 30 +- vl.c | 18 +- 19 files changed, 2326 insertions(+), 338 deletions(-) create mode 100644 hw/9pfs/proxy.h create mode 100644 hw/9pfs/virtfs-proxy-helper.c create mode 100644 hw/9pfs/virtfs-proxy-helper.texi create mode 100644 hw/9pfs/virtio-9p-marshal.c create mode 100644 hw/9pfs/virtio-9p-proxy.c
Signature · 1 line
1.7.6
PATCH 2/13 hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file
From: "M. Mohan Kumar" <[email protected]>
Move p9 marshaling/unmarshaling code to a separate file so that proxy filesytem driver can use these calls. Also made marshaling code generic to accept "struct iovec" instead of V9fsPDU.
--- Makefile.objs | 2 +- hw/9pfs/virtio-9p-marshal.c | 257 ++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p.c | 258 +------------------------------------------ hw/9pfs/virtio-9p.h | 12 ++ 4 files changed, 274 insertions(+), 255 deletions(-) create mode 100644 hw/9pfs/virtio-9p-marshal.c
Makefile.objs +1 -1
@@ -310,7 +310,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o 9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-handle.o -9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-synth.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-synth.o virtio-9p-marshal.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
hw/9pfs/virtio-9p-marshal.c new file +257 -0
257 lines not on this page · raw message
hw/9pfs/virtio-9p.c +4 -254
270 lines not on this page · raw message
hw/9pfs/virtio-9p.h +12 -0
@@ -468,4 +468,16 @@ extern void v9fs_path_free(V9fsPath *path);extern void v9fs_path_copy (V9fsPath *lhs,V9fsPath *rhs);extern int v9fs_name_to_path (V9fsState *s,V9fsPath *dirpath,const char *name,V9fsPath *path); + +size_t v9fs_pack (struct iovec *in_sg,int in_num,size_t offset, +const void *src,size_t size); +size_t v9fs_unmarshal (struct iovec *out_sg,int out_num,size_t offset, +const char *fmt, ...); +size_t v9fs_marshal (struct iovec *in_sg,int in_num,size_t offset, +const char *fmt, ...); +#define pdu_marshal(pdu, offset, fmt, args...) \ + v9fs_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, fmt, ##args) +#define pdu_unmarshal(pdu, offset, fmt, args...) \ + v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, fmt, ##args) +#endif
Signature · 1 line
1.7.6
PATCH 6/13 hw/9pfs: Open and create files
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add interfaces to open and create files for proxy file system driver.
--- Makefile | 2 + configure | 1 + hw/9pfs/proxy.h | 6 ++ hw/9pfs/virtfs-proxy-helper.c | 135 ++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p-marshal.c | 12 +++ hw/9pfs/virtio-9p-proxy.c | 178 +++++++++++++++++++++++++++++++++++++++-- hw/9pfs/virtio-9p.c | 12 --- 7 files changed, 325 insertions(+), 21 deletions(-)
Makefile +2 -0
@@ -153,6 +153,8 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) +hw/9pfs/virtfs-proxy-helper$(EXESUF): QEMU_CFLAGS += -DTARGET_PHYS_ADDR_BITS=$(PROXY_PHYS_ADDR_BITS) +hw/9pfs/virtfs-proxy-helper$(EXESUF): hw/9pfs/virtfs-proxy-helper.o hw/9pfs/virtio-9p-marshal.o hw/9pfs/virtfs-proxy-helper$(EXESUF): LIBS+=$(LIBS_PROXY) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
configure +1 -0
@@ -3474,6 +3474,7 @@ if test "$smartcard_nss" = "yes" ; then echo "libcacard_libs=$libcacard_libs" >> $config_host_mak echo "libcacard_cflags=$libcacard_cflags" >> $config_host_mak fi +echo "PROXY_PHYS_ADDR_BITS=$target_phys_bits" >> $config_host_mak list="" if test ! -z "$gdb_xml_files" ; then for x in $gdb_xml_files; do
hw/9pfs/proxy.h +6 -0
@@ -13,4 +13,10 @@ typedef struct {int type; int size; } ProxyHeader; + +enum { +T_OPEN =1 , +T_CREATE , +}; +#endif
hw/9pfs/virtfs-proxy-helper.c +133 -2
160 lines not on this page · raw message
hw/9pfs/virtio-9p-marshal.c +12 -0
@@ -12,6 +12,18 @@*/ #include "virtio-9p.h" +void v9fs_string_free (V9fsString *str) +{ +g_free (str->data); + str->data =NULL ; + str->size =0 ; +} + +void v9fs_string_null (V9fsString *str) +{ +v9fs_string_free (str); +} +static size_t v9fs_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack) {
hw/9pfs/virtio-9p-proxy.c +171 -7
202 lines not on this page · raw message
hw/9pfs/virtio-9p.c +0 -12
@@ -149,18 +149,6 @@ void v9fs_string_init(V9fsString *str) str->size =0 ; } -void v9fs_string_free (V9fsString *str) -{ -g_free (str->data); - str->data =NULL ; - str->size =0 ; -} - -void v9fs_string_null (V9fsString *str) -{ -v9fs_string_free (str); -} -static int number_to_string (void *arg,char type) {unsigned int ret =0 ;
Signature · 1 line
1.7.6
PATCH 5/13 hw/9pfs: Add support to use named socket for proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add option to use named socket for communicating between proxy helper and qemu proxy FS. Access to socket can be given by using command line options -u and -g.
--- hw/9pfs/virtfs-proxy-helper.c | 89 ++++++++++++++++++++++++++++++++++++++-- hw/9pfs/virtio-9p-proxy.c | 56 ++++++++++++++++++++++--- qemu-config.c | 6 +++ vl.c | 6 ++- 4 files changed, 144 insertions(+), 13 deletions(-)
hw/9pfs/virtfs-proxy-helper.c +84 -5
@@ -26,6 +26,9 @@ static struct option helper_opts[] = { {"fd", required_argument, NULL, 'f'}, {"path", required_argument, NULL, 'p'}, {"nodaemon", no_argument, NULL, 'n'}, + {"socket", required_argument, NULL, 's'}, + {"uid", required_argument, NULL, 'u'}, + {"gid", required_argument, NULL, 'g'}, };int is_daemon;
@@ -153,11 +156,61 @@ static int read_request(int sockfd, struct iovec *iovec) }while (1 ); } +/* create unix domain socket and return the descriptor */ +static int proxy_socket (const char *path,uid_t uid,gid_t gid) +{ +int sock, client; +struct sockaddr_un proxy, qemu; +socklen_t size; + +/* requested socket already exists, refuse to start */ +if (!access (path,F_OK )) { +do_log (LOG_CRIT ,"socket already exists\n" ); +return -1 ; + } + + sock =socket (AF_UNIX ,SOCK_STREAM ,0 ); +if (sock <0 ) { +do_perror ("socket" ); +return -1 ; + } + +/* mask other part of mode bits */ +umask (7 ); + + proxy.sun_family =AF_UNIX ; +strcpy (proxy.sun_path, path); +if (bind (sock, (struct sockaddr *)&proxy, +sizeof (struct sockaddr_un )) <0 ) { +do_perror ("bind" ); +return -1 ; + } +if (chown (proxy.sun_path, uid, gid) <0 ) { +do_perror ("chown" ); +return -1 ; + } +if (listen (sock,1 ) <0 ) { +do_perror ("listen" ); +return -1 ; + } + + client =accept (sock, (struct sockaddr *)&qemu, &size); +if (client <0 ) { +do_perror ("accept" ); +return -1 ; + } +return client; +} +static void usage (char *prog) {fprintf (stderr,"usage: %s\n" " -p|--path <path> 9p path to export\n" " {-f|--fd <socket-descriptor>} socket file descriptor to be used\n" +" {-s|--socket <socketname> socket file used for communication\n" +" \t-u|--uid <uid> -g|--gid <gid>} - uid:gid combination to give " +" access to this socket\n" +" \tNote: -s & -f can not be used together\n" " [-n|--nodaemon] Run as a normal program\n" ,basename (prog)); }
@@ -184,16 +237,20 @@ error:int main (int argc,char **argv) {int sock; +char sock_name[PATH_MAX ];char rpath[PATH_MAX ];struct stat stbuf;int c, option_index; +uid_t own_u; +gid_t own_g; is_daemon =1 ; - rpath[0 ] ='\0' ; + sock_name[0 ] = rpath[0 ] ='\0' ; sock =-1 ; + own_u = own_g =-1 ;while (1 ) { option_index =0 ; - c =getopt_long (argc, argv,"p:nh?f:" , helper_opts, + c =getopt_long (argc, argv,"p:nh?f:s:u:g:" , helper_opts, &option_index);if (c ==-1 ) {break ;
@@ -205,9 +262,18 @@ int main(int argc, char **argv)case 'n' : is_daemon =0 ;break ; -case 'f' : +case 'f' : sock =atoi (optarg);break ; +case 's' : +strcpy (sock_name, optarg); +break ; +case 'u' : + own_u =atoi (optarg); +break ; +case 'g' : + own_g =atoi (optarg); +break ;case '?' :case 'h' :default :
@@ -218,8 +284,15 @@ int main(int argc, char **argv) }/* Parameter validation */ -if (sock ==-1 || rpath[0 ] =='\0' ) { -fprintf (stderr,"socket descriptor or path not specified\n" ); +if ((sock_name[0 ] =='\0' && sock ==-1 ) || rpath[0 ] =='\0' ) { +fprintf (stderr,"socket, socket descriptor or path not specified\n" ); +usage (argv[0 ]); +return -1 ; + } + +if (*sock_name && (own_u ==-1 || own_g ==-1 )) { +fprintf (stderr,"owner uid:gid not specified, " ); +fprintf (stderr,"owner specifies who can access the socket file\n" );usage (argv[0 ]);return -1 ; }
@@ -243,6 +316,12 @@ int main(int argc, char **argv) }do_log (LOG_INFO ,"Started" ); +if (*sock_name) { + sock =proxy_socket (sock_name, own_u, own_g); +if (sock <0 ) { + goto error; + } + }if (chroot (rpath) <0 ) {do_perror ("chroot" );
hw/9pfs/virtio-9p-proxy.c +49 -7
80 lines not on this page · raw message
qemu-config.c +6 -0
@@ -187,6 +187,9 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "sock_fd", .type = QEMU_OPT_NUMBER, + }, { + .name = "socket", + .type = QEMU_OPT_STRING, }, { /*End of list */ }
@@ -219,6 +222,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "sock_fd", .type = QEMU_OPT_NUMBER, + }, { + .name = "socket", + .type = QEMU_OPT_STRING, }, { /*End of list */ }
vl.c +5 -1
@@ -2663,7 +2663,7 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_virtfs: {QemuOpts *fsdev;QemuOpts *device; -const char *writeout, *sock_fd; +const char *writeout, *sock_fd, *socket; olist =qemu_find_opts ("virtfs" );if (!olist) {
@@ -2703,6 +2703,10 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"path" ,qemu_opt_get (opts,"path" ));qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); + socket =qemu_opt_get (opts,"socket" ); +if (socket) { +qemu_opt_set (fsdev,"socket" , socket); + } sock_fd =qemu_opt_get (opts,"sock_fd" );if (sock_fd) {qemu_opt_set (fsdev,"sock_fd" , sock_fd);
Signature · 1 line
1.7.6
PATCH 7/13 hw/9pfs: Create other filesystem objects
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add interfaces to create filesystem objects like directory, device nodes, symbolic links, links for proxy filesytem driver
--- hw/9pfs/proxy.h | 4 ++ hw/9pfs/virtfs-proxy-helper.c | 63 +++++++++++++++++++++- hw/9pfs/virtio-9p-proxy.c | 119 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 175 insertions(+), 11 deletions(-)
hw/9pfs/proxy.h +4 -0
@@ -17,6 +17,10 @@ typedef struct {enum {T_OPEN =1 ,T_CREATE , +T_MKNOD , +T_MKDIR , +T_SYMLINK , +T_LINK , };#endif
hw/9pfs/virtfs-proxy-helper.c +62 -1
87 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.c +109 -10
164 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 8/13 hw/9pfs: Add stat/readlink/statfs for proxy FS
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- hw/9pfs/proxy.h | 3 ++ hw/9pfs/virtfs-proxy-helper.c | 81 ++++++++++++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p-proxy.c | 67 +++++++++++++++++++++++++++++++--- 3 files changed, 144 insertions(+), 7 deletions(-)
hw/9pfs/proxy.h +3 -0
@@ -21,6 +21,9 @@ enum {T_MKDIR ,T_SYMLINK ,T_LINK , +T_LSTAT , +T_READLINK , + T_STATFS, };#endif
hw/9pfs/virtfs-proxy-helper.c +80 -1
115 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.c +61 -6
102 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 3/13 hw/9pfs: Add new proxy filesystem driver
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add new proxy filesystem driver to add root privilege to qemu process. It needs a helper process to be started by root user.
Following command line can be used to utilize proxy filesystem driver -virtfs proxy,id=<id>,mount_tag=<tag>,sock_fd=<socket-fd>
--- Makefile.objs | 1 + fsdev/qemu-fsdev.c | 1 + fsdev/qemu-fsdev.h | 1 + hw/9pfs/proxy.h | 10 ++ hw/9pfs/virtio-9p-proxy.c | 374 +++++++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 + vl.c | 6 +- 7 files changed, 399 insertions(+), 1 deletions(-) create mode 100644 hw/9pfs/proxy.h create mode 100644 hw/9pfs/virtio-9p-proxy.c
Makefile.objs +1 -0
@@ -311,6 +311,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o 9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-handle.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-synth.o virtio-9p-marshal.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-proxy.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
fsdev/qemu-fsdev.c +1 -0
@@ -25,6 +25,7 @@ static FsDriverTable FsDrivers[] = { { .name = "local", .ops = &local_ops}, { .name = "handle", .ops = &handle_ops}, { .name = "synth", .ops = &synth_ops}, + { .name = "proxy", .ops = &proxy_ops}, };int qemu_fsdev_add (QemuOpts *opts)
fsdev/qemu-fsdev.h +1 -0
@@ -44,4 +44,5 @@ FsDriverEntry *get_fsdev_fsentry(char *id);extern FileOperations local_ops;extern FileOperations handle_ops;extern FileOperations synth_ops; +extern FileOperations proxy_ops;#endif
hw/9pfs/proxy.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __PROXY_HELP_H +#define __PROXY_HELP_H + +#define BUFF_SZ (4 * 1024) + +typedef struct { +int type; +int size; +}ProxyHeader ; +#endif
hw/9pfs/virtio-9p-proxy.c new file +374 -0
374 lines not on this page · raw message
qemu-config.c +7 -0
@@ -183,6 +183,10 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "readonly", .type = QEMU_OPT_BOOL, + + }, { + .name = "sock_fd", + .type = QEMU_OPT_NUMBER, }, { /*End of list */ }
@@ -212,6 +216,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "readonly", .type = QEMU_OPT_BOOL, + }, { + .name = "sock_fd", + .type = QEMU_OPT_NUMBER, }, { /*End of list */ }
vl.c +5 -1
@@ -2663,7 +2663,7 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_virtfs: {QemuOpts *fsdev;QemuOpts *device; -const char *writeout; +const char *writeout, *sock_fd; olist =qemu_find_opts ("virtfs" );if (!olist) {
@@ -2703,6 +2703,10 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"path" ,qemu_opt_get (opts,"path" ));qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); + sock_fd =qemu_opt_get (opts,"sock_fd" ); +if (sock_fd) { +qemu_opt_set (fsdev,"sock_fd" , sock_fd); + }qemu_opt_set_bool (fsdev,"readonly" ,qemu_opt_get_bool (opts,"readonly" ,0 ));
Signature · 1 line
1.7.6
PATCH 10/13 hw/9pfs: xattr interfaces in proxy filesystem driver
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add xattr support for proxy FS
--- hw/9pfs/proxy.h | 4 ++ hw/9pfs/virtfs-proxy-helper.c | 60 ++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 121 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 176 insertions(+), 9 deletions(-)
hw/9pfs/proxy.h +4 -0
@@ -30,6 +30,10 @@ enum {T_UTIME ,T_RENAME ,T_REMOVE , +T_LGETXATTR , +T_LLISTXATTR , +T_LSETXATTR , + T_LREMOVEXATTR, };#endif
hw/9pfs/virtfs-proxy-helper.c +60 -0
90 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.c +112 -9
168 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 12/13 hw/9pfs: Documentation changes related to proxy fs
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- qemu-options.hx | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-)
qemu-options.hx +22 -8
@@ -527,19 +527,19 @@ DEFHEADING() DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, - "-fsdev fsdriver,id=id,path=path,[security_model={mapped|passthrough|none}]\n" - " [,writeout=immediate][,readonly]\n", + "-fsdev fsdriver,id=id[,path=path,][security_model={mapped|passthrough|none}]\n" + " [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI -@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly] +@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,socket=@var{socket}|sock_fd=@var{sock_fd}] @findex -fsdev Define a new file system device. Valid options are: @table @option @item @var{fsdriver} This option specifies the fs driver backend to use. -Currently "local" and "handle" file system drivers are supported. +Currently "local", "handle" and "proxy" file system drivers are supported. @item id=@var{id} Specifies identifier for this device @item path=@var{path}
@@ -556,7 +556,7 @@ file attributes. Directories exported by this security model cannot interact with other unix tools. "none" security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory -only for local fsdriver. Other fsdrivers (like handle) don't take +only for local fsdriver. Other fsdrivers (like handle, proxy) don't take security model as a parameter. @item writeout=@var{writeout} This is an optional argument. The only supported value is "immediate".
@@ -566,6 +566,13 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item socket=@var{socket} +Enables proxy filesystem driver to use passed socket file for communicating +with virtfs-proxy-helper +@item sock_fd=@var{sock_fd} +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 @end table -fsdev option is used along with -device driver "virtio-9p-pci".
@@ -591,14 +598,14 @@ DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, STEXI -@item -virtfs @var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}][,readonly] +@item -virtfs @var{fsdriver}[,path=@var{path}],mount_tag=@var{mount_tag}[,security_model=@var{security_model}][,writeout=@var{writeout}][,readonly][,socket=@var{socket}|sock_fd=@var{sock_fd}] @findex -virtfs The general form of a Virtual File system pass-through options are: @table @option @item @var{fsdriver} This option specifies the fs driver backend to use. -Currently "local" and "handle" file system drivers are supported. +Currently "local", "handle" and "proxy" file system drivers are supported. @item id=@var{id} Specifies identifier for this device @item path=@var{path}
@@ -615,7 +622,7 @@ file attributes. Directories exported by this security model cannot interact with other unix tools. "none" security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory only -for local fsdriver. Other fsdrivers (like handle) don't take security +for local fsdriver. Other fsdrivers (like handle, proxy) don't take security model as a parameter. @item writeout=@var{writeout} This is an optional argument. The only supported value is "immediate".
@@ -625,6 +632,13 @@ reported as written by the storage subsystem. @item readonly Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. +@item socket=@var{socket} +Enables proxy filesystem driver to use passed socket file for +communicating with virtfs-proxy-helper. Usually a helper like libvirt +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 @end table ETEXI
Signature · 1 line
1.7.6
PATCH 9/13 hw/9pfs: File ownership and others
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
Add file ownership interfaces like chmod/chown, utime update, rename, remove and truncating files for proxy FS
--- hw/9pfs/proxy.h | 6 ++ hw/9pfs/virtfs-proxy-helper.c | 61 ++++++++++++++++++- hw/9pfs/virtio-9p-proxy.c | 134 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 188 insertions(+), 13 deletions(-)
hw/9pfs/proxy.h +6 -0
@@ -24,6 +24,12 @@ enum {T_LSTAT ,T_READLINK ,T_STATFS , +T_CHMOD , +T_CHOWN , +T_TRUNCATE , +T_UTIME , +T_RENAME , + T_REMOVE, };#endif
hw/9pfs/virtfs-proxy-helper.c +60 -1
79 lines not on this page · raw message
hw/9pfs/virtio-9p-proxy.c +122 -12
182 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 13/13 hw/9pfs: man page for proxy helper
In reply to M. Mohan KumarFrom: "M. Mohan Kumar" <[email protected]>
--- Makefile | 12 ++++++- hw/9pfs/virtfs-proxy-helper.texi | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletions(-) create mode 100644 hw/9pfs/virtfs-proxy-helper.texi
Makefile +11 -1
@@ -37,6 +37,7 @@ LIBS+=-lz $(LIBS_TOOLS) ifdef BUILD_DOCS DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 QMP/qmp-commands.txt +DOCS+=hw/9pfs/virtfs-proxy-helper.1 else DOCS= endif
@@ -283,7 +284,10 @@ ifdef CONFIG_POSIX $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8" $(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8" endif - +ifdef CONFIG_VIRTFS + $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" + $(INSTALL_DATA) hw/9pfs/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1" +endif install-sysconfig: $(INSTALL_DIR) "$(DESTDIR)$(sysconfdir)/qemu" $(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(sysconfdir)/qemu"
@@ -361,6 +365,12 @@ qemu-img.1: qemu-img.texi qemu-img-cmds.texi pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@, \ " GEN $@") +hw/9pfs/virtfs-proxy-helper.1: hw/9pfs/virtfs-proxy-helper.texi + $(call quiet-command, \ + perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< hw/9pfs/virtfs-proxy-helper.pod && \ + pod2man --section=1 --center=" " --release=" " hw/9pfs/virtfs-proxy-helper.pod > $@, \ + " GEN $@") + qemu-nbd.8: qemu-nbd.texi $(call quiet-command, \ perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-nbd.pod && \
hw/9pfs/virtfs-proxy-helper.texi new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.6