Subject: CVE-2024-41008: drm/amdgpu: change vm->task_info handling

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

drm/amdgpu: change vm->task_info handling

This patch changes the handling and lifecycle of vm->task_info object.
The major changes are:
- vm->task_info is a dynamically allocated ptr now, and its uasge is
  reference counted.
- introducing two new helper funcs for task_info lifecycle management
    - amdgpu_vm_get_task_info: reference counts up task_info before
      returning this info
    - amdgpu_vm_put_task_info: reference counts down task_info
- last put to task_info() frees task_info from the vm.

This patch also does logistical changes required for existing usage
of vm->task_info.

V2: Do not block all the prints when task_info not found (Felix)

V3: Fixed review comments from Felix
   - Fix wrong indentation
   - No debug message for -ENOMEM
   - Add NULL check for task_info
   - Do not duplicate the debug messages (ti vs no ti)
   - Get first reference of task_info in vm_init(), put last
     in vm_fini()

V4: Fixed review comments from Felix
   - fix double reference increment in create_task_info
   - change amdgpu_vm_get_task_info_pasid
   - additional changes in amdgpu_gem.c while porting

The Linux kernel CVE team has assigned CVE-2024-41008 to this issue.

Affected and fixed versions
===========================

	Fixed in 6.9 with commit b8f67b9ddf4f

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-41008
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
	drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
	drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
	drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c
	drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
	drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
	drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
	drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
	drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
	drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
	drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
	drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
	drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
	drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/b8f67b9ddf4f8fe6dd536590712b5912ad78f99c