Received: by 10.192.165.148 with SMTP id m20csp485286imm; Fri, 4 May 2018 01:02:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZovhjJsfYApHi2R8ch89cVp1252rdExPR/3Gf5EnZDdRCmMt+af6y87F21Bha1Z4d0pnCVQ X-Received: by 2002:a17:902:7406:: with SMTP id g6-v6mr10048256pll.237.1525420976345; Fri, 04 May 2018 01:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525420976; cv=none; d=google.com; s=arc-20160816; b=Nq6PyQ7pZOcKtLSksqW1xYV0HFUpAHIDznGQSEcy2l8Vk+q2iDZq+BSWUwKbCDYJWo zIHJ7kIeFXbL1wLualkh+HUbkUSuJ2KDqg6kasItktUdISAk//YJiFnDX6WfDU9rRuu6 08CbeDdQYfrT4wNB5WnYlSk3XeQwhmcPb4cphOZMUBP+Iihq8f5jcjYwfn2mtyS/tuUu bHIGyv9UsEbHcGrXyP7ta6fepD81HGMs962PZiBIKWDEN9IK0kcixPDwOEUD+YCJuJp+ 15z3URGNvEHENKTooqbe8RuJvarSNuif03djqBnIQ6Z9vLQ4gOUkMHU3C/0kG2BF3Bgc lulw== 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=48wDZfmEoWuYTBulYZr3u58Jp0t4E+4PiuY6qINPVPs=; b=Lg//pgMI0z/bkvzRSRXA+ILQHPdUEuamHR0GJS/sLwhtWSHF3Skh1ERlzNbK40Kwa/ jVLLZc3ppFfyUItqPkmv1/rHiGUkGSNILESmNqmHHfAV28EVduw8jy9x4YQA8mchvg9W xWvPI+93ZZ/zgfNStTCxfkSxDvkTjj8WQOQY7cOZST+ReO9Eqp/65AUugLWRCVf3f1ek 0w2uM+zoL2u8//UNRf4ljjiswEdhJls87h5Fjr4JkxfumvkfZoFRTt74IawmrT/JT87b GZH7HCIfroBfiLxA7+oIUkHplWAZMwnGF8oIUaLZUtjJ0nPRgUF1dInR+xn/n+v4N76X TuKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=syksIbUJ; 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 e184-v6si12993003pgc.475.2018.05.04.01.02.41; Fri, 04 May 2018 01:02:56 -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=syksIbUJ; 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 S1751404AbeEDIBu (ORCPT + 99 others); Fri, 4 May 2018 04:01:50 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:43854 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750733AbeEDIBt (ORCPT ); Fri, 4 May 2018 04:01:49 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4481ZAx120778; Fri, 4 May 2018 08:01:35 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=48wDZfmEoWuYTBulYZr3u58Jp0t4E+4PiuY6qINPVPs=; b=syksIbUJr/cEA63mSg/JoZPXfR7L/aOtJWwsG1i9RYAJvRHGaoivBY9Mtul4BBcz29no k3B5T8pJ6tIaGXK2XGvLdaiFdoxoYo9w3l2GdKriV2kdfDEtwAPg1D+LKVIgqNd8WI12 UU0hqeFEoo9tg2jvb3IdmyrWA+zItTneDnirxr12Rf61IyU3j6bnpVPgdsER4NfenoaD hlWGjmdTBxCY2fjqHb7BkRrckbivI+EHwjJ5ka99k1N6ioMd0rhsWyzpi4SK0sk93LEg jhKaMbnZNqfYSGcARlstxI0mMHcqYSCcNDGOm+PZC/A67/mS6Xnox1TsePeGf+rncpW3 Tg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2hmgdjvwdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 May 2018 08:01:35 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4481Y4t009865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 May 2018 08:01:35 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4481XGp013263; Fri, 4 May 2018 08:01:33 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:33 -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: fix double free in nvme_rdma_free_queue Date: Fri, 4 May 2018 16:02:18 +0800 Message-Id: <1525420938-9492-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 BUG: KASAN: double-free or invalid-free in nvme_rdma_free_queue+0xf6/0x110 [nvme_rdma] Workqueue: nvme-reset-wq nvme_rdma_reset_ctrl_work [nvme_rdma] Call Trace: dump_stack+0x91/0xeb print_address_description+0x6b/0x290 kasan_report_invalid_free+0x55/0x80 __kasan_slab_free+0x176/0x190 kfree+0xeb/0x310 nvme_rdma_free_queue+0xf6/0x110 [nvme_rdma] nvme_rdma_configure_admin_queue+0x1a3/0x4d0 [nvme_rdma] nvme_rdma_reset_ctrl_work+0x4e/0xd0 [nvme_rdma] process_one_work+0x3ca/0xaa0 worker_thread+0x4e2/0x6c0 kthread+0x18d/0x1e0 ret_from_fork+0x24/0x30 The double free is on ctrl->async_event_sqe. If nvme_rdma_start_queue in nvme_rdma_configure_admin_queue fails, nvme_rdma_free_queue will be invoked. However, at the moment, the ctrl->async_event_sqe has not been allocated and it has been freed in nvme_rdma_reset_ctrl_work -> nvme_rdma_shutdown_ctrl ->nvme_rdma_destroy_admin_queue -> nvme_rdma_free_queue Signed-off-by: Jianchao Wang --- drivers/nvme/host/rdma.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index a0ead1d..fd965d0 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -168,8 +168,11 @@ static inline size_t nvme_rdma_inline_data_size(struct nvme_rdma_queue *queue) static void nvme_rdma_free_qe(struct ib_device *ibdev, struct nvme_rdma_qe *qe, size_t capsule_size, enum dma_data_direction dir) { + if (!qe->data) + return; ib_dma_unmap_single(ibdev, qe->dma, capsule_size, dir); kfree(qe->data); + qe->data = NULL; } static int nvme_rdma_alloc_qe(struct ib_device *ibdev, struct nvme_rdma_qe *qe, -- 2.7.4