Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp710094pxv; Thu, 15 Jul 2021 14:07:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8C60ttHIir22FJu7DR/eJJkJ5BpsY8Rg1v6xhtWSKfN5pJzv+UM3BOHt0VGq7koyw6JNo X-Received: by 2002:aa7:d8c6:: with SMTP id k6mr9823764eds.374.1626383239564; Thu, 15 Jul 2021 14:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383239; cv=none; d=google.com; s=arc-20160816; b=ifY4AOFesFqnIyvpWeVafv9+TeLJXvc2dqF2juoh78f5jx11xJ4ks7rTOGt3cAGPZX MaF3RgvRzgOU94zgZiqUorUA0FaXYPtUAvY86My07qXGJIEuJplpP4tUIhZ6CW6iC8/A m8BUAMhmhEuSt6ylwpaIWfvF4EUV7bkTUZucC559Gskdz+Y3eXbmzucC1e0YkH8YAX6N tyCl3Cbr/8PfQDefY4iA9/qpIPUw7z3NEsJ0LKwbFGqyZMbrDMbEo98tr4c/U3w8nELK B6xaS0yk4s0j8LBG8mkvXropciXQgDlmU3HeVoqXtEan4ZHyyRT+BlFkY2J81b9dua58 mPqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f/0PTXdIudMJXdYjmda9usz/BHvAo/a3dQde1Q8049E=; b=CYG5s55QzVxIQ+UVOkAbWENwWI7/y8M2Em9d0Aspg1kNA1USM1qfHgScxN7uq3/wAI xH5ypv2O/0XNwst7ExupS1dBnyBHNQVaGXpum5bI7VP9i5Gvvv2oSsYTLUa62VSVYiFA H8KuDQ/y6PHFzE2bTTkw2wCCO2KAZ9NIMLN6W9I7PP2VuzrxuJpIYTy43W8rb1JuiecC mHD44E9o5hW/pvU9kQT4tQiApOvVHYJSSZtqkm6QD8ik+/TbgnhmQx9Weos1F9emPz5y abOwNxZp0H613qfwSGFJUtnb/qHR6cdTXtVViLniv1yuMgiKqY1pu6ME19W9YEA8lM1H HrVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JRN+W6yW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 10si8108187eji.282.2021.07.15.14.06.56; Thu, 15 Jul 2021 14:07:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JRN+W6yW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241439AbhGOTSX (ORCPT + 99 others); Thu, 15 Jul 2021 15:18:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:38832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242677AbhGOTC5 (ORCPT ); Thu, 15 Jul 2021 15:02:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16D60613EB; Thu, 15 Jul 2021 18:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375548; bh=LEb2Bs3wCYJs84G3awPLv8h4ima8q0QSZGPBFsyY92E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRN+W6yW3IwjGbXS0GJDY8k1G3o2xKDEgnjkBe0K2eURMQgc4rf76ZCQKexHEvy0B D8k8+tF3JBqs8Dl0JbMOdI8VRTEdrvru9tVwACX5ZQoRPK9El55+ILdLkgH1A1SxWG 5ucCHIGXXKR1BASM2Bv8Q2aO20mc24IgUcDouulQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerd Rausch , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.12 134/242] RDMA/cma: Fix rdma_resolve_route() memory leak Date: Thu, 15 Jul 2021 20:38:16 +0200 Message-Id: <20210715182616.602078122@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gerd Rausch [ Upstream commit 74f160ead74bfe5f2b38afb4fcf86189f9ff40c9 ] Fix a memory leak when "mda_resolve_route() is called more than once on the same "rdma_cm_id". This is possible if cma_query_handler() triggers the RDMA_CM_EVENT_ROUTE_ERROR flow which puts the state machine back and allows rdma_resolve_route() to be called again. Link: https://lore.kernel.org/r/f6662b7b-bdb7-2706-1e12-47c61d3474b6@oracle.com Signed-off-by: Gerd Rausch Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index bb46f794f324..8d94a6bfcac1 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2793,7 +2793,8 @@ static int cma_resolve_ib_route(struct rdma_id_private *id_priv, cma_init_resolve_route_work(work, id_priv); - route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); + if (!route->path_rec) + route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); if (!route->path_rec) { ret = -ENOMEM; goto err1; -- 2.30.2