From 0b6809fc19262d21e1ba2c7bbf0fca6cffab2280 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Tue, 24 Sep 2019 19:53:00 -0700 Subject: [PATCH] [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. --- LibOS/shim/src/sys/shim_epoll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LibOS/shim/src/sys/shim_epoll.c b/LibOS/shim/src/sys/shim_epoll.c index d305cd89..6f219f1a 100644 --- a/LibOS/shim/src/sys/shim_epoll.c +++ b/LibOS/shim/src/sys/shim_epoll.c @@ -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--;