[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC 02/36] 9pfs: local: split chmod operation per se
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PATCH RFC 02/36] 9pfs: local: split chmod operation per security model |
Date: |
Mon, 30 Jan 2017 13:09:52 +0100 |
User-agent: |
StGit/0.17.1-20-gc0b1b-dirty |
Having all security models implemented in one monolithic function is
cumbersome. Especially when the need arises to fix something in the
shared code, as it forces to change all the paths at the same time.
This doesn't fix any bug, it is just preparatory cleanup.
Signed-off-by: Greg Kurz <address@hidden>
---
hw/9pfs/9p-local.c | 46 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 7de07e1ba67f..73a20657f1fc 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -461,25 +461,53 @@ static ssize_t local_pwritev(FsContext *ctx,
V9fsFidOpenState *fs,
return ret;
}
-static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
+static int local_chmod_mapped(FsContext *fs_ctx, V9fsPath *fs_path,
+ FsCred *credp)
+{
+ char *buffer;
+ int ret = -1;
+ char *path = fs_path->data;
+
+ buffer = rpath(fs_ctx, path);
+ ret = local_set_xattr(buffer, credp);
+ g_free(buffer);
+
+ return ret;
+}
+
+static int local_chmod_passthrough(FsContext *fs_ctx, V9fsPath *fs_path,
+ FsCred *credp)
{
char *buffer;
int ret = -1;
char *path = fs_path->data;
+ buffer = rpath(fs_ctx, path);
+ ret = chmod(buffer, credp->fc_mode);
+ g_free(buffer);
+
+ return ret;
+}
+
+static int local_chmod_mapped_file(FsContext *fs_ctx, V9fsPath *fs_path,
+ FsCred *credp)
+{
+ char *path = fs_path->data;
+
+ return local_set_mapped_file_attr(fs_ctx, path, credp);
+}
+
+static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
+{
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
- buffer = rpath(fs_ctx, path);
- ret = local_set_xattr(buffer, credp);
- g_free(buffer);
+ return local_chmod_mapped(fs_ctx, fs_path, credp);
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
- return local_set_mapped_file_attr(fs_ctx, path, credp);
+ return local_chmod_mapped_file(fs_ctx, fs_path, credp);
} else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
(fs_ctx->export_flags & V9FS_SM_NONE)) {
- buffer = rpath(fs_ctx, path);
- ret = chmod(buffer, credp->fc_mode);
- g_free(buffer);
+ return local_chmod_passthrough(fs_ctx, fs_path, credp);
}
- return ret;
+ g_assert_not_reached();
}
static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
- [Qemu-devel] [PATCH RFC 00/36] 9pfs: local: fix vulnerability to symlink attacks, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 01/36] 9pfs: local: move xattr security ops to 9p-xattr.c, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 02/36] 9pfs: local: split chmod operation per security model,
Greg Kurz <=
- [Qemu-devel] [PATCH RFC 03/36] 9pfs: local: split mknod operation per security model, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 04/36] 9pfs: local: split mkdir operation per security model, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 05/36] 9pfs: local: split open2 operation per security model, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 08/36] 9pfs: local: improve error handling in link op, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 09/36] 9pfs: local: post link operation for mapped-file security, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 07/36] 9pfs: local: split mkdir operation per security model, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 10/36] v9fs: local: improve error handling in rename op, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 11/36] 9pfs: local: post rename operation for mapped-file security, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 12/36] 9pfs: local: pre remove operation for mapped-file security, Greg Kurz, 2017/01/30
- [Qemu-devel] [PATCH RFC 06/36] 9pfs: local: split symlink operation per security model, Greg Kurz, 2017/01/30