staging: lustre: o2iblnd: Fix crash in kiblnd_handle_early_rxs()
authorDoug Oucharek <dougso@me.com>
Thu, 10 May 2018 18:07:01 +0000 (11:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 May 2018 11:55:05 +0000 (13:55 +0200)
Under upstream staging commit 5a2ca43fa54f561c252c2, the list handling
code in kiblnd_handle_early_rxs() got changed to list_for_each_safe().
That protects against the current thread from deleting the current entry
it is looking at. It does not protect against another thread from deleting
the next item in the list (which the tmp variable points to). The way this
routine holds then releases a lock opens the door to other threads doing
just that.

This patch reverts this commit on this routine.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-9886
Fixes: 5a2ca43fa54f ("Staging: lustre: Iterate list using list_for_each_entry")
Signed-off-by: Doug Oucharek <dougso@me.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c

index 32fa8cafe9ea9de70c4e2537c81c995eb824516b..47eb8b4c28db16d361499e7a28ca6abc183c3780 100644 (file)
@@ -1965,13 +1965,14 @@ kiblnd_handle_early_rxs(struct kib_conn *conn)
 {
        unsigned long flags;
        struct kib_rx *rx;
-       struct kib_rx *tmp;
 
        LASSERT(!in_interrupt());
        LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
 
        write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
-       list_for_each_entry_safe(rx, tmp, &conn->ibc_early_rxs, rx_list) {
+       while (!list_empty(&conn->ibc_early_rxs)) {
+               rx = list_entry(conn->ibc_early_rxs.next,
+                               struct kib_rx, rx_list);
                list_del(&rx->rx_list);
                write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);