Received: by 10.192.165.148 with SMTP id m20csp485801imm; Fri, 4 May 2018 01:03:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpMCCD2Dwes+rxnKHxLmQbxoVOFQmkJy8+LMEH6E8l5jlFRjTsgtB21R+5BWd1baXWC74k6 X-Received: by 2002:a17:902:2826:: with SMTP id e35-v6mr1409316plb.348.1525421004361; Fri, 04 May 2018 01:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525421004; cv=none; d=google.com; s=arc-20160816; b=A8PburFlqI1O8nh9QFwA3bIm/AZLzZ7vMg/bOTwL3dy/3BrGmh4pIpVdZ61nETdlWs ptEE/3GXWUK/DWpJlEdsMSoFBVJxyDE8Y6c6D/oIsrFj7NpxWEBS0hEgnpOB2PZDXP+6 u9YfLQTAJA93iAypxOR7lQ8upjSdvU1SOmDMak+E0JH7cxLlcLWA/dL98PjE+IFZ8wgr /8W3iSCxuDOWnH3YO5SLa4PR4AOj/V3rOthPwavYK+H4B1b56MCwg9Qru6uOPm69qo7F YlEgRYfWsXnFbdiMtjhuEkM58Llo08pWXIvjoKU2o5dtFOYfmM2BLR6suLtF3DWfNzq6 SwUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=z/0zUaek2CzhhVpKkKBk+3AeO+ZhgExNtuUL3TDIYic=; b=ITMBn0P5omhIr/O0KpGeWBTEtDDpGo6PjoJyekLQQ3WiVj6wZ7Vaypod7nAzu1s3xp bT0BIqMFih4Ued/LF7BjSqx+awP9f+OQOTRm9b2RIXK7ANAQA4d/Pt7pxXldCNqydpwS y9DxEu7ShQ0KM3c7EP32tiOS7ug2P9VvNbhBC+9eRrvLUBZBCUmJNMYjhwhH/f8K4YaF ZMMgk7jFQYYYffUS07U6T8v6USPkc0jGQDUwXLa+LlitNPdjRODn+Kz4+m7vxVe4CwGK 5vs1mpuUzpgsN0l/WQA2pu6JOJcLO/txXDlxvfVb6jtgqehl1me2pAoCytL/hj4Bc1gR ZFwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=O3TfABNi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e66-v6si15161682plb.499.2018.05.04.01.03.10; Fri, 04 May 2018 01:03:24 -0700 (PDT) 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=@oracle.com header.s=corp-2017-10-26 header.b=O3TfABNi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751343AbeEDICd (ORCPT + 99 others); Fri, 4 May 2018 04:02:33 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:55750 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750709AbeEDICb (ORCPT ); Fri, 4 May 2018 04:02:31 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4481Hbk087396; Fri, 4 May 2018 08:01:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=z/0zUaek2CzhhVpKkKBk+3AeO+ZhgExNtuUL3TDIYic=; b=O3TfABNiA0zSX0f/CuVyKcJvS1Ygh6lVaQXVshXo+fCl8vSqWEfrRaw91sJJycJ9qwvf fx+IYXAfy6gCk9XX2DkqvXhxWj4POEAO4xePQEPTWhuhv9wdCq7/W5Ey2BtzGb0D4sTq SSupisVh+ozQddiKr5uDaUDXJd25z8cNCOT5Dh1tqdVn53uELVhFu3ZrSUVz2II27opM 7h8UTIfSlkldrsBZcx6Te+jzfzgpNNqP5QqV9epzC+IZeY5oMLwn7vmhFpTMQ+DYPJA8 TZH5NLqO1TCviBiX9JfzRcYvIp8IrAzdqut4y7xeBZsMBUHnK18VKACjC+VWYmyF6E0m 8Q== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2hmeg6516j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 May 2018 08:01:55 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4481tD0023535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 May 2018 08:01:55 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4481s17006067; Fri, 4 May 2018 08:01:54 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 04 May 2018 01:01:54 -0700 From: Jianchao Wang To: keith.busch@intel.com, axboe@fb.com, hch@lst.de, sagi@grimberg.me Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-rdma: clear NVME_RDMA_Q_LIVE before free the queue Date: Fri, 4 May 2018 16:02:38 +0800 Message-Id: <1525420958-9537-1-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8882 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805040075 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When nvme_init_identify in nvme_rdma_configure_admin_queue fails, the ctrl->queues[0] is freed but the NVME_RDMA_Q_LIVE is still set. If nvme_rdma_stop_queue is invoked, we will incur use-after-free which will cause memory corruption. BUG: KASAN: use-after-free in rdma_disconnect+0x1f/0xe0 [rdma_cm] Read of size 8 at addr ffff8801dc3969c0 by task kworker/u16:3/9304 CPU: 3 PID: 9304 Comm: kworker/u16:3 Kdump: loaded Tainted: G W 4.17.0-rc3+ #20 Workqueue: nvme-delete-wq nvme_delete_ctrl_work Call Trace: dump_stack+0x91/0xeb print_address_description+0x6b/0x290 kasan_report+0x261/0x360 rdma_disconnect+0x1f/0xe0 [rdma_cm] nvme_rdma_stop_queue+0x25/0x40 [nvme_rdma] nvme_rdma_shutdown_ctrl+0xf3/0x150 [nvme_rdma] nvme_delete_ctrl_work+0x98/0xe0 process_one_work+0x3ca/0xaa0 worker_thread+0x4e2/0x6c0 kthread+0x18d/0x1e0 ret_from_fork+0x24/0x30 To fix it, clear the NVME_RDMA_Q_LIVE before free the ctrl->queues[0]. The queue will be freed, so it certainly is not LIVE any more. Signed-off-by: Jianchao Wang --- drivers/nvme/host/rdma.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index fd965d0..ffbfe82 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -812,6 +812,11 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, if (new) nvme_rdma_free_tagset(&ctrl->ctrl, ctrl->ctrl.admin_tagset); out_free_queue: + /* + * The queue will be freed, so it is not LIVE any more. + * This could avoid use-after-free in nvme_rdma_stop_queue. + */ + clear_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[0].flags); nvme_rdma_free_queue(&ctrl->queues[0]); return error; } -- 2.7.4