[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 094/109] virtiofsd: passthrough_ll: fix refcounting on remove/
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PATCH v2 094/109] virtiofsd: passthrough_ll: fix refcounting on remove/rename |
Date: |
Tue, 21 Jan 2020 12:24:18 +0000 |
From: Miklos Szeredi <address@hidden>
Signed-off-by: Miklos Szeredi <address@hidden>
Reviewed-by: Misono Tomohiro <address@hidden>
---
tools/virtiofsd/passthrough_ll.c | 50 +++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 9f37829824..0dc3011919 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1140,17 +1140,42 @@ out_err:
fuse_reply_err(req, saverr);
}
+static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
+ const char *name)
+{
+ int res;
+ struct stat attr;
+
+ res = fstatat(lo_fd(req, parent), name, &attr,
+ AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+ if (res == -1) {
+ return NULL;
+ }
+
+ return lo_find(lo_data(req), &attr);
+}
+
static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
{
int res;
+ struct lo_inode *inode;
+ struct lo_data *lo = lo_data(req);
+
if (!is_safe_path_component(name)) {
fuse_reply_err(req, EINVAL);
return;
}
+ inode = lookup_name(req, parent, name);
+ if (!inode) {
+ fuse_reply_err(req, EIO);
+ return;
+ }
+
res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR);
fuse_reply_err(req, res == -1 ? errno : 0);
+ unref_inode_lolocked(lo, inode, 1);
}
static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
@@ -1158,12 +1183,23 @@ static void lo_rename(fuse_req_t req, fuse_ino_t
parent, const char *name,
unsigned int flags)
{
int res;
+ struct lo_inode *oldinode;
+ struct lo_inode *newinode;
+ struct lo_data *lo = lo_data(req);
if (!is_safe_path_component(name) || !is_safe_path_component(newname)) {
fuse_reply_err(req, EINVAL);
return;
}
+ oldinode = lookup_name(req, parent, name);
+ newinode = lookup_name(req, newparent, newname);
+
+ if (!oldinode) {
+ fuse_reply_err(req, EIO);
+ goto out;
+ }
+
if (flags) {
#ifndef SYS_renameat2
fuse_reply_err(req, EINVAL);
@@ -1176,26 +1212,38 @@ static void lo_rename(fuse_req_t req, fuse_ino_t
parent, const char *name,
fuse_reply_err(req, res == -1 ? errno : 0);
}
#endif
- return;
+ goto out;
}
res = renameat(lo_fd(req, parent), name, lo_fd(req, newparent), newname);
fuse_reply_err(req, res == -1 ? errno : 0);
+out:
+ unref_inode_lolocked(lo, oldinode, 1);
+ unref_inode_lolocked(lo, newinode, 1);
}
static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
{
int res;
+ struct lo_inode *inode;
+ struct lo_data *lo = lo_data(req);
if (!is_safe_path_component(name)) {
fuse_reply_err(req, EINVAL);
return;
}
+ inode = lookup_name(req, parent, name);
+ if (!inode) {
+ fuse_reply_err(req, EIO);
+ return;
+ }
+
res = unlinkat(lo_fd(req, parent), name, 0);
fuse_reply_err(req, res == -1 ? errno : 0);
+ unref_inode_lolocked(lo, inode, 1);
}
static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
--
2.24.1
- [PATCH v2 085/109] Virtiofsd: fix memory leak on fuse queueinfo, (continued)
- [PATCH v2 085/109] Virtiofsd: fix memory leak on fuse queueinfo, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 086/109] virtiofsd: Support remote posix locks, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 088/109] virtiofsd: prevent fv_queue_thread() vs virtio_loop() races, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 087/109] virtiofsd: use fuse_lowlevel_is_virtio() in fuse_session_destroy(), Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 089/109] virtiofsd: make lo_release() atomic, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 090/109] virtiofsd: prevent races with lo_dirp_put(), Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 091/109] virtiofsd: rename inode->refcount to inode->nlookup, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 092/109] libvhost-user: Fix some memtable remap cases, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 093/109] virtiofsd: add man page, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 094/109] virtiofsd: passthrough_ll: fix refcounting on remove/rename,
Dr. David Alan Gilbert (git) <=
- [PATCH v2 095/109] virtiofsd: introduce inode refcount to prevent use-after-free, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 096/109] virtiofsd: do not always set FUSE_FLOCK_LOCKS, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 098/109] virtiofsd: Reset O_DIRECT flag during file open, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 097/109] virtiofsd: convert more fprintf and perror to use fuse log infra, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 100/109] virtiofsd: add definition of fuse_buf_writev(), Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 099/109] virtiofsd: Fix data corruption with O_APPEND write in writeback mode, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 101/109] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for better performance, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 102/109] virtiofsd: process requests in a thread pool, Dr. David Alan Gilbert (git), 2020/01/21
- [PATCH v2 103/109] virtiofsd: prevent FUSE_INIT/FUSE_DESTROY races, Dr. David Alan Gilbert (git), 2020/01/21