Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp676844imu; Fri, 21 Dec 2018 05:44:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN71gRHf3eONhrpgLer3XgCMl5ArhaPqzwDEYtzTza3Kj1PG2bkHb6eu5PG5istWvFj2utkG X-Received: by 2002:a17:902:7581:: with SMTP id j1mr2619981pll.308.1545399874018; Fri, 21 Dec 2018 05:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545399873; cv=none; d=google.com; s=arc-20160816; b=blMoDLbrCbFbrvn+26ixz7ECaTqgXch95tkBJwG6srjtflYwUQfqaoQpvuTPtRKVNZ U2K7NULuQZtTYjwrzTcmuofIR2Xd4/GDOV2XBI5dq0qP4M3AIfSsWnBsrvc7S+Csk+Rt uCkm8ekQ1meghc1GXTNweirQmFozGE/agrY/yZ3fQ2G5f4SvKrhfYGkCyli4Mwa+dumg eOyAjf3uhPw6+pztG5q1ZhYWYQtMMvT7vM5lEV4LKwa/XU57ia6MeEl/QOnHgVYm2UM0 iXqs2vURtuiMrV5hTviFou+tUZg6lFRaWapcrQRFHdj0BL2zQi8qIQUOi1MV0xEpLQoK yVSQ== 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=qVA79DYVZGjAPTiYQY7DmNDV4w0iyvWD1MDEJ+YKub0=; b=Zf/EWxx9OJnriM5no6ZzddPZPKBKZBHgPjK6R0IgETG5eQ7sRjm6laQoVpOMSM095h SZGCvuxoky0W/HQJkeLxePw48u8GmHCovF1dzs1mBYi3HXEV0CkDva+AebEF6cPXylsZ tnA3ZApvzpeX+m/opPr5tx0lTEOhmOsNqiSWl6sZCo6nu3QNHljw53IWh3UcHjzSYhLZ LFrk4YGESaEHplTRZiJ1a3dmBpBLuSQW0GVeYCG23393s2Q5IpoeNuViQ+y4XrZtH3Pl mEyLWMEmGn3k5bPIirzeQeANYAjrhdrEnD5X8opORC3mMezhGT2R0Inrg5ukymGDGRly mSgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IeSGlxjc; 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 g22si24476955pfj.222.2018.12.21.05.44.18; Fri, 21 Dec 2018 05:44:33 -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=IeSGlxjc; 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 S2388971AbeLUDLL (ORCPT + 99 others); Thu, 20 Dec 2018 22:11:11 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:35761 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732931AbeLUDLL (ORCPT ); Thu, 20 Dec 2018 22:11:11 -0500 Received: by mail-it1-f194.google.com with SMTP id p197so4784246itp.0 for ; Thu, 20 Dec 2018 19:11:10 -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=qVA79DYVZGjAPTiYQY7DmNDV4w0iyvWD1MDEJ+YKub0=; b=IeSGlxjcI+TpjYCFxk147TXVKJ6dQAo/r1SVykZSPMRC/+hLQx/e3+kRL/qRGTRziR D57iE8nfffDLLTuCHE+QanvltxfhOGFHkG+okuXLGAm85pBceLPSnmZ87tIxRTZXTiqd P6c8diV5rzx5xrkPbI7RNtwE11NRn5lAKIxv0SQGbQEO1VbthIqvAzeEc1CCNVmKW7wb M6ybHVfOf3AK1nLHUYOTJr2Ote38tS51AC8iAPdn6MDrUt8Pm1XHF3dU4oyKMf1MMcYR WMKSc+o+TL3yfLKoHRtkQoJ5gsTWu80aBLVtXok9c8bTtSBULqqlJIqGnyGvpFrcR9zK ALSQ== 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=qVA79DYVZGjAPTiYQY7DmNDV4w0iyvWD1MDEJ+YKub0=; b=plUqdiKKeM/ED5wwlpgrVE6Xn/9kYrqaJ/kOJI2XDMFeRtoOkcnLqYczreFs5enDme z7wJusWg3WfX8YI1x3nDA1VSQkxypi8+Y22byNfom/WBF4r057JUx2CTeqD0RV0F25gn m8EYDgyKrK0BHM6BRPD5P0KGfAD/9YCXso9nrG9dEvR12uSwctTEtHfIPzdW4MS7f5sH LHI6KrFGgBkzvknJybCV780lCRS/QCyHU029590pRGS7SdwtBagbIChj+D/1LKdfNb50 waaQA3bg2rXOg6Ilnnwx3HPFDGA7btL/ttrpXyRY0YSSepBCdE/JqCH56yMenRzm7mPW 2OTg== X-Gm-Message-State: AA+aEWbl2aMwK9lWQ6QBvfOOQ1vs4ZGZBQ7dtml8Hku8UkKvZNolSHMt t/ddYrlwyUfOa/HYGxcMhSbEqA== X-Received: by 2002:a02:1dc8:: with SMTP id 191mr550671jaj.55.1545361870187; Thu, 20 Dec 2018 19:11:10 -0800 (PST) Received: from yuzhao.bld.corp.google.com ([2620:15c:183:0:a0c3:519e:9276:fc96]) by smtp.gmail.com with ESMTPSA id d133sm5425783itd.1.2018.12.20.19.11.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 19:11:09 -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 Subject: [PATCH 2/3] drm/amd: validate user pitch alignment Date: Thu, 20 Dec 2018 20:10:52 -0700 Message-Id: <20181221031053.240161-2-yuzhao@google.com> X-Mailer: git-send-email 2.20.1.415.g653613c723-goog In-Reply-To: <20181221031053.240161-1-yuzhao@google.com> References: <20181221031053.240161-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 Userspace may request pitch alignment that is not supported by GPU. Some requests 32, but GPU ignores it and uses default 64 when cpp is 4. If GEM object is allocated based on the smaller alignment, GPU DMA will go out of bound. For GPU that does frame buffer compression, DMA writing out of bound memory will cause memory corruption. Signed-off-by: Yu Zhao --- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c index e309d26170db..755daa332f8a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c @@ -527,6 +527,15 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev, struct drm_gem_object *obj; struct amdgpu_framebuffer *amdgpu_fb; int ret; + 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); + + if (mode_cmd->pitches[0] != pitch) { + dev_err(&dev->pdev->dev, "Invalid pitch: expecting %d but got %d\n", + pitch, mode_cmd->pitches[0]); + return ERR_PTR(-EINVAL); + } obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]); if (obj == NULL) { -- 2.20.1.415.g653613c723-goog