From patchwork Fri Aug 5 13:46:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 9265425 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 79B8E60760 for ; Fri, 5 Aug 2016 13:46:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AD3F2623D for ; Fri, 5 Aug 2016 13:46:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EFB928443; Fri, 5 Aug 2016 13:46:59 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 04DB92623D for ; Fri, 5 Aug 2016 13:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759732AbcHENq5 (ORCPT ); Fri, 5 Aug 2016 09:46:57 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35532 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759715AbcHENq4 (ORCPT ); Fri, 5 Aug 2016 09:46:56 -0400 Received: by mail-pf0-f194.google.com with SMTP id h186so20135854pfg.2 for ; Fri, 05 Aug 2016 06:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m6uWVpEKyALzxg0t1PJ3BaOED6GUO6x/7RWEIz2l0yM=; b=JXXuJPI3LkURx1Prt3VPNnVkIcxXaOnbynAtUItDmm0MS1RQGTvbbX4zZOd/BwpVxv gK3a/CZkoB/+G4wUQL8wNpa3G4zhpkde1KS9BeA3wwzSkbXeY8H99WI8tfVJiPlBvqzT g75Dg9/hWWiU/RHnkwslZD38H3oQil6GbLFtOz5InqRtfXKPT7bQKAp+Hq+QKAJ8TXUN aqJRzMx5uKQH/HiAGzMglyW/Lr1zXDhYedKTlGZCyczuvtQ3/cBK1nmqga0SORYY/iL+ 0iG+CKPQniP42Da8nGPmwpPauHWwvehiwX+KgcuTwYKjLNTv94o5qU2mFb9FVxAS77NP ZORg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m6uWVpEKyALzxg0t1PJ3BaOED6GUO6x/7RWEIz2l0yM=; b=FapVsYahtw96VSeyEMJnyHC1EnAKEjHp1NiqnqFJUMrWHib8HZUX/imseWTKgXJqmq +ei918NVbXbpUfiiAmemjkKiF3gNGpGaXTnkQeYoCq8Cp+ZVCpihQKMiq4MblLisRxUR R2ZUGUzu0j9WIVh1FJWkco5AGLVWwMdN5VdFkAgXU4SYi+YPjNXmOp6qowf5GG9PhWB6 tYEZDVTUWl69gMj/ib7c7J06yghfhJF9octEd+Z+ctifJgAWnIFKS28xSJ1pbyEVGuIw URwNbeE16tYT+6PNXt3s556ZD7h6JuAgNBhKPTjYjstjRfodLRWUhrEAuiEAkerOXRV4 3hDg== X-Gm-Message-State: AEkooutDMga5i3+rD+EGlAI46W3dHtN9qhpIuACXJjS/973xEUGMNnF0h+JECknQ5qOBdg== X-Received: by 10.98.91.197 with SMTP id p188mr136000898pfb.101.1470404816214; Fri, 05 Aug 2016 06:46:56 -0700 (PDT) Received: from localhost.localdomain.localdomain (ec2-52-192-197-227.ap-northeast-1.compute.amazonaws.com. [52.192.197.227]) by smtp.gmail.com with ESMTPSA id a5sm28316223pfc.89.2016.08.05.06.46.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Aug 2016 06:46:55 -0700 (PDT) From: Wei Yongjun To: Doug Ledford , Sean Hefty , Hal Rosenstock , Bart Van Assche , Alex Vesker , Moni Shoua , Haggai Eran , Matan Barak , Guy Shapiro , Shachar Raindel Cc: Wei Yongjun , linux-rdma@vger.kernel.org Subject: [PATCH] IB/core: Fix possible memory leak in cma_resolve_iboe_route() Date: Fri, 5 Aug 2016 13:46:49 +0000 Message-Id: <1470404809-16658-1-git-send-email-weiyj.lk@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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 'work' and 'route->path_rec' are malloced in cma_resolve_iboe_route() and should be freed before leaving from the error handling cases, otherwise it will cause memory leak. Fixes: 200298326b27 ('IB/core: Validate route when we init ah') Signed-off-by: Wei Yongjun Reviewed-by: Haggai Eran --- drivers/infiniband/core/cma.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) -- 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/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index e6dfa1b..5f65a78 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2462,18 +2462,24 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) if (addr->dev_addr.bound_dev_if) { ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if); - if (!ndev) - return -ENODEV; + if (!ndev) { + ret = -ENODEV; + goto err2; + } if (ndev->flags & IFF_LOOPBACK) { dev_put(ndev); - if (!id_priv->id.device->get_netdev) - return -EOPNOTSUPP; + if (!id_priv->id.device->get_netdev) { + ret = -EOPNOTSUPP; + goto err2; + } ndev = id_priv->id.device->get_netdev(id_priv->id.device, id_priv->id.port_num); - if (!ndev) - return -ENODEV; + if (!ndev) { + ret = -ENODEV; + goto err2; + } } route->path_rec->net = &init_net;