Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2686713ybl; Thu, 29 Aug 2019 11:28:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8DJF63G0TJZ2/HI15VA/qG+LB5IetOJvL774lpQxA12EB2tsrdcyHmZ77JL1s3b9V28lT X-Received: by 2002:a17:902:b116:: with SMTP id q22mr11151889plr.338.1567103308005; Thu, 29 Aug 2019 11:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103307; cv=none; d=google.com; s=arc-20160816; b=Ag0jMVJuMp8y/lwCbnAk1pN9Fdsuar2kpd1PdYg6sRiMGT6Ldc4kMEP64tue4Lbtgh t+bOHXLgbOsZPKUWFo0K4u85Lrkf+5SaPSoW4wz2Z7UzsnbQaTfxyjw8fQQjDTkjMmwO 6JrO5U8tRYEskyvlhoZLkZg9TLJwHM4peImjomnLRZMEr19iSCdUzt3cCrQGuucrLH/5 bzX9Xfcze3VtSn5K7pICBJ8y0821TDrZJiICibumR7o8NCrEjfTMLKjJ5EQ5Kt1KfYlD 9NRkKn/rMGl7srbcrZqjKMKWVbJhSrrGrO0YAv/xLEytf9HoejzngpQ2av++9mcjlhI4 /7PQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HOYtduCCdc042ENxObdfo/uHxWc0Wexb3CBFIs96uGI=; b=oCt1AhnpHeAahlK587lrBivkRSfmy+7ojDYCDYXexX+a7X+tGH8EuOYmMOaGSLEWUJ XmGkKph746ODXyrCnlE7NZYFJMD1B9nD4plsIv96r3FO/u90mdfZ49nicPCm/+fi2+8z F8nkFoHuVpCwcfwKIES4rWA3N3E8mXDVr+78dou0XvpaUKzD+EdReRTcdRVU8fdkR/69 +iqxpp2YSjTtZH4n1UDFMjmut+L5vtDtBcT2hlm+5A+YvDCzNoJF6rJ/Ih5nUzc+e8Sg dVS8pX5sxYv55GnLlKVzF/Qb4fE1MMX5Qb1j+3FJ0wwq0bt6bYMIhcDZqjYtCchWnrvX nuOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ekIR7PTN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si2717872pjv.5.2019.08.29.11.28.12; Thu, 29 Aug 2019 11:28:27 -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=ekIR7PTN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729322AbfH2SPd (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:57230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729307AbfH2SPa (ORCPT ); Thu, 29 Aug 2019 14:15:30 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 09DAC23403; Thu, 29 Aug 2019 18:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102529; bh=daF/PX4Ijm80cFU8SbPUPm1tciP79fQ1UuLIBgd+6cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ekIR7PTNPIiLkcRN2lZpzqWOCTeHU+qlFkpxr2MdvtnRkJ6pn+/Nv/GQec1BcJWip 7yz0/Nn48qGiWXJxEscfPPH2sFkaJqQhSsXZHjNvL6i6qB1490zz0jq/mwEFD37Pgc bJvC2HxvjJ3ARCH+/5yVhP9j76q5GRqLU9Z6YU+o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Sasha Levin , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.2 65/76] drm/amdgpu: prevent memory leaks in AMDGPU_CS ioctl Date: Thu, 29 Aug 2019 14:13:00 -0400 Message-Id: <20190829181311.7562-65-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolai Hähnle [ Upstream commit 1a701ea924815b0518733aa8d5d05c1f6fa87062 ] Error out if the AMDGPU_CS ioctl is called with multiple SYNCOBJ_OUT and/or TIMELINE_SIGNAL chunks, since otherwise the last chunk wins while the allocated array as well as the reference counts of sync objects are leaked. Signed-off-by: Nicolai Hähnle Reviewed-by: Christian König Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index fe028561dc0e6..bc40d6eabce7d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1192,6 +1192,9 @@ static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p, num_deps = chunk->length_dw * 4 / sizeof(struct drm_amdgpu_cs_chunk_sem); + if (p->post_deps) + return -EINVAL; + p->post_deps = kmalloc_array(num_deps, sizeof(*p->post_deps), GFP_KERNEL); p->num_post_deps = 0; @@ -1215,8 +1218,7 @@ static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p, static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p, - struct amdgpu_cs_chunk - *chunk) + struct amdgpu_cs_chunk *chunk) { struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps; unsigned num_deps; @@ -1226,6 +1228,9 @@ static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p num_deps = chunk->length_dw * 4 / sizeof(struct drm_amdgpu_cs_chunk_syncobj); + if (p->post_deps) + return -EINVAL; + p->post_deps = kmalloc_array(num_deps, sizeof(*p->post_deps), GFP_KERNEL); p->num_post_deps = 0; -- 2.20.1