[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 088/104] virtiofsd: make lo_release() atomic
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PATCH 088/104] virtiofsd: make lo_release() atomic |
Date: |
Thu, 12 Dec 2019 16:38:48 +0000 |
From: Stefan Hajnoczi <address@hidden>
Hold the lock across both lo_map_get() and lo_map_remove() to prevent
races between two FUSE_RELEASE requests. In this case I don't see a
serious bug but it's safer to do things atomically.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
tools/virtiofsd/passthrough_ll.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index fc79d5ac43..eadd568435 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1805,14 +1805,18 @@ static void lo_release(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
struct lo_data *lo = lo_data(req);
- int fd;
+ struct lo_map_elem *elem;
+ int fd = -1;
(void)ino;
- fd = lo_fi_fd(req, fi);
-
pthread_mutex_lock(&lo->mutex);
- lo_map_remove(&lo->fd_map, fi->fh);
+ elem = lo_map_get(&lo->fd_map, fi->fh);
+ if (elem) {
+ fd = elem->fd;
+ elem = NULL;
+ lo_map_remove(&lo->fd_map, fi->fh);
+ }
pthread_mutex_unlock(&lo->mutex);
close(fd);
--
2.23.0
- [PATCH 079/104] virtiofsd: fix memory leak on lo.source, (continued)
- [PATCH 079/104] virtiofsd: fix memory leak on lo.source, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 080/104] virtiofsd: add helper for lo_data cleanup, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 081/104] virtiofsd: Prevent multiply running with same vhost_user_socket, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 082/104] virtiofsd: enable PARALLEL_DIROPS during INIT, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 084/104] Virtiofsd: fix memory leak on fuse queueinfo, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 083/104] virtiofsd: fix incorrect error handling in lo_do_lookup, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 086/104] virtiofsd: use fuse_lowlevel_is_virtio() in fuse_session_destroy(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 085/104] virtiofsd: Support remote posix locks, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 087/104] virtiofsd: prevent fv_queue_thread() vs virtio_loop() races, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 089/104] virtiofsd: prevent races with lo_dirp_put(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 088/104] virtiofsd: make lo_release() atomic,
Dr. David Alan Gilbert (git) <=
- [PATCH 091/104] libvhost-user: Fix some memtable remap cases, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 090/104] virtiofsd: rename inode->refcount to inode->nlookup, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 092/104] virtiofsd: add man page, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 094/104] virtiofsd: do not always set FUSE_FLOCK_LOCKS, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 095/104] virtiofsd: convert more fprintf and perror to use fuse log infra, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 093/104] virtiofsd: introduce inode refcount to prevent use-after-free, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 096/104] virtiofsd: Reset O_DIRECT flag during file open, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 097/104] virtiofsd: Fix data corruption with O_APPEND wirte in writeback mode, Dr. David Alan Gilbert (git), 2019/12/12