virtio-9p: Use layered xattr approach
PATCH 1/2 virtio-9p: Use layered xattr approach
We would need this to make sure we handle the mapped security model correctly for different xattr names.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- Makefile.objs | 2 +- hw/file-op-9p.h | 11 ++++ hw/virtio-9p-local.c | 95 ++------------------------------- hw/virtio-9p-xattr-user.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p-xattr.c | 111 +++++++++++++++++++++++++++++++++++++++ hw/virtio-9p-xattr.h | 67 +++++++++++++++++++++++ hw/virtio-9p.c | 6 ++- 7 files changed, 328 insertions(+), 92 deletions(-) create mode 100644 hw/virtio-9p-xattr-user.c create mode 100644 hw/virtio-9p-xattr.c create mode 100644 hw/virtio-9p-xattr.h
Makefile.objs +1 -1
@@ -245,7 +245,7 @@ sound-obj-$(CONFIG_CS4231A) += cs4231a.o adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0 hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) -hw-obj-$(CONFIG_VIRTFS) += virtio-9p-debug.o virtio-9p-local.o +hw-obj-$(CONFIG_VIRTFS) += virtio-9p-debug.o virtio-9p-local.o virtio-9p-xattr.o virtio-9p-xattr-user.o ###################################################################### # libdis
hw/file-op-9p.h +11 -0
@@ -47,11 +47,14 @@ typedef struct FsCreddev_t fc_rdev; } FsCred; +struct xattr_operations ; +typedef struct FsContext {char *fs_root;SecModel fs_sm;uid_t uid; +struct xattr_operations **xops; }FsContext ;extern void cred_init (FsCred *);
@@ -94,4 +97,12 @@ typedef struct FileOperationsint (*lremovexattr)(FsContext *,const char *,const char *); void *opaque; } FileOperations; + +static inline const char *rpath (FsContext *ctx,const char *path) +{ +/* FIXME: so wrong... */ +static char buffer[4096 ]; +snprintf (buffer,sizeof (buffer),"%s/%s" , ctx->fs_root, path); +return buffer; +}#endif
hw/virtio-9p-local.c +5 -90
128 lines not on this page · raw message
hw/virtio-9p-xattr-user.c new file +128 -0
128 lines not on this page · raw message
hw/virtio-9p-xattr.c new file +111 -0
111 lines not on this page · raw message
hw/virtio-9p-xattr.h new file +67 -0
67 lines not on this page · raw message
hw/virtio-9p.c +5 -1
@@ -17,6 +17,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "virtio-9p-debug.h" +#include "virtio-9p-xattr.h" int debug_9p_pdu;
@@ -3541,23 +3542,26 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)if (!strcmp (fse->security_model,"passthrough" )) {/* Files on the Fileserver set to client user credentials */ s->ctx.fs_sm =SM_PASSTHROUGH ; + s->ctx.xops = passthrough_xattr_ops; }else if (!strcmp (fse->security_model,"mapped" )) {/* Files on the fileserver are set to QEMU credentials. * Client user credentials are saved in extended attributes. */ s->ctx.fs_sm =SM_MAPPED ; + s->ctx.xops = mapped_xattr_ops; }else if (!strcmp (fse->security_model,"none" )) {/* * Files on the fileserver are set to QEMU credentials. */ s->ctx.fs_sm =SM_NONE ; - + s->ctx.xops = none_xattr_ops; }else {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" ); s->ctx.fs_sm =SM_NONE ; + s->ctx.xops = none_xattr_ops; }if (lstat (fse->path, &stat)) {
Signature · 1 line
1.7.0.4
PATCH 2/2 virtio-9p: Support mapped posix acl
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- Makefile.objs | 3 +- hw/virtio-9p-posix-acl.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p-xattr.c | 4 + hw/virtio-9p-xattr.h | 28 +++++++++ 4 files changed, 178 insertions(+), 1 deletions(-) create mode 100644 hw/virtio-9p-posix-acl.c
Makefile.objs +2 -1
@@ -245,7 +245,8 @@ sound-obj-$(CONFIG_CS4231A) += cs4231a.o adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0 hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) -hw-obj-$(CONFIG_VIRTFS) += virtio-9p-debug.o virtio-9p-local.o virtio-9p-xattr.o virtio-9p-xattr-user.o +hw-obj-$(CONFIG_VIRTFS) += virtio-9p-debug.o virtio-9p-local.o virtio-9p-xattr.o +hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o ###################################################################### # libdis
hw/virtio-9p-posix-acl.c new file +144 -0
144 lines not on this page · raw message
hw/virtio-9p-xattr.c +4 -0
@@ -96,16 +96,20 @@ int v9fs_remove_xattr(FsContext *ctx,XattrOperations *mapped_xattr_ops[] = { &mapped_user_xattr, + &mapped_pacl_xattr, + &mapped_dacl_xattr,NULL , };XattrOperations *passthrough_xattr_ops[] = { &passthrough_user_xattr, + &passthrough_acl_xattr,NULL , };/* for .user none model should be same as passthrough */ XattrOperations *none_xattr_ops[] = { &passthrough_user_xattr, + &none_acl_xattr,NULL , };
hw/virtio-9p-xattr.h +28 -0
@@ -32,6 +32,11 @@ typedef struct xattr_operationsextern XattrOperations mapped_user_xattr;extern XattrOperations passthrough_user_xattr; +extern XattrOperations mapped_pacl_xattr; +extern XattrOperations mapped_dacl_xattr; +extern XattrOperations passthrough_acl_xattr; +extern XattrOperations none_acl_xattr; +extern XattrOperations *mapped_xattr_ops[];extern XattrOperations *passthrough_xattr_ops[];extern XattrOperations *none_xattr_ops[];
@@ -64,4 +69,27 @@ static inline int pt_removexattr(FsContext *ctx, return lremovexattr(rpath(ctx, path), name); } +static inline ssize_t notsup_getxattr (FsContext *ctx,const char *path, +const char *name,void *value, +size_t size) +{ + errno =ENOTSUP ; +return -1 ; +} + +static inline int notsup_setxattr (FsContext *ctx,const char *path, +const char *name,void *value, +size_t size,int flags) +{ + errno =ENOTSUP ; +return -1 ; +} + +static inline int notsup_removexattr (FsContext *ctx, +const char *path,const char *name) +{ + errno =ENOTSUP ; +return -1 ; +} +#endif
Signature · 1 line
1.7.0.4