OSDN Git Service

iser-target: Fix possible use-after-free
authorSagi Grimberg <sagig@mellanox.com>
Thu, 4 Jun 2015 16:49:21 +0000 (19:49 +0300)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 9 Jun 2015 05:17:09 +0000 (22:17 -0700)
commit524630d5824c7a75aab568c6bd1423fd748cd3bb
tree3e20d18196345667e47b2c9380ca784eea9ddc6c
parent2f1b6b7d9a815f341b18dfd26a363f37d4d3c96a
iser-target: Fix possible use-after-free

iser connection termination process happens in 2 stages:
- isert_wait_conn:
  - resumes rdma disconnect
  - wait for session commands
  - wait for flush completions (post a marked wr to signal we are done)
  - wait for logout completion
  - queue work for connection cleanup (depends on disconnected/timewait
    events)
- isert_free_conn
  - last reference put on the connection

In case we are terminating during IOs, we might be posting send/recv
requests after we posted the last work request which might lead
to a use-after-free condition in isert_handle_wc.
After we posted the last wr in isert_wait_conn we are guaranteed that
no successful completions will follow (meaning no new work request posts
may happen) but other flush errors might still come. So before we
put the last reference on the connection, we repeat the process of
posting a marked work request (isert_wait4flush) in order to make sure all
pending completions were flushed.

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Jenny Falkovich <jennyf@mellanox.com>
Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/infiniband/ulp/isert/ib_isert.c