@@ -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;
}
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 <groug@kaod.org> --- hw/9pfs/9p.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)