Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp93136pxy; Sat, 31 Jul 2021 01:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDnJPqU6CTt1Z6+DIuFS8p2lj+Hjk9Npv8f+S0DzHEb4d313c9NIMuzrVP0iIQ5Ym71a12 X-Received: by 2002:a5e:8208:: with SMTP id l8mr2698187iom.197.1627718808205; Sat, 31 Jul 2021 01:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627718808; cv=none; d=google.com; s=arc-20160816; b=erm7tG2Vll3itVYcrFbgnqzhVMd/EBb2iAeMvz/9EezDrtlPGjjkqyakvpFABhMCvG BidfY5Vmf7ybBvx6rgL6CnXpC7oIhS/n0htGOJAj73du+O6W+z0QQIa8PGncVDx0RDHi Fvyyj1M8s2FvRi2967HIyVLQfZCC16VJcwbWF1uHocdYKXiY8JBHTijSIBLHfW6jBXGR UR0u2igUiT87HvFoLwoubKY3VCz4TmNeGn8LlFuUReiIhHLcoqu9iq9yYCdRqg9MomDk KiYo++rE7pcU4fQS70gvfost6VW0VljZ5YhYA0gtim5GW1vesSXTI7INbODIgI0JuDoq fiAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=M8s8mhhqZ8Up+UA2vSw3vvwlmTtYXes+e5VhDxbCIyA=; b=A1KXr5mHPQ/pyTH+tcn0mQB8xbHBeEsDQ48ROcJyUf8/SO1AO9KNyu5lnpi3B/e99k u1HOmCmZooXNX3Jnz/omhZYU6RCrDUn3NAynbnY8alUx3JdXsvd3cNfcO+Vl8oBpoX8/ DQCLt2WurpO/8h61gChSLUIkNDiGBqlIt07cNgpJqA3y/k3Ng3SLgRBbs/5Fa5J7K+FP mkHiz8bQUQiS8rEUPOkc0SCymt4YtYlCQt8Ks7wyRvvbJEv+vkiyIywGAYB6iWPgV8tl n7hvwwFA5hbMa0HZ2l6A6Eq14h5KumvKRJli9EPDT16lJZvvbU/E3xN/+biZTaE7syHB +ivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bLCvfbuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si4661996jat.115.2021.07.31.01.06.31; Sat, 31 Jul 2021 01:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bLCvfbuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232812AbhGaIFs (ORCPT + 99 others); Sat, 31 Jul 2021 04:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbhGaIFr (ORCPT ); Sat, 31 Jul 2021 04:05:47 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95969C06175F; Sat, 31 Jul 2021 01:05:40 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id m11so1618372plx.4; Sat, 31 Jul 2021 01:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=M8s8mhhqZ8Up+UA2vSw3vvwlmTtYXes+e5VhDxbCIyA=; b=bLCvfbuEP6qV/fkOAbd7z0uDgSx0ITQwQ67JwV6y4UggR35pF/iBN9Y8uYAn4i/h1Q +OmDW2Bp+HnZF8bq9DQrAQLAEtP7Hmw43DF3bGKC9mVG1uM++cb6eue6AYxwUf5FGa/5 yygFB1IvISIM9pbIojyzAmH8J9NROnYxvvngVaPra8EzHBvCwLcguFYJNOaNzh22y/DI xG2VSnH4tKPMDU1rbk/FTaKi279oWIWrgkhDyJsmN7b6bOcccMIb7I2RPvOU1KzK9+Jm 1fy57BXltuQjLDKNAwRGrPzvaxfc77lC6ehTunPUh7Se1cx+02jNjUKqTV0KXl+Td99o rqiA== 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:mime-version :content-transfer-encoding; bh=M8s8mhhqZ8Up+UA2vSw3vvwlmTtYXes+e5VhDxbCIyA=; b=KQ5p0cQUYc7HSesilmkr8P2RCjlWKllvoVJ5EnJIcUfoVBuNiyrJzo/NOw8S/VcPA8 sY3YHn16X2cCKutsK7BQ2r/lgajv9P+xs3pTYjj1vQTRQryCZR2oIuHBnUPETlmOsAke toQCyOc/ByM9KI02VRqQEAkroxeS8F/GdZkssTyodABL9qQ814YEtkjo+vAEViDnvu2K R/ANubDqNIojqeeZPqMg1oxxQI2Rxn2uXcFc7G4bSj8HGyQBs/6xja8LJgz0eG2E0nKH dS6/5OgsnMekOfdSck5S9mLvH5VIWT1eK5ryHiklNqnFK0viUl1mK+lC21Pd6QYBFx2q YVdw== X-Gm-Message-State: AOAM532Ix96m96UOv43K3BJYZ9IniPScyOe8iRSZMxQ1O8B+dKYQUUHi 9qlBBar1u3OG1N/HD7xtqYY= X-Received: by 2002:a63:b60:: with SMTP id a32mr1585053pgl.29.1627718740214; Sat, 31 Jul 2021 01:05:40 -0700 (PDT) Received: from localhost.localdomain ([45.135.186.29]) by smtp.gmail.com with ESMTPSA id c7sm5288427pgq.22.2021.07.31.01.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 01:05:39 -0700 (PDT) From: Tuo Li To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, airlied@redhat.com, Felix.Kuehling@amd.com, Oak.Zeng@amd.com, nirmoy.das@amd.com, tzimmermann@suse.de, Philip.Yang@amd.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, baijiaju1990@gmail.com, Tuo Li , TOTE Robot Subject: [PATCH] drm/amdgpu: fix possible null-pointer dereference in amdgpu_ttm_tt_populate() Date: Sat, 31 Jul 2021 01:04:37 -0700 Message-Id: <20210731080437.74539-1-islituo@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable ttm is assigned to the variable gtt, and the variable gtt is checked in: if (gtt && gtt->userptr) This indicates that both ttm and gtt can be NULL. If so, a null-pointer dereference will occur: if (ttm->page_flags & TTM_PAGE_FLAG_SG) Also, some null-pointer dereferences will occur in the function ttm_pool_alloc() which is called in: return ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx); To fix these possible null-pointer dereferences, the function returns -EINVAL when ttm is NULL. Reported-by: TOTE Robot Signed-off-by: Tuo Li --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 3a55f08e00e1..80440f799c09 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1120,8 +1120,11 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev, struct amdgpu_device *adev = amdgpu_ttm_adev(bdev); struct amdgpu_ttm_tt *gtt = (void *)ttm; + if (ttm == NULL) + return -EINVAL; + /* user pages are bound by amdgpu_ttm_tt_pin_userptr() */ - if (gtt && gtt->userptr) { + if (gtt->userptr) { ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL); if (!ttm->sg) return -ENOMEM; -- 2.25.1