Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp656923pxv; Thu, 15 Jul 2021 12:39:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyakIFgrahgEtvlv3ehoSdpnmCZLCJcAuL2le0n8vqlhFjlavmGz+nF521G+kmZHyWz/+Ki X-Received: by 2002:a50:8e19:: with SMTP id 25mr9447614edw.11.1626377970965; Thu, 15 Jul 2021 12:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377970; cv=none; d=google.com; s=arc-20160816; b=KBzdFEWlF562XCSLYYQiZHjaarrYJL1/6XsZlVxSIHUF+IESICTOcm+5WeNUlJrvcn UyO/yBHsptqIjrO2REFLUJofIwprQJB8rSluwrEWYs78ZqlxwtKxDXDMmo+rVcMCoYRq 6si7DWWf7a5lKGvH59AjhNEHsf119HDYvmYZLMrl15XTug4fGOxDzhVEiBbLXIOyatLA DKaeYVKL1xAV8yxCp368ER1AYNAmp/eb9XOxkYAbyhQxb8qRgzhRoLzBq3nGqNHYAVEr znbcKg13mjxrWiDzmYZhnFiS5kEbqb60FkyGBj2gJnP2PZpu52BNTwU/d/3bwV9Ehq93 9TeQ== 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=zo27RO5+nEAAZsgtO3rEx9T4rFwfj1/tPHhipWdM7G4=; b=x5zJ+XxkGeE6kM8Kx4YnuLztSvAYAm8Yb32La8bDdQbyWzchNixltwGhuH3pWM+A1n VltKXr0ts5a//iEvcBThKTmGd1iTlU2O+HWO2hlt85trXjCVp5heBjCA2HOQdnY2Htwp Hsa6ra7eBpD67qsogLxRef12GLTCWHPZ//jx5jkqeIob/WKtllEEip03QVSRJtXZ4tva 4aibraykrmAjLEHZcqZQ0wfLCd4OTdJjUz5QEv0qjgnr8qvSoQsVVFhX80BOjhkA0PI4 j0ytUIDpZCQnKvXY/WcOw3o5tMq1nE/nHNGpJCP9ElZlFs0mmb67J8KY/WZVoIUlRk2s jtUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cLzJxHMz; 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 q18si10012185edi.63.2021.07.15.12.39.07; Thu, 15 Jul 2021 12:39:30 -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=cLzJxHMz; 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 S1343754AbhGOTiE (ORCPT + 99 others); Thu, 15 Jul 2021 15:38:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:51510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242244AbhGOTNG (ORCPT ); Thu, 15 Jul 2021 15:13:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26F15613F5; Thu, 15 Jul 2021 19:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376173; bh=6P1DaPNiG2jjjF3kBCBMBzJZei5nT5ZkPAH+dWgv9EA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cLzJxHMzrDt4LNvQ/z/cTMKF5KQMpGSdaCXwN9mA1iT8Mq06n4HaJUrMLqyP7qKWD s42wGIqfOKwzMmq+8kkwxP3fWDMH0Ob3eBeqqa/GVYaxT8NdlJEuo9vmDIaJY1uMJD BbVryhtNGaSsmNoejeVRKq0ECBB/3fG6VzfIakzk= 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.13 156/266] RDMA/cma: Fix rdma_resolve_route() memory leak Date: Thu, 15 Jul 2021 20:38:31 +0200 Message-Id: <20210715182640.523757165@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 ad9a9ba5f00d..5d3b8b8d163d 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2829,7 +2829,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