From patchwork Tue Mar 14 12:56:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Rangoju X-Patchwork-Id: 9623185 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 6139A604A9 for ; Tue, 14 Mar 2017 12:56:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 539AA2815E for ; Tue, 14 Mar 2017 12:56:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 474902854A; Tue, 14 Mar 2017 12:56:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 8000D2815E for ; Tue, 14 Mar 2017 12:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750865AbdCNM4y (ORCPT ); Tue, 14 Mar 2017 08:56:54 -0400 Received: from mail-bn3nam01on0134.outbound.protection.outlook.com ([104.47.33.134]:32064 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750853AbdCNM4v (ORCPT ); Tue, 14 Mar 2017 08:56:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chelsious.onmicrosoft.com; s=selector1-chelsio-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=lCmhFlunRYglKeFiHBKw0TKLZSbdJjW5FjpIgTmWtNk=; b=YnkWiktoMzMCoLW918O0XZ5Or5h9zYkqtdhMxM0UbUeMbThSRNo6bKTUh/CtCZPBvwy/NF75XA+LzW2m/6/4Tu3fKxR4Kl0W/p5A3xF3UT+vWUgkHxQiqM/Mmysxkv30bThdIqJMTJrnNzs7i+IKPaYzYEvQSKXepdhM3FziwVc= Received: from CY1PR12MB0774.namprd12.prod.outlook.com (10.164.69.140) by CY1PR12MB0775.namprd12.prod.outlook.com (10.164.69.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.961.17; Tue, 14 Mar 2017 12:56:34 +0000 Received: from CY1PR12MB0774.namprd12.prod.outlook.com ([10.164.69.140]) by CY1PR12MB0774.namprd12.prod.outlook.com ([10.164.69.140]) with mapi id 15.01.0961.021; Tue, 14 Mar 2017 12:56:34 +0000 From: "Raju Rangoju" To: Sagi Grimberg , "linux-nvme@lists.infradead.org" , "linux-rdma@vger.kernel.org" CC: Christoph Hellwig Subject: RE: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference Thread-Topic: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference Thread-Index: AQHSm/9NP5HN0EgY9E+URKc4z34mg6GUS7aw Date: Tue, 14 Mar 2017 12:56:34 +0000 Message-ID: References: <1489412381-28947-1-git-send-email-sagi@grimberg.me> In-Reply-To: <1489412381-28947-1-git-send-email-sagi@grimberg.me> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: grimberg.me; dkim=none (message not signed) header.d=none; grimberg.me; dmarc=none action=none header.from=chelsio.com; x-originating-ip: [111.93.130.157] x-microsoft-exchange-diagnostics: 1; CY1PR12MB0775; 7:CsBt5MOxsxdOrbKxIGBkL0QGX63+efzEjwTdAa8TbOzzBWoK8e+KGp65zV5V1GE2ORxkhDQZ+j+wjndQBQ/PB8LTVf65dw2n3PujD37ifEp1PlZ6g18H2KftftzuNJdrrDP39bmMD0y/NRZ0UIN4W/CJa+ypq4BV1kyy+lLzgYgbTE5kmLwUEU8QnlImWYEVzvM7LKaZegw+JTXg/il0hgr9QlyLF9lxbhG3/O+m1QQnqahe0JdReekwLLFn8+k6q4OtAxulQKHDvuKr1m7BSD80dh6XG9SM6xWYpeO6jiSSavS4FJmdszDaGC0mu5MIkWJ8fHPyOAFbT3mlDsNjhg== x-ms-office365-filtering-correlation-id: b212696a-7ace-4e15-ece8-08d46ad98b46 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR12MB0775; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(258649278758335); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(20161123558025)(2016111802025)(6072148)(6043046); SRVR:CY1PR12MB0775; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0775; x-forefront-prvs: 02462830BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39840400002)(39450400003)(39410400002)(13464003)(189998001)(966004)(102836003)(2906002)(6116002)(122556002)(81166006)(3846002)(6306002)(6436002)(2900100001)(8676002)(3280700002)(4326008)(9686003)(106116001)(8936002)(38730400002)(66066001)(3660700001)(6246003)(7736002)(77096006)(74316002)(5660300001)(229853002)(305945005)(7696004)(6506006)(2950100002)(2201001)(33656002)(25786008)(86362001)(2501003)(55016002)(54356999)(99286003)(50986999)(76176999)(53546007)(53936002)(422495003); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR12MB0775; H:CY1PR12MB0774.namprd12.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: chelsio.com X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Mar 2017 12:56:34.2429 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 065db76d-a7ae-4c60-b78a-501e8fc17095 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0775 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 Patch looks good. Tested-by: Raju Rangoju -----Original Message----- From: linux-rdma-owner@vger.kernel.org [mailto:linux-rdma-owner@vger.kernel.org] On Behalf Of Sagi Grimberg Sent: 13 March 2017 19:10 To: linux-nvme@lists.infradead.org; linux-rdma@vger.kernel.org Cc: Christoph Hellwig 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(-) 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; -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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)