IB/srp: Fix use-after-free in srp_reset_req()
authorBart Van Assche <bvanassche@acm.org>
Fri, 24 Aug 2012 10:27:54 +0000 (10:27 +0000)
committerRoland Dreier <roland@purestorage.com>
Mon, 1 Oct 2012 03:36:47 +0000 (20:36 -0700)
srp_free_req() uses the scsi_cmnd structure contents to unmap
buffers, so we must invoke srp_free_req() before we release
ownership of that structure.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: David Dillow <dillowda@ornl.gov>
Cc: <stable@vger.kernel.org>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/ulp/srp/ib_srp.c

index 1b5b0c7300549cefee683b3d5745b39a446b5bca..ac66e6b43ee200030b9882e9e3d49d8d0cda049b 100644 (file)
@@ -638,9 +638,9 @@ static void srp_reset_req(struct srp_target_port *target, struct srp_request *re
        struct scsi_cmnd *scmnd = srp_claim_req(target, req, NULL);
 
        if (scmnd) {
+               srp_free_req(target, req, scmnd, 0);
                scmnd->result = DID_RESET << 16;
                scmnd->scsi_done(scmnd);
-               srp_free_req(target, req, scmnd, 0);
        }
 }