Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2352913pxb; Mon, 20 Sep 2021 19:50:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEaGSMk8O8+AiPpvCZRkeJeqVSKM6czGkQivQKBXWbdhwMyzgSRPp4yQmb4GmweFSzV3RY X-Received: by 2002:a05:6e02:ea2:: with SMTP id u2mr20321264ilj.133.1632192632239; Mon, 20 Sep 2021 19:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192632; cv=none; d=google.com; s=arc-20160816; b=DLRrcAtYKnoPy6KERvYXQMN2r+TkXufx7J5ug9KpZHGUwTcfGlPf5cRtfKgYaGwdn8 1y+kxbAwDvqpa2lU+0uqdBrjcEBxESGLoKyMZEmDKM9i7yvUP3TlxvCsEAretbpTTeDn 8ZjYnHyXT95WNUlQzPUDgMi4gJ6ekli2rv0vUqUuhK1Rdap2i+QqkyjYmKdbvAskaXRv QXtXyiSLnko2UVG2VlRa9oCWWBxf0gecwGgNmtfy1D7w2RYpnWFN8F5q27WijHfHspiz /+cYCGI8iQ3IFUsL16AdhdzpBcWGXBLowvoTtb/CKteoJ6RlbXm1YP9wFS2S/ty/es2d SbVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fYvjBEEVIgzK2oQoAnCzXJNQm/KiGHYSMt4MNlwx+F0=; b=voE/ihqhV357rDI3S/00yppA6HisaOZ5P4vlmoSIdPpa5xuwlDec0JDgGof9zjWFCx tZjl18+JPVESFWOwYBOQD/FW0UlEWu2pta4DEs18cyMUgqM/jxyzQA2NTtgYFXtfbbCe QPRO+IoMuyzMa3AM2sA0nPWU3rstL7WYVkL/BW1p+/eAFvsXk5/pkKaWTUehd6Yr/zTQ l/mlKOQLheHkCy1msNYd20q+9FXpBpOYhsq2G3MmE9R3s8ndbNc8ApWsgFyLRB/Ee3BU HsuhIVlchUn8mpQAoBA3prFnBaRpvdZOVd2CIy89Pz161l6M6RcbJR4UkhvlGPxjUM6W bX9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZOjyNkmz; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si16161857iow.113.2021.09.20.19.50.19; Mon, 20 Sep 2021 19:50:32 -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=@linuxfoundation.org header.s=korg header.b=ZOjyNkmz; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353574AbhITSlP (ORCPT + 99 others); Mon, 20 Sep 2021 14:41:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:52048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379743AbhITSg1 (ORCPT ); Mon, 20 Sep 2021 14:36:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A84F863317; Mon, 20 Sep 2021 17:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158968; bh=r8FTPvJxXE+wC6Tv736YV3bi0zSs/+qRb6U3teRNAdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOjyNkmzgxqn6j4PcmtNGxiAZI2OA8p5z6shTUhtOLkENN8BSSuQbhJy5oIQToj16 4pyd3jv2vXDGjCw2IhvNIHYj7c6v8O0BsbDIOMA1EWGmh53x+Zf/ReILhZNAiMnEsT UYxaTqxgRlSQRw02za/y+0sxVBEZDuExydPs+T9w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Nirmoy Das , =?UTF-8?q?Michel=20D=C3=A4nzer?= , Alex Deucher Subject: [PATCH 5.14 016/168] drm/amdgpu: fix use after free during BO move Date: Mon, 20 Sep 2021 18:42:34 +0200 Message-Id: <20210920163922.180392385@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian König commit c92db8d64f9e0313e7ecdc9500db93a5040c9370 upstream. The memory backing old_mem is already freed at that point, move the check a bit more up. Signed-off-by: Christian König Fixes: bfa3357ef9ab ("drm/ttm: allocate resource object instead of embedding it v2") Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1699 Acked-by: Nirmoy Das Reviewed-by: Michel Dänzer Signed-off-by: Alex Deucher Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -513,6 +513,15 @@ static int amdgpu_bo_move(struct ttm_buf goto out; } + if (bo->type == ttm_bo_type_device && + new_mem->mem_type == TTM_PL_VRAM && + old_mem->mem_type != TTM_PL_VRAM) { + /* amdgpu_bo_fault_reserve_notify will re-set this if the CPU + * accesses the BO after it's moved. + */ + abo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; + } + if (adev->mman.buffer_funcs_enabled) { if (((old_mem->mem_type == TTM_PL_SYSTEM && new_mem->mem_type == TTM_PL_VRAM) || @@ -543,15 +552,6 @@ static int amdgpu_bo_move(struct ttm_buf return r; } - if (bo->type == ttm_bo_type_device && - new_mem->mem_type == TTM_PL_VRAM && - old_mem->mem_type != TTM_PL_VRAM) { - /* amdgpu_bo_fault_reserve_notify will re-set this if the CPU - * accesses the BO after it's moved. - */ - abo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; - } - out: /* update statistics */ atomic64_add(bo->base.size, &adev->num_bytes_moved);