Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp647192imu; Fri, 11 Jan 2019 06:45:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN7nPj8KxZKJ+QXhvFjxj4zd/xaokr8sDBaFRo2DdBukn9oBqb8JVMkQq4mZN6Jm9v6v2oS4 X-Received: by 2002:a63:ec13:: with SMTP id j19mr13509050pgh.6.1547217933984; Fri, 11 Jan 2019 06:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547217933; cv=none; d=google.com; s=arc-20160816; b=dRlrHJvjEEGmipi49JWOoETMFtetENJLeLieX+l1b9VpcUukDpgnG56f4gWOIIWaqE PvakmFUiJzLwUmoCPg0Dcz4IixdsfbSX9jr7e7I98siNlkFx7TToZfy82MacY5kHshu1 m3n5TRKvrbwd5Di7TN5WzTzzHGpW+U5B1uR7Lc+q0kt9gpS0EXCpdOA+7hIZXRdMq67y wh6mK1ln2LKcbZNzCGEbPRiJFX6FiSq8kPiVOFKkwarIYS0umgpNKVaeU5dF5vGoGJbI QQZVJcdS+EM2ZxRuaQr1Pc3EnTu2RM6l8Wlc9B3yj8ylqmXmV7O63rTBbiZBD+ml4Irr tYJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O/kzD/L4/EpIrSklOdxFdME72nd1YrZBgrFwSINNtoo=; b=TV4+Htm8Ss4Id+8+qxJcZ8FPxE9qsm7+rEUX1mN32ABsB8SzFyG0EYxkQEvexgwhuA R4jiAVEljdBkmT5N8ZAXqrnZZD6HbQf9fFJaUQP64N/3RE6f/2+ce3EoNwJuxy7ssXas oDlSlf8aFBCxSfd3Jb9d4cvt2XxhAKniATQmi5sdkfoPThP3XnXp+74A2wJHqYm6YSFv REe+Ovb07ONZW3i2yndpA3CDzHMOrnvZjPnLU6CYJ5SfmqPdhwgEdVT4gKM309iL4aii 558lV/FTTJL5S25WpBv0AsQfTvtVhENCfiQbeaZxBYSGi5qdSNamurMpsi+s2vaSmQTc wGWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iIOmsrs9; 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 f65si14871716pfb.194.2019.01.11.06.45.18; Fri, 11 Jan 2019 06:45:33 -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; dkim=pass header.i=@kernel.org header.s=default header.b=iIOmsrs9; 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 S2404369AbfAKOn2 (ORCPT + 99 others); Fri, 11 Jan 2019 09:43:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:36302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404362AbfAKOn0 (ORCPT ); Fri, 11 Jan 2019 09:43:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D8DAE206B6; Fri, 11 Jan 2019 14:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217805; bh=NLwRLLyoaPze/svjYnmNLfWyeYs8+PKc3wbY0gXStR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iIOmsrs9LR1EQKmXEgSeOgfJFYcdLIvodC3ncPWsuBPwtE2MdUGo97r75SwtlNPgP ZBmNi8Mzjy5dTG88j3OZ7wWmpwy3EBjNL7MiHEbUof2sTww+YwG6Nzdzsjo2Q/SzG5 6JM7w4b41WThby6a2Q2+P3df2kI0ePuObo/EcUtQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Gorenko , Max Gurtovoy , Laurence Oberman , Bart Van Assche , Doug Ledford Subject: [PATCH 4.20 48/65] RDMA/srpt: Fix a use-after-free in the channel release code Date: Fri, 11 Jan 2019 15:15:34 +0100 Message-Id: <20190111131102.868093083@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit ed041919f0d23c109d52cde8da6ddc211c52d67e upstream. This patch avoids that KASAN sporadically reports the following: BUG: KASAN: use-after-free in rxe_run_task+0x1e/0x60 [rdma_rxe] Read of size 1 at addr ffff88801c50d8f4 by task check/24830 CPU: 4 PID: 24830 Comm: check Not tainted 4.20.0-rc6-dbg+ #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Call Trace: dump_stack+0x86/0xca print_address_description+0x71/0x239 kasan_report.cold.5+0x242/0x301 __asan_load1+0x47/0x50 rxe_run_task+0x1e/0x60 [rdma_rxe] rxe_post_send+0x4bd/0x8d0 [rdma_rxe] srpt_zerolength_write+0xe1/0x160 [ib_srpt] srpt_close_ch+0x8b/0xe0 [ib_srpt] srpt_set_enabled+0xe7/0x150 [ib_srpt] srpt_tpg_enable_store+0xc0/0x100 [ib_srpt] configfs_write_file+0x157/0x1d0 __vfs_write+0xd7/0x3d0 vfs_write+0x102/0x290 ksys_write+0xab/0x130 __x64_sys_write+0x43/0x50 do_syscall_64+0x71/0x210 entry_SYSCALL_64_after_hwframe+0x49/0xbe Allocated by task 13856: save_stack+0x43/0xd0 kasan_kmalloc+0xc7/0xe0 kasan_slab_alloc+0x11/0x20 kmem_cache_alloc+0x105/0x320 rxe_alloc+0xff/0x1f0 [rdma_rxe] rxe_create_qp+0x9f/0x160 [rdma_rxe] ib_create_qp+0xf5/0x690 [ib_core] rdma_create_qp+0x6a/0x140 [rdma_cm] srpt_cm_req_recv.cold.59+0x1588/0x237b [ib_srpt] srpt_rdma_cm_req_recv.isra.35+0x1d5/0x220 [ib_srpt] srpt_rdma_cm_handler+0x6f/0x100 [ib_srpt] cma_listen_handler+0x59/0x60 [rdma_cm] cma_ib_req_handler+0xd5b/0x2570 [rdma_cm] cm_process_work+0x2e/0x110 [ib_cm] cm_work_handler+0x2aae/0x502b [ib_cm] process_one_work+0x481/0x9e0 worker_thread+0x67/0x5b0 kthread+0x1cf/0x1f0 ret_from_fork+0x24/0x30 Freed by task 3440: save_stack+0x43/0xd0 __kasan_slab_free+0x139/0x190 kasan_slab_free+0xe/0x10 kmem_cache_free+0xbc/0x330 rxe_elem_release+0x66/0xe0 [rdma_rxe] rxe_destroy_qp+0x3f/0x50 [rdma_rxe] ib_destroy_qp+0x140/0x360 [ib_core] srpt_release_channel_work+0xdc/0x310 [ib_srpt] process_one_work+0x481/0x9e0 worker_thread+0x67/0x5b0 kthread+0x1cf/0x1f0 ret_from_fork+0x24/0x30 Cc: Sergey Gorenko Cc: Max Gurtovoy Cc: Laurence Oberman Cc: Signed-off-by: Bart Van Assche Signed-off-by: Doug Ledford Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/srpt/ib_srpt.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -2010,6 +2010,14 @@ static void srpt_free_ch(struct kref *kr kfree_rcu(ch, rcu); } +/* + * Shut down the SCSI target session, tell the connection manager to + * disconnect the associated RDMA channel, transition the QP to the error + * state and remove the channel from the channel list. This function is + * typically called from inside srpt_zerolength_write_done(). Concurrent + * srpt_zerolength_write() calls from inside srpt_close_ch() are possible + * as long as the channel is on sport->nexus_list. + */ static void srpt_release_channel_work(struct work_struct *w) { struct srpt_rdma_ch *ch; @@ -2037,6 +2045,11 @@ static void srpt_release_channel_work(st else ib_destroy_cm_id(ch->ib_cm.cm_id); + sport = ch->sport; + mutex_lock(&sport->mutex); + list_del_rcu(&ch->list); + mutex_unlock(&sport->mutex); + srpt_destroy_ch_ib(ch); srpt_free_ioctx_ring((struct srpt_ioctx **)ch->ioctx_ring, @@ -2047,11 +2060,6 @@ static void srpt_release_channel_work(st sdev, ch->rq_size, srp_max_req_size, DMA_FROM_DEVICE); - sport = ch->sport; - mutex_lock(&sport->mutex); - list_del_rcu(&ch->list); - mutex_unlock(&sport->mutex); - wake_up(&sport->ch_releaseQ); kref_put(&ch->kref, srpt_free_ch);