Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4061104imu; Mon, 7 Jan 2019 14:53:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN4NqaynEi58q/4XnC4G/5LkQxCh0nR8eViMgrlqLR4XIvoSKx0fwcjU6cFtLBO57iy4sB8v X-Received: by 2002:a63:2507:: with SMTP id l7mr30128555pgl.22.1546901608828; Mon, 07 Jan 2019 14:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546901608; cv=none; d=google.com; s=arc-20160816; b=AjJ21BkfV/CkEElFGYEYP9WglqGjnsyfUt3+pYQ+Nsw9A6IKmPm6DkpprOG43gUl9B x5YmQTGbyjKooFBR+oHYHPW2BXY0P141QPiZzj7tM611YsBBMsWtUD3PvCgYsq0RGLsu rqkDPySFMY1nDsjX7xqXf/uSidJu+7MBusEJlmxvWSMPFZt0T6cELo0/Mm335+5+P4wx fXDUId07TOkE+wnNN4+bZIVU+y12a8Xbjxe0VvTz3AkHKqR6/xNFvMqskTAWRtthVr4m AtmVpUhKR7TY1ISy7bS7PAsgJKXC49LksO0NFymjL1IRAuBCLF2SBIfk+umuodS1H8nu eZdg== 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=mkKf9i6TdcB9R0RaIer+SvvdNV+GxmYU8yKh13/uJ4Q=; b=NPDNjmJ0jSVNGbJLUve2ZJms5UlV3F35iLE3/PA1Xd5OR3+nCc8XGLsG4AguGQ0FyB wggqXPwNSdTtMLLWhZ48G+wAmjPoZ0pC7eMADNjWyN8+b/ThKyMuEefATfCaAbtryJ47 vn/iGpI7YZl3fqUbXWVk5m7vMtuKtqzSRew4WG/P0qOvVdOiCiW69OhkEypx+gDRKH6y x4OkOybacChBCcJEa/lYrA5ZArlyKZOWHN5LNFKLxS0h7WUc1bqO2JCFGtSoo4JKHNcb EFH4tjdDBG2rp5LGhBrvuM43ERa++igE9DigZgd+2xzLcHvkuFxpOY4P9xtz+za/R+8c jfiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nnKuEr99; 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 h19si61970614plr.67.2019.01.07.14.53.13; Mon, 07 Jan 2019 14:53:28 -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=nnKuEr99; 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 S1727290AbfAGWvm (ORCPT + 99 others); Mon, 7 Jan 2019 17:51:42 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:39678 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727248AbfAGWvl (ORCPT ); Mon, 7 Jan 2019 17:51:41 -0500 Received: by mail-it1-f194.google.com with SMTP id a6so3507048itl.4 for ; Mon, 07 Jan 2019 14:51:41 -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=mkKf9i6TdcB9R0RaIer+SvvdNV+GxmYU8yKh13/uJ4Q=; b=nnKuEr99zTNxggVtXQ5HDzZv5Zd3V0C1NvD5UACvZ40O/z7ZevRSsYcForgsqHLhee c7Z0ggU9Xb0JHwMtbBQmCivO4+a5CO8alUAUMbNWGMapop+OtF0aHx+kbCmWNO26ncbp uqgu+Qjw1pDlcRtlhJxblNaXRNHUEim/wUffFn6BOnNVChJrlZJr/RwSVH+CTt/Dv6ET pX3JNJke1lLqEHeGg+UykjhnjMh2g1Zo/Kkl7V1P4Wsmsg38qHSY+3V5Yxs7G2fgumt6 iU9zOPcoyssc1+fOB6F1JpoXdoZcIrcSnwrsS4rgmeLlYwIdCzcGKNbv4GAxLFwcA/oF rCiw== 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=mkKf9i6TdcB9R0RaIer+SvvdNV+GxmYU8yKh13/uJ4Q=; b=jdnmduZekygNXOHJvVypdVm9gWVsIiOA8ZtJamSJpiTx5z6fwVIS6hdOVn8Ktbb4wN xfT7FVtzWiqQSngs+dwY4utpajk8V2QzfwlbA9tbsPh+4IZRMsDdk4NfCAVl/3jQ5ThQ YdZ2OiS3uFUWPcaeGvwVt+3toevawuWox6dCDnEmYgald2xLjE+eGlhM5LKB9mo5vJ3a SbvQqmn02J92dA1zQw+1mdRiS836PBJ6Nq3hVERvjRwepbh9TVFJsxbYbxzuM1GWV1ng kNNYuoM0d07CC5RglCCYma45ZLelFvSEI38bafQXA0UBbgEHXtC3wZEUzJ5KZLuguSvc QZTw== X-Gm-Message-State: AA+aEWYXsGCc/5tStoqrETXUiZy90D/Gb4wUPr6eMzcNefSTtClyUvI5 mvPMpm5J0wZIapnnjtLKSgQJkg== X-Received: by 2002:a02:9f96:: with SMTP id a22mr44857755jam.7.1546901500763; Mon, 07 Jan 2019 14:51:40 -0800 (PST) Received: from yuzhao.bld.corp.google.com ([2620:15c:183:0:a0c3:519e:9276:fc96]) by smtp.gmail.com with ESMTPSA id t10sm28512412ioi.4.2019.01.07.14.51.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 14:51:40 -0800 (PST) From: Yu Zhao To: =?UTF-8?q?Michel=20D=C3=A4nzer?= , 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 v6 2/2] drm/amd: validate user GEM object size Date: Mon, 7 Jan 2019 15:51:15 -0700 Message-Id: <20190107225115.163992-2-yuzhao@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190107225115.163992-1-yuzhao@google.com> References: <20181230010021.196990-1-yuzhao@google.com> <20190107225115.163992-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, otherwise it could be exploited to 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 de9f198d5371..32b7648b7ef4 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 = mode_cmd->pitches[0] / cpp; @@ -551,6 +552,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.97.g81188d93c3-goog