Skip to contentSkip to conversation

hw/9pfs: Use O_NOFOLLOW when opening files on server

PATCH In review Aneesh Kumar K.V 2 participants 3 messages May 22, 2013 – May 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/9pfs: Use O_NOFOLLOW when opening files on server

From: "Aneesh Kumar K.V" <[email protected]>

9p server should never follow a symlink. So use O_NOFOLLOW with all open syscall

---
 hw/9pfs/virtio-9p-handle.c |  2 +-
 hw/9pfs/virtio-9p-local.c  | 48 +++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 42 insertions(+), 8 deletions(-)
hw/9pfs/virtio-9p-handle.c +1 -1
index fe8e0ed..e2a89e3 100644
@@ -608,7 +608,7 @@ static int handle_init(FsContext *ctx)
     struct file_handle fh;
     struct handle_data *data = g_malloc(sizeof(struct handle_data));
 
-    data->mountfd = open(ctx->fs_root, O_DIRECTORY);
+    data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_NOFOLLOW);
     if (data->mountfd < 0) {
         ret = data->mountfd;
         goto err_out;
hw/9pfs/virtio-9p-local.c +41 -7

96 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#1 lore raw

hw/9pfs/virtio-9p-handle.c static int handle_init(FsContext *ctx) · line 611

Quoted 10 lines · Aneesh Kumar K.V
hw/9pfs/virtio-9p-handle.c +1 -1
index fe8e0ed..e2a89e3 100644
@@ -608,7 +608,7 @@ static int handle_init(FsContext *ctx)
     struct file_handle fh;
     struct handle_data *data = g_malloc(sizeof(struct handle_data));
 
-    data->mountfd = open(ctx->fs_root, O_DIRECTORY);
+    data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_NOFOLLOW);

Why is the root path not allowed to be a symlink?

And if so, it would be more user-friendly to resolve the path before open. That way we don't need to bug the user with an error here.

#2 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Aneesh Kumar K.V
hw/9pfs/virtio-9p-handle.c +0 -0
index fe8e0ed..e2a89e3 100644
@@ -608,7 +608,7 @@ static int handle_init(FsContext *ctx)
     struct file_handle fh;
     struct handle_data *data = g_malloc(sizeof(struct handle_data));
 
Quoted 4 lines

hw/9pfs/virtio-9p-handle.c static int handle_init(FsContext *ctx) · line 611

Quoted 2 lines
hw/9pfs/virtio-9p-handle.c +1 -1
-    data->mountfd = open(ctx->fs_root, O_DIRECTORY);
+    data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_NOFOLLOW);

Why is the root path not allowed to be a symlink?

No specific reason.

Quoted 3 lines

And if so, it would be more user-friendly to resolve the path before open. That way we don't need to bug the user with an error here.

I will drop that hunk.

-aneesh