From patchwork Tue Mar 14 13:40:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Zhang X-Patchwork-Id: 9623457 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 6D194604A9 for ; Tue, 14 Mar 2017 13:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6102028584 for ; Tue, 14 Mar 2017 13:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55B5228587; Tue, 14 Mar 2017 13:41:10 +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 7A27428584 for ; Tue, 14 Mar 2017 13:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbdCNNlC (ORCPT ); Tue, 14 Mar 2017 09:41:02 -0400 Received: from mx6-phx2.redhat.com ([209.132.183.39]:51215 "EHLO mx6-phx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751154AbdCNNlB (ORCPT ); Tue, 14 Mar 2017 09:41:01 -0400 Received: from zmail25.collab.prod.int.phx2.redhat.com (zmail25.collab.prod.int.phx2.redhat.com [10.5.83.31]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EDeRgM053156; Tue, 14 Mar 2017 09:40:27 -0400 Date: Tue, 14 Mar 2017 09:40:27 -0400 (EDT) From: Yi Zhang To: Sagi Grimberg Cc: linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org, Christoph Hellwig Message-ID: <1898652754.2479312.1489498827670.JavaMail.zimbra@redhat.com> In-Reply-To: <1489412381-28947-1-git-send-email-sagi@grimberg.me> References: <1489412381-28947-1-git-send-email-sagi@grimberg.me> Subject: Re: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference MIME-Version: 1.0 X-Originating-IP: [10.66.13.182] X-Mailer: Zimbra 8.0.6_GA_5922 (ZimbraWebClient - GC55 (Linux)/8.0.6_GA_5922) Thread-Topic: nvmet-rdma: Fix a possible uninitialized variable dereference Thread-Index: bfle5ocyG3yTAE/gp5Q6GmDTQ1wXdA== 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 Thanks Sagi Tested-by: Yi Zhang Best Regards, Yi Zhang ----- Original Message ----- From: "Sagi Grimberg" To: linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org Cc: "Christoph Hellwig" Sent: Monday, March 13, 2017 9:39:41 PM Subject: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference When handling a new recv command, we grab a new rsp resource and check for the queue state being live. In case the queue is not in live state, we simply restore the rsp back to the free list. However in this flow we didn't set rsp->queue yet, so we cannot dereference it. Instead, make sure to initialize rsp->queue (and other rsp members) as soon as possible so we won't reference uninitialized variables. Reported-by: Yi Zhang Reported-by: Raju Rangoju Signed-off-by: Sagi Grimberg --- - v1 broke srq, this one doesn't drivers/nvme/target/rdma.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 9aa1da3778b3..ecc4fe862561 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -703,11 +703,6 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue, { u16 status; - cmd->queue = queue; - cmd->n_rdma = 0; - cmd->req.port = queue->port; - - ib_dma_sync_single_for_cpu(queue->dev->device, cmd->cmd->sge[0].addr, cmd->cmd->sge[0].length, DMA_FROM_DEVICE); @@ -760,9 +755,12 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) cmd->queue = queue; rsp = nvmet_rdma_get_rsp(queue); + rsp->queue = queue; rsp->cmd = cmd; rsp->flags = 0; rsp->req.cmd = cmd->nvme_cmd; + rsp->req.port = queue->port; + rsp->n_rdma = 0; if (unlikely(queue->state != NVMET_RDMA_Q_LIVE)) { unsigned long flags;