OSDN Git Service

RDMA/iw_cxgb4: ensure eps don't get freed while the mutex is held
authorHariprasad S <hariprasad@chelsio.com>
Wed, 4 May 2016 19:57:31 +0000 (01:27 +0530)
committerDoug Ledford <dledford@redhat.com>
Thu, 5 May 2016 20:11:14 +0000 (16:11 -0400)
commit6e410d8f7175caf2316c515f1ea0bf80d33b3158
tree06f9d18b62083f5cd0638daf72530b549b1b44a7
parent88bc230dc614b8e19000022d0ae2c1dfd578a0b0
RDMA/iw_cxgb4: ensure eps don't get freed while the mutex is held

In rx_data(), with the ep in FPDU_MODE, refcnt=2, if we get unexpected
streaming data, we call c4iw_modify_rc_qp() and move the qp from
RTS -> TERMINATE.  In c4iw_modify_rc_qp(), if rdma_fini() returns
an error, the ep will be dereferenced (refcnt=1).  Then rx_data()
calls c4iw_ep_disconnect() which starts the close operation.
But if send_halfclose() fails in c4iw_ep_disconnect(), we  will call
release_ep_resources() derefing the ep which reduces the refcnt to 0 and
and frees the ep. However we still has the ep mutex at that point, so we
have a touch-after-free bug.  There is a similar issue where
peer_close() calls c4iw_ep_disconnect().

The solution is to add a reference to the ep in c4iw_ep_disconnect()
after acquiring  the mutex, and release it after releasing the mutex.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/cxgb4/cm.c