[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/7] 9pfs: don't create files if pathname already ex
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PATCH 5/7] 9pfs: don't create files if pathname already exists |
Date: |
Tue, 10 Jan 2017 15:32:40 +0100 |
User-agent: |
StGit/0.17.1-20-gc0b1b-dirty |
As specified in the http://man.cat-v.org/plan_9/5/open :
"An attempt to create a file in a directory where the given
name already exists will be rejected"
Malicious code in a guest could for example create a named pipe and
then pass its name to the server in a RLCREATE message. This would
cause QEMU to hang in open(), waiting for someone to open the other
end of the pipe.
Let's fix this by simply using O_EXCL.
Signed-off-by: Greg Kurz <address@hidden>
---
hw/9pfs/9p.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index edd7b97270e3..d9686601deda 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1545,7 +1545,7 @@ static void coroutine_fn v9fs_lcreate(void *opaque)
flags = get_dotl_openflags(pdu->s, flags);
err = v9fs_co_open2(pdu, fidp, &name, gid,
- flags | O_CREAT, mode, &stbuf);
+ flags | O_CREAT | O_EXCL, mode, &stbuf);
if (err < 0) {
goto out;
}
@@ -2252,7 +2252,8 @@ static void coroutine_fn v9fs_create(void *opaque)
v9fs_path_copy(&fidp->path, &path);
} else {
err = v9fs_co_open2(pdu, fidp, &name, -1,
- omode_to_uflags(mode)|O_CREAT, perm, &stbuf);
+ omode_to_uflags(mode) | O_CREAT | O_EXCL, perm,
+ &stbuf);
if (err < 0) {
goto out;
}
- [Qemu-devel] [PATCH 0/7] fix potential hangs in 9pfs, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 1/7] 9pfs: restrict open to regular files and directories, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 2/7] tests: virtio-9p: improve error reporting, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 3/7] tests: virtio-9p: add LOPEN operation test, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 4/7] tests: virtio-9p: TLOPEN should fail to open a FIFO, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 5/7] 9pfs: don't create files if pathname already exists,
Greg Kurz <=
- [Qemu-devel] [PATCH 6/7] tests: virtio-9p: add LCREATE operation test, Greg Kurz, 2017/01/10
- [Qemu-devel] [PATCH 7/7] tests: virtio-9p: TLCREATE should fail if pathname exists, Greg Kurz, 2017/01/10