Received: by 10.223.185.116 with SMTP id b49csp829522wrg; Sat, 10 Feb 2018 21:24:59 -0800 (PST) X-Google-Smtp-Source: AH8x224K13S8VYkBfZ49czAMGXO/N4QvgBTw4hy9xq8xKwSmwE0yfuS8r5DKa64lPEkAt6BnLi93 X-Received: by 2002:a17:902:52ed:: with SMTP id a100-v6mr6925695pli.75.1518326699780; Sat, 10 Feb 2018 21:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326699; cv=none; d=google.com; s=arc-20160816; b=HNdBc/Jl8rjnJ7cDrL+OV7sL7zRce+ta1boaKhicYJLI3V0hLm3LFB9jN6p+q+20+e u37DcDbqz7FJPeB4PcKB2ynEKuPw+SqpnaxVyxryCfR35EL3WjbM928w4oE2m30I3DvZ JIH+smC55pk6tRne9qvJGuS8QItt4NVjjgObW8FyBfEtuBxsGmt+F+ocjk1jJMwI1lfb V5FXSQlvnK0PQXZP26+lWVRJ+lXH9FRjNeeksOZY3VK5miyJK5i/L69eB8opGIrXcB2s FdNHNccdP4rD9H4JZYAo5GrBYAR49e2XOD79F1rxvmzz3QZoz3u5ExuOv6AxZtyrEKsn eSnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=CCF/mLu2RDSEGNTXRRw14+c+q8o6WfLVNqYmxG/DO5Q=; b=QGSSRfJmFHauOsBbgWgi/G+YBfY5lpZi8MNzX2Jy4K0lLBci0g6S6H9mD9DHcEv6oR 7KPAs6pUYiKLHUykVjSmMtFv9yeRfBOnqiJJ5JP2AmvRMEE2mQcYS/VSAOinYxs3sLvC 0Brl/LLOpSNBO1ngU3Tx13/BkJ0cw6RTnXaq/dPqs26SKBWEXB08uq70lUvrllR6zujE LGYo3q/lf6uaXH/jGIBqyud0kapN3BVdIrWrvmwzwO17V3XyYA8P2ooexQgudjcE/8zA mOWnbOsadJt0mFHP/1UhBaJCGLgylFdZf0elZcpfIWWGoxVdwePdicQ1Uzn865CbIurE jF4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si2431943pgs.308.2018.02.10.21.24.45; Sat, 10 Feb 2018 21:24:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932109AbeBKFXV (ORCPT + 99 others); Sun, 11 Feb 2018 00:23:21 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41340 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752531AbeBKEdk (ORCPT ); Sat, 10 Feb 2018 23:33:40 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKc-0002hK-Ei; Sun, 11 Feb 2018 04:33:38 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004SE-76; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Bart Van Assche" , "Sagi Grimberg" , "Doug Ledford" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 10/79] IB/srp: Avoid that a cable pull can trigger a kernel crash In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 8a0d18c62121d3c554a83eb96e2752861d84d937 upstream. This patch fixes the following kernel crash: general protection fault: 0000 [#1] PREEMPT SMP Workqueue: ib_mad2 timeout_sends [ib_core] Call Trace: ib_sa_path_rec_callback+0x1c4/0x1d0 [ib_core] send_handler+0xb2/0xd0 [ib_core] timeout_sends+0x14d/0x220 [ib_core] process_one_work+0x200/0x630 worker_thread+0x4e/0x3b0 kthread+0x113/0x150 Fixes: commit aef9ec39c47f ("IB: Add SCSI RDMA Protocol (SRP) initiator") Signed-off-by: Bart Van Assche Reviewed-by: Sagi Grimberg Signed-off-by: Doug Ledford [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings --- --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -310,10 +310,19 @@ static void srp_path_rec_completion(int static int srp_lookup_path(struct srp_target_port *target) { + int ret = -ENODEV; + target->path.numb_path = 1; init_completion(&target->done); + /* + * Avoid that the SCSI host can be removed by srp_remove_target() + * before srp_path_rec_completion() is called. + */ + if (!scsi_host_get(target->scsi_host)) + goto out; + target->path_query_id = ib_sa_path_rec_get(&srp_sa_client, target->srp_host->srp_dev->dev, target->srp_host->port, @@ -327,16 +336,22 @@ static int srp_lookup_path(struct srp_ta GFP_KERNEL, srp_path_rec_completion, target, &target->path_query); - if (target->path_query_id < 0) - return target->path_query_id; + ret = target->path_query_id; + if (ret < 0) + goto put; wait_for_completion(&target->done); - if (target->status < 0) + ret = target->status; + if (ret < 0) shost_printk(KERN_WARNING, target->scsi_host, PFX "Path record query failed\n"); - return target->status; +put: + scsi_host_put(target->scsi_host); + +out: + return ret; } static int srp_send_req(struct srp_target_port *target)