[LibOS] Do not get/put handles when adding/removing from epoll

Previously, Graphene explicitly incremented refcount of a handle added
to/removed from epoll, in epoll_ctl(EPOLL_CTL_ADD/EPOLL_CTL_DEL).
However, according to epoll(7), closing a file descriptor causes the
FD (handle) to be removed from all epoll sets. In other words,
adding/removing a handle to/from epoll must not count towards refcount
of the handle. Otherwise the handle remains dangling in the epoll set
even if it was close()'d (this particular case led to Nginx segfault).
This commit removes get/put of handle during epoll add/remove.
This commit is contained in:
Dmitrii Kuvaiskii
2019-09-28 15:31:41 +02:00
committed by Michał Kowalczyk
parent 1645e3435f
commit 0b6809fc19
+1 -2
View File
@@ -137,7 +137,6 @@ int delete_from_epoll_handles(struct shim_handle* handle) {
LISTP_DEL(epoll_fd, &handle->epolls, back);
unlock(&handle->lock);
put_handle(handle);
struct shim_handle* epoll_hdl = epoll_fd->epoll;
struct shim_epoll_handle* epoll = &epoll_hdl->info.epoll;
@@ -217,6 +216,7 @@ int shim_do_epoll_ctl(int epfd, int op, int fd, struct __kernel_epoll_event* eve
INIT_LIST_HEAD(epoll_fd, back);
LISTP_ADD_TAIL(epoll_fd, &hdl->epolls, back);
unlock(&hdl->lock);
put_handle(hdl);
INIT_LIST_HEAD(epoll_fd, list);
LISTP_ADD_TAIL(epoll_fd, &epoll->fds, list);
@@ -250,7 +250,6 @@ int shim_do_epoll_ctl(int epfd, int op, int fd, struct __kernel_epoll_event* eve
debug("delete handle %p from epoll handle %p\n", hdl, epoll);
put_handle(epoll_hdl);
put_handle(hdl);
LISTP_DEL(epoll_fd, &epoll->fds, list);
epoll->nfds--;