lkml.org 
[lkml]   [2020]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.19 34/38] epoll: do not insert into poll queues until all sanity checks are done
    Date
    From: Al Viro <viro@zeniv.linux.org.uk>

    commit f8d4f44df056c5b504b0d49683fb7279218fd207 upstream.

    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    fs/eventpoll.c | 37 ++++++++++++++++++-------------------
    1 file changed, 18 insertions(+), 19 deletions(-)

    --- a/fs/eventpoll.c
    +++ b/fs/eventpoll.c
    @@ -1450,6 +1450,22 @@ static int ep_insert(struct eventpoll *e
    RCU_INIT_POINTER(epi->ws, NULL);
    }

    + /* Add the current item to the list of active epoll hook for this file */
    + spin_lock(&tfile->f_lock);
    + list_add_tail_rcu(&epi->fllink, &tfile->f_ep_links);
    + spin_unlock(&tfile->f_lock);
    +
    + /*
    + * Add the current item to the RB tree. All RB tree operations are
    + * protected by "mtx", and ep_insert() is called with "mtx" held.
    + */
    + ep_rbtree_insert(ep, epi);
    +
    + /* now check if we've created too many backpaths */
    + error = -EINVAL;
    + if (full_check && reverse_path_check())
    + goto error_remove_epi;
    +
    /* Initialize the poll table using the queue callback */
    epq.epi = epi;
    init_poll_funcptr(&epq.pt, ep_ptable_queue_proc);
    @@ -1472,22 +1488,6 @@ static int ep_insert(struct eventpoll *e
    if (epi->nwait < 0)
    goto error_unregister;

    - /* Add the current item to the list of active epoll hook for this file */
    - spin_lock(&tfile->f_lock);
    - list_add_tail_rcu(&epi->fllink, &tfile->f_ep_links);
    - spin_unlock(&tfile->f_lock);
    -
    - /*
    - * Add the current item to the RB tree. All RB tree operations are
    - * protected by "mtx", and ep_insert() is called with "mtx" held.
    - */
    - ep_rbtree_insert(ep, epi);
    -
    - /* now check if we've created too many backpaths */
    - error = -EINVAL;
    - if (full_check && reverse_path_check())
    - goto error_remove_epi;
    -
    /* We have to drop the new item inside our item list to keep track of it */
    spin_lock_irq(&ep->wq.lock);

    @@ -1516,6 +1516,8 @@ static int ep_insert(struct eventpoll *e

    return 0;

    +error_unregister:
    + ep_unregister_pollwait(ep, epi);
    error_remove_epi:
    spin_lock(&tfile->f_lock);
    list_del_rcu(&epi->fllink);
    @@ -1523,9 +1525,6 @@ error_remove_epi:

    rb_erase_cached(&epi->rbn, &ep->rbr);

    -error_unregister:
    - ep_unregister_pollwait(ep, epi);
    -
    /*
    * We need to do this because an event could have been arrived on some
    * allocated wait queue. Note that we don't care about the ep->ovflist

    \
     
     \ /
      Last update: 2020-10-05 17:28    [W:4.095 / U:0.048 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site