From 2b22692848e8f9e2e5d3d59707eeb8e883e25140 Mon Sep 17 00:00:00 2001 From: Hou Tao Date: Sat, 28 Oct 2017 20:58:22 +0800 Subject: [PATCH 3/8] epoll: remove file from tfile_check_list when releasing file Before the removal of epmutex, the acquisition of epmutex in eventpoll_release_file() will prevent the freeing of file, so it's OK to iterate files in tfile_check_list. And now epmutex is removed, so when releasing file, we need to remove file from tfile_check_list to ensure the validity of file. Signed-off-by: Hou Tao Signed-off-by: Wei Li --- fs/eventpoll.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index d326ba3d0866..7964c91cd603 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1016,6 +1016,18 @@ void eventpoll_release_file(struct file *file) ep_remove(ep, epi); mutex_unlock(&ep->mtx); } + + /* + * The file can not been added to tfile_check_list again, because + * (1) its refcnt has been zero, so ep_ctrl() can no longer get its reference + * (2) its related ep items have been removed, so ep_loop_check_proc() + * can not get the file by ep->rbr + */ + if (!list_empty_careful(&file->f_tfile_llink)) { + mutex_lock(&epmutex); + list_del_init(&file->f_tfile_llink); + mutex_unlock(&epmutex); + } } static int ep_alloc(struct eventpoll **pep) -- 2.17.1