Received: by 10.213.65.68 with SMTP id h4csp242125imn; Fri, 23 Mar 2018 03:43:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELs1NsXDgJpEqgONMQuXL/9h51J0HuxFI2l3K6RL5hdGMAlS1kWqga0TGSQrY8EOmcWuEt/u X-Received: by 2002:a17:902:b608:: with SMTP id b8-v6mr29187163pls.392.1521801837326; Fri, 23 Mar 2018 03:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521801837; cv=none; d=google.com; s=arc-20160816; b=0Fapjm6l64UYaoSSzoBWjbgmpiTl1oC5xccdKcti/xJN7m5OfhDJ27X30kIgbvgRhI vIny5NC9u4oqfzv6EHHLDCyFFksyQpKbIkwsVtDVx6M8XWlr16zoBQuhjfmVR7IHzB7U MdwTMDScF8AIH3BhC8dO59QnS0GHKjXiXgN8nQHdc1jbaO0HXisfMI59ZWAZiotk3xq0 b+1ogDvLPMMamUs2Z+0uKnOKbmm6fkhDvpLorgR1cbcOALl7VB2extWHIMaTJYiif8Dk bghSV0kOF0aolkVdLsxOH3LJf3EkgftNTrwBxrOVqZfCHvgt+pOR/Z0u4umDvZlRwZSj 17Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ggyNcff1GN10+ZSIp3MSdYwdYQP4KTZKjkmr9OExrAE=; b=sYfRXgvdhIgWJ/LO5FX0zzYB+IVj76V2fLG33Dh/yyyOn2ydFnJYdHmqstcln4hsGE bVr2mBfgsOfuOctnPPKQ2OdeZ1IbsSfbELqAxyEMZb+U+s9tbWWLNqKqJVlsVhioArRi D/QXbMIXBHS4mSiw9zhP920+I1rSnLQTuYNKxTPZL3kjkIfCjqW3CwT9z7BEKS++rXXn Sjr80g/qmy6f/6ivVqizlqQgB3nNBw7XQAkkV9zQmWXOM3jJ0gp/kDnywuEDslAAYPm/ aLseN6DknQ9uSgMY/pBjrQXLZXSm8fjX0NrVA3Kavpm0SvM2iq9Dt2999FIvrYuOroRD jyzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si5880383pgc.296.2018.03.23.03.43.42; Fri, 23 Mar 2018 03:43:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756446AbeCWKmy (ORCPT + 99 others); Fri, 23 Mar 2018 06:42:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46646 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933609AbeCWKQP (ORCPT ); Fri, 23 Mar 2018 06:16:15 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 98342CCE; Fri, 23 Mar 2018 10:16:14 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prakash Kamliya , Sharat Masetty , Rob Clark , Sasha Levin Subject: [PATCH 4.4 75/97] drm/msm: fix leak in failed get_pages Date: Fri, 23 Mar 2018 10:55:02 +0100 Message-Id: <20180323094201.783718616@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Prakash Kamliya [ Upstream commit 62e3a3e342af3c313ab38603811ecdb1fcc79edb ] get_pages doesn't keep a reference of the pages allocated when it fails later in the code path. This can lead to a memory leak. Keep reference of the allocated pages so that it can be freed when msm_gem_free_object gets called later during cleanup. Signed-off-by: Prakash Kamliya Signed-off-by: Sharat Masetty Signed-off-by: Rob Clark Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/msm/msm_gem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -89,14 +89,17 @@ static struct page **get_pages(struct dr return p; } + msm_obj->pages = p; + msm_obj->sgt = drm_prime_pages_to_sg(p, npages); if (IS_ERR(msm_obj->sgt)) { + void *ptr = ERR_CAST(msm_obj->sgt); + dev_err(dev->dev, "failed to allocate sgt\n"); - return ERR_CAST(msm_obj->sgt); + msm_obj->sgt = NULL; + return ptr; } - msm_obj->pages = p; - /* For non-cached buffers, ensure the new pages are clean * because display controller, GPU, etc. are not coherent: */ @@ -119,7 +122,10 @@ static void put_pages(struct drm_gem_obj if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl, msm_obj->sgt->nents, DMA_BIDIRECTIONAL); - sg_free_table(msm_obj->sgt); + + if (msm_obj->sgt) + sg_free_table(msm_obj->sgt); + kfree(msm_obj->sgt); if (use_pages(obj))