Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3930365imm; Mon, 8 Oct 2018 11:52:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV601ARcnXQ3tNX/ijEfTHMmJN91ug1Dk6O2hIxHj0P3idD5luoCh+g0Imx1LjKhXpGwkzYCr X-Received: by 2002:a17:902:850b:: with SMTP id bj11-v6mr25628431plb.107.1539024752777; Mon, 08 Oct 2018 11:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024752; cv=none; d=google.com; s=arc-20160816; b=snV6ojHnVB3PkcOD7PLCZ9jbpP5yJWGRAOyr20y1Avjomm5JTRmVKr1/fLx9OKl3+m kWL2G4Z0f0O2/mEIzCPfr+cTOAD21qf+Md5YQRQLN55+u2BqwDj1gsjqSLzcpZCdqVhE Z/hHGzu2DJZZjIkX4VLINxawFyceBIDHQcySnrNtgnDei2Kt41LS/TgpdIzxj5Wt3Fml iqX5Eq3MxiFSR4tLRGSVtLMUziATexNqpx8GWvW7Q3kWMx0U6a9CH4km1TVD9sxNa/6q DXM67MsTk7GB7uAMCfVKFHUYB98NY35wGfMDsxotxUit5Sj1T8VlgCMtp8riVzVmSr7N Dl7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4F2J3caNiWgzPeksrp0bq3aefFcLj1//+x/v4T0BYXs=; b=p4Op1A7V8A2S1n4txVmHDQFYld7CcQ6BVhVOI/NyQIj13e1drlryB2ZgMDcvfsp2qD OoY5RZlYwc96e1xVmxbmf2z4I56mSvw7ueg6xWlGWT51fWMygow2XDr/VQYXCVfmI+BL q9CAj1AOtB99IWU8FzJLugUdOJlXkhR2MIvxaJ2lLKM3Ec/vQeatfKCSTaFYRYvuT+Vv vpcV4ej6qvhXagr9yX7pB4aI+TzDGR1CO1Dvbjgttlare93ri2hqV7jiifIicKTdP3ht 3PCrns/JfthRarG4+Ov4VD2f0xMPguog2d7EpJ7ZgVb6oYe/cZQggM2zDxeSTMbRzUae QsbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="u/GfzTvJ"; 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 72-v6si1265557pla.334.2018.10.08.11.52.17; Mon, 08 Oct 2018 11:52:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b="u/GfzTvJ"; 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 S1732474AbeJICFS (ORCPT + 99 others); Mon, 8 Oct 2018 22:05:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:55384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727260AbeJICFS (ORCPT ); Mon, 8 Oct 2018 22:05:18 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3014A20645; Mon, 8 Oct 2018 18:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024730; bh=+/W9j0Qrs5iJFVWUadykvhEjiGEqb19C18Zk2C4m6BI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u/GfzTvJ6xce5n+O5ePfNSR95/My4ntfIg0/DYCwzJ3Mf8Ow2jsOudrPXgTpHbhvn +9Xxv6gyLkTRMP7If7TCkFB1hQqhPDMBXO9438qXi1Uy4HNyD3aeEDtjwWE1WvOTaN eZKNX86dYDkK/pWZaL7JUiYzaRygO0sAgk4B6cic= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Andrey Grodzovsky , Alex Deucher , Sasha Levin Subject: [PATCH 4.18 134/168] drm/amdgpu: fix error handling in amdgpu_cs_user_fence_chunk Date: Mon, 8 Oct 2018 20:31:54 +0200 Message-Id: <20181008175625.138805888@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Christian K?nig" [ Upstream commit 0165de983272d1fae0809ed9db47c46a412279bc ] Slowly leaking memory one page at a time :) Signed-off-by: Christian König Reviewed-by: Andrey Grodzovsky Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -38,6 +38,7 @@ static int amdgpu_cs_user_fence_chunk(st { struct drm_gem_object *gobj; unsigned long size; + int r; gobj = drm_gem_object_lookup(p->filp, data->handle); if (gobj == NULL) @@ -49,20 +50,26 @@ static int amdgpu_cs_user_fence_chunk(st p->uf_entry.tv.shared = true; p->uf_entry.user_pages = NULL; - size = amdgpu_bo_size(p->uf_entry.robj); - if (size != PAGE_SIZE || (data->offset + 8) > size) - return -EINVAL; - - *offset = data->offset; - drm_gem_object_put_unlocked(gobj); + size = amdgpu_bo_size(p->uf_entry.robj); + if (size != PAGE_SIZE || (data->offset + 8) > size) { + r = -EINVAL; + goto error_unref; + } + if (amdgpu_ttm_tt_get_usermm(p->uf_entry.robj->tbo.ttm)) { - amdgpu_bo_unref(&p->uf_entry.robj); - return -EINVAL; + r = -EINVAL; + goto error_unref; } + *offset = data->offset; + return 0; + +error_unref: + amdgpu_bo_unref(&p->uf_entry.robj); + return r; } static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)