Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3028068imu; Sun, 23 Dec 2018 13:54:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Ji6zpa/YyKslkiQEcIRiATpFlVWWRE1g+Hlx8gBDqDyCQ9wlRsnkGfti4BoUKYrVCxkgC X-Received: by 2002:a65:47ca:: with SMTP id f10mr10554257pgs.166.1545602061846; Sun, 23 Dec 2018 13:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545602061; cv=none; d=google.com; s=arc-20160816; b=ydqviNRrJeA86mTquu84k/zmfgxmY7jrqAoNo9nUOzYnqhH+5t2PMbiZ8TLozDhOXu lk3GNc6Yjz10jknRQSKPoJEQ2wY7MuyHcIa6baNxgv+OSfRII6OQi0TKZZzabW/pA8HJ 4tFqnxOm8Gm55eWIL52qSFdVdw950+D/KZidi8dmQoR+aQsIo5LMNZfd8BJ1Uv9ANg6k K6gFr/ONN3c8NCFvjViJm6g29/0VYwdDIqcCZ4lWThNFZRAnUCqM8KzUSwt0z4gFJIe4 /qS6uXSk8Zmpffy4pxQOkFyK2j+aMiOTZ2ifJw0EpnP+GNmIKkNyqMIsYW1Wgy+CQy56 btuA== 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=C4T60ebSd3XIwaQkfiltqImM3j39ie8rJCcw2QWQ+cE=; b=IPHjlFy2RiEq6cQq3/2i/xLP+obczQaKt+cju8Ui0PJGRh7U6A6Ay06wp0ODqK1r0r s1MtXrJ2pk2tT/15J6DBX1ZPGVEkdvlALbYhqz38n3oNtV2NbqCP9CgXUopCmi6R0yLJ Srx0RUJ/VmYeJTv3+eUknMdK200u5zKzSMh7LKIqjLNSblSm63qsK6aHfn2csaDZzxDh KSXu/k+09rOSfMCt5ptg9EVU/zgqdXYN5UeC+MbB9HwCNdCdyc5pb5MVl4kDX80etKfZ nhZaaom4/R1rM/wKo0YUGCdkAR/Z2ovCA+Zdi4cJW5J0g8fbObVhqXn9zUlwyNgiXERm jF5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qQ6IRTp0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si5281416pfc.98.2018.12.23.13.54.06; Sun, 23 Dec 2018 13:54:21 -0800 (PST) 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=@google.com header.s=20161025 header.b=qQ6IRTp0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725954AbeLWVwz (ORCPT + 99 others); Sun, 23 Dec 2018 16:52:55 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:52459 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbeLWVwz (ORCPT ); Sun, 23 Dec 2018 16:52:55 -0500 Received: by mail-it1-f193.google.com with SMTP id g76so13967841itg.2 for ; Sun, 23 Dec 2018 13:52:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C4T60ebSd3XIwaQkfiltqImM3j39ie8rJCcw2QWQ+cE=; b=qQ6IRTp0R0sDr0+/cQCb1bhVRyBuCmCtaXTPV3kTBlaLObAmpzTVBfH0HjRoXAuZfC d3WBdioCF184RSxQOc/d2ADGit34MQFBudOgHqi7yZBUFb7qxfXXtSGrEfB3EULjV76U 4PVUdpS2tmMm3pZfI1Ky5aZH/eAe1sxuW2CSvYB09tRZCFEA4amu7vEF/kKrX51Z/aLk 48095xl+iY0FrKoNb7Qv0/4RnhZSCYGdYal88WBZlDTP++qo/OyQ4I1EjgDKehU+v5Af ZZuKdN8KraBtlUTkxwahdlgn22t5eBdw6Jvpamxou5NrVhOCRSb3l39iVj1OMBkj3B5U iaXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C4T60ebSd3XIwaQkfiltqImM3j39ie8rJCcw2QWQ+cE=; b=d51UwzH2Ue56jdh1S3YNMvalgFe2BdlD3gRltM/hwBO2fThbYOaKYDISxDdLcTJ0yM cA/4alb+KuVSedS7+bZyMd1mgsvmEugV8kfdx2f12R2unM/Ruv+Wx7Q1dWquTrI6qSNF MtSlFlRuixe7PX/nZ6cwCEGWTFYMpi4IWSauPpmyVvNG2+M+nqmP3BHvjbIdrCdOpuW/ fAqU9kdSrRuYBdZ47zvbfDA76+C2E4tHr5xiQxsI8FFAgXSwUN6zgYbK02hKT0Dybhvc yOm4mhMeiFGdw+O5Z7K5T09//li8p+AqHhcKVZvhm+f/+7pK+5Hi19D79QBA1pLJT7yl CcTQ== X-Gm-Message-State: AA+aEWYidJWbbyl4VH/8NIRo6uArqDQd7b+yQJlSLaIIYVBU/kqrLGZd VZynXWVEnqCAVsh6guZLjb5IEw== X-Received: by 2002:a24:878c:: with SMTP id f134mr7405915ite.81.1545601973690; Sun, 23 Dec 2018 13:52:53 -0800 (PST) Received: from yuzhao.bld.corp.google.com ([2620:15c:183:0:a0c3:519e:9276:fc96]) by smtp.gmail.com with ESMTPSA id v74sm10386881ita.27.2018.12.23.13.52.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Dec 2018 13:52:53 -0800 (PST) From: Yu Zhao To: David Airlie , Daniel Vetter , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher Cc: David Zhou , Samuel Li , Harry Wentland , Junwei Zhang , Daniel Stone , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yu Zhao , stable@vger.kernel.org Subject: [PATCH v4 2/2] drm/amd: validate user GEM object size Date: Sun, 23 Dec 2018 14:52:39 -0700 Message-Id: <20181223215239.173339-2-yuzhao@google.com> X-Mailer: git-send-email 2.20.1.415.g653613c723-goog In-Reply-To: <20181223215239.173339-1-yuzhao@google.com> References: <20181222192712.9420-1-yuzhao@google.com> <20181223215239.173339-1-yuzhao@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When creating frame buffer, userspace may request to attach to a previously allocated GEM object that is smaller than what GPU requires. Validation must be done to prevent out-of-bound DMA, which could not only corrupt memory but also reveal sensitive data. This fix is not done in a common code path because individual driver might have different requirement. Cc: stable@vger.kernel.org # v4.2+ Signed-off-by: Yu Zhao --- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c index af0626a2b528..9aa23cb20873 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c @@ -527,6 +527,7 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev, struct drm_gem_object *obj; struct amdgpu_framebuffer *amdgpu_fb; int ret; + int height; struct amdgpu_device *adev = dev->dev_private; int cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0); int pitch = amdgpu_align_pitch(adev, mode_cmd->width, cpp, false); @@ -550,6 +551,13 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev, return ERR_PTR(-EINVAL); } + height = ALIGN(mode_cmd->height, 8); + if (obj->size < pitch * height) { + DRM_DEBUG_KMS("Invalid GEM size: expecting >= %d but got %zu\n", + pitch * height, obj->size); + return ERR_PTR(-EINVAL); + } + amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL); if (amdgpu_fb == NULL) { drm_gem_object_put_unlocked(obj); -- 2.20.1.415.g653613c723-goog