From patchwork Tue Feb 14 18:56:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9572523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B926601E7 for ; Tue, 14 Feb 2017 18:56:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1439B27DCD for ; Tue, 14 Feb 2017 18:56:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08E442845E; Tue, 14 Feb 2017 18:56:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD37627DCD for ; Tue, 14 Feb 2017 18:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752880AbdBNS4s (ORCPT ); Tue, 14 Feb 2017 13:56:48 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:26512 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752833AbdBNS4q (ORCPT ); Tue, 14 Feb 2017 13:56:46 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86579468" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 02:56:43 +0800 Received: from MILHUBIP03.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id BC.34.57638.BE253A85; Tue, 14 Feb 2017 10:56:43 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Tue, 14 Feb 2017 10:56:39 -0800 X-AuditID: 0ac94369-26dee9800001e126-4f-58a352eb6a04 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id C0.D6.18148.8E253A85; Tue, 14 Feb 2017 10:56:40 -0800 (PST) From: Bart Van Assche To: Doug Ledford CC: , Bart Van Assche , Israel Rukshin , Max Gurtovoy , Laurence Oberman , Steve Feeley , Subject: [PATCH v2 2/8] IB/srp: Avoid that duplicate responses trigger a kernel bug Date: Tue, 14 Feb 2017 10:56:30 -0800 Message-ID: <20170214185636.29250-3-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170214185636.29250-1-bart.vanassche@sandisk.com> References: <20170214185636.29250-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRmVeSWpSXmKPExsXCddJ5ke7roMURBpse6lq8PP+B1eLG4rUs Fs8O9bJYnP/wisni9KMD7BYLNj5idGDzeDb9MJPH+31X2Tw+b5ILYI7isklJzcksSy3St0vg ynj13LpgLV/Fy7NPWRoYW3m6GDk5JARMJDo63zF2MXJxCAksZZJYsXQPE4SzjVHixf1prDBV M39+YYNIbGSUmPz6ITtIgk3ASOLb+5ksILaIgJrEpleL2EGKmAU6mCT+nz0K1M3BISwQLLHx iCyIySKgKnH6QhpIOa+AvcSJ1zcZIebLS+xquwi2i1PAQWLmt4VgthBQzdn+OWAjJQSmsUr0 b33PBNEsKHFy5hOwvcwCEhIHX7xghmhQlzi5ZD7TBEahWUjKZiEpW8DItIpRLDczpzg3PbXA 0FSvODEvJbM4Wy85P3cTIyTEM3cw3n3ifYhRgINRiYf3hOziCCHWxLLiytxDjBIczEoivBoO QCHelMTKqtSi/Pii0pzU4kOM0hwsSuK852SmRggJpCeWpGanphakFsFkmTg4pRoYd0WkTb74 YsHBnPfvjhzYdOmjruXfbR9vZMYtve3l9pv7doEJf8DvLZsKt/j0Jf2e+lj979xf3vNF3K9s Wj3thw9j/rRp1sKPDmrVGtz0Sfq9QtONaUmngYmdUnxoe9itz0xxj0/5bPe2CjfbMm3m7znG cTFvHvhv8NNy3fD484p56Yez0yQNvimxFGckGmoxFxUnAgDycmlfbQIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHJMWRmVeSWpSXmKPExsXCtZGTTfdF0OIIg0032S0O/mxjtHh5/gOr xY3Fa1ksnh3qZbE4/+EVk8XpRwfYLRZsfMRo8fXlC2YHDo9n0w8zebzfd5XNY9qa80wenzfJ BbBEcdmkpOZklqUW6dslcGW8em5dsJav4uXZpywNjK08XYycHBICJhIzf35h62Lk4hASWM8o 8X5xBztIgk3ASOLb+5ksILaIgJrEpleL2EGKmAW6mCTOt/1l7GLk4BAWCJbYeEQWxGQRUJU4 fSENpJxXwF6i78t5Noj58hK72i6ygticAg4SM78tBLOFgGrO9s9hn8DIvYCRYRWjWG5mTnFu emaBoZFecWJeSmZxtl5yfu4mRkiIRO1gvD7R/BAjEwenVANj9JPeDY077J9Z9ou9S7CyfP3k 6m/T5+0PTu0qrAiKd/rYdqBOp08j0+n9rqOnis0Fpr4/OWf2U4dU2apT6j5NgpsKnLc8jGj/ pM4olNm+fLrsKwMlIYeQa4cfBgY0G5yzP5zr+za7YKJvtHO00TuRoJ0TBNelLjrbdTI/4IHX x8OFTTHpya+UWIozEg21mIuKEwFBJ7OhwQEAAA== MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After srp_process_rsp() returns there is a short time during which the scsi_host_find_tag() call will return a pointer to the SCSI command that is being completed. If during that time a duplicate response is received, avoid that the following call stack appears: BUG: unable to handle kernel NULL pointer dereference at (null) IP: srp_recv_done+0x450/0x6b0 [ib_srp] Oops: 0000 [#1] SMP CPU: 10 PID: 0 Comm: swapper/10 Not tainted 4.10.0-rc7-dbg+ #1 Call Trace: __ib_process_cq+0x4b/0xd0 [ib_core] ib_poll_handler+0x1d/0x70 [ib_core] irq_poll_softirq+0xba/0x120 __do_softirq+0xba/0x4c0 irq_exit+0xbe/0xd0 smp_apic_timer_interrupt+0x38/0x50 apic_timer_interrupt+0x90/0xa0 RIP: srp_recv_done+0x450/0x6b0 [ib_srp] RSP: ffff88046f483e20 Signed-off-by: Bart Van Assche Cc: Israel Rukshin Cc: Max Gurtovoy Cc: Laurence Oberman Cc: Steve Feeley Cc: Reviewed-by: Leon Romanovsky --- drivers/infiniband/ulp/srp/ib_srp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 07e3613e4798..12027e3a4dec 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -1892,9 +1892,11 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp) complete(&ch->tsk_mgmt_done); } else { scmnd = scsi_host_find_tag(target->scsi_host, rsp->tag); - if (scmnd) { + if (scmnd && scmnd->host_scribble) { req = (void *)scmnd->host_scribble; scmnd = srp_claim_req(ch, req, NULL, scmnd); + } else { + scmnd = NULL; } if (!scmnd) { shost_printk(KERN_ERR, target->scsi_host,