CVE-2025-40096
JSON

7.8high

drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies

Severity
7.8high CVSS:3.1 by Linux
Exploit likelihood
0.16% (higher than 5% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
Linux

Description

In the Linux kernel, the following vulnerability has been resolved: drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies When adding dependencies with drm_sched_job_add_dependency(), that function consumes the fence reference both on success and failure, so in the latter case the dma_fence_put() on the error path (xarray failed to expand) is a double free. Interestingly this bug appears to have been present ever since commit ebd5f74255b9 ("drm/sched: Add dependency tracking"), since the code back then looked like this: drm_sched_job_add_implicit_dependencies(): ... for (i = 0; i < fence_count; i++) { ret = drm_sched_job_add_dependency(job, fences[i]); if (ret) break; } for (; i < fence_count; i++) dma_fence_put(fences[i]); Which means for the failing 'i' the dma_fence_put was already a double free. Possibly there were no users at that time, or the test cases were insufficient to hit it. The bug was then only noticed and fixed after commit 9c2ba265352a ("drm/scheduler: use new iterator in drm_sched_job_add_implicit_dependencies v2") landed, with its fixup of commit 4eaf02d6076c ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies"). At that point it was a slightly different flavour of a double free, which commit 963d0b356935 ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies harder") noticed and attempted to fix. But it only moved the double free from happening inside the drm_sched_job_add_dependency(), when releasing the reference not yet obtained, to the caller, when releasing the reference already released by the former in the failure case. As such it is not easy to identify the right target for the fixes tag so lets keep it simple and just continue the chain. While fixing we also improve the comment and explain the reason for taking the reference and not dropping it.

Affected

Product or packageVersionsReported by
Linux Linuxfrom 963d0b3569354230f6e2c36a286ef270a8901878 before 4c38a63ae12ecc9370a7678077bde2d61aa80e9c, from 963d0b3569354230f6e2c36a286ef270a8901878 before 57239762aa90ad768dac055021f27705dae73344, from 963d0b3569354230f6e2c36a286ef270a8901878 before e5e3eb2aff92994ee81ce633f1c4e73bd4b87e11, from 963d0b3569354230f6e2c36a286ef270a8901878 before fdfb47e85af1e11ec822c82739dde2dd8dff5115, from 963d0b3569354230f6e2c36a286ef270a8901878 before 5801e65206b065b0b2af032f7f1eef222aa2fd83, 5.16
Not affected: before 5.16, from 6.1.158 up to 6.1.*, from 6.6.114 up to 6.6.*, from 6.12.55 up to 6.12.*, from 6.17.5 up to 6.17.*, from 6.18 up to *
CVE List

Classification

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

In the Linux kernel, the following vulnerability has been resolved: drm/sched: Fix potential double free in drm_sched_job_add_resv_dependencies When adding dependencies with drm_sched_job_add_dependency(), that function consumes the fence reference both on success and failure, so in the latter case the dma_fence_put() on the error path (xarray failed to expand) is a double free. Interestingly this bug appears to have been present ever since commit ebd5f74255b9 ("drm/sched: Add dependency tracking"), since the code back then looked like this: drm_sched_job_add_implicit_dependencies(): ... for (i = 0; i < fence_count; i++) { ret = drm_sched_job_add_dependency(job, fences[i]); if (ret) break; } for (; i < fence_count; i++) dma_fence_put(fences[i]); Which means for the failing 'i' the dma_fence_put was already a double free. Possibly there were no users at that time, or the test cases were insufficient to hit it. The bug was then only noticed and fixed after commit 9c2ba265352a ("drm/scheduler: use new iterator in drm_sched_job_add_implicit_dependencies v2") landed, with its fixup of commit 4eaf02d6076c ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies"). At that point it was a slightly different flavour of a double free, which commit 963d0b356935 ("drm/scheduler: fix drm_sched_job_add_implicit_dependencies harder") noticed and attempted to fix. But it only moved the double free from happening inside the drm_sched_job_add_dependency(), when releasing the reference not yet obtained, to the caller, when releasing the reference already released by the former in the failure case. As such it is not easy to identify the right target for the fixes tag so lets keep it simple and just continue the chain. While fixing we also improve the comment and explain the reason for taking the reference and not dropping it.

NVD (es)

En el kernel de Linux, la siguiente vulnerabilidad ha sido resuelta: drm/sched: Corrige una posible doble liberación en drm_sched_job_add_resv_dependencies Al añadir dependencias con drm_sched_job_add_dependency(), esa función consume la referencia de la valla tanto en caso de éxito como de fallo, por lo que en este último caso el dma_fence_put() en la ruta de error (xarray no pudo expandirse) es una doble liberación. Curiosamente, este error parece haber estado presente desde el commit ebd5f74255b9 ('drm/sched: Add dependency tracking'), ya que el código en aquel entonces se veía así: drm_sched_job_add_implicit_dependencies(): ... for (i = 0; i < fence_count; i++) { ret = drm_sched_job_add_dependency(job, fences[i]); if (ret) break; } for (; i < fence_count; i++) dma_fence_put(fences[i]); Lo que significa que para la 'i' fallida el dma_fence_put ya era una doble liberación. Posiblemente no había usuarios en ese momento, o los casos de prueba eran insuficientes para detectarlo. El error fue entonces solo notado y corregido después de que el commit 9c2ba265352a ('drm/scheduler: use new iterator in drm_sched_job_add_implicit_dependencies v2') aterrizara, con su corrección del commit 4eaf02d6076c ('drm/scheduler: fix drm_sched_job_add_implicit_dependencies'). En ese momento era una variante ligeramente diferente de una doble liberación, que el commit 963d0b356935 ('drm/scheduler: fix drm_sched_job_add_implicit_dependencies harder') notó e intentó corregir. Pero solo movió la doble liberación de ocurrir dentro de drm_sched_job_add_dependency(), al liberar la referencia aún no obtenida, al llamador, al liberar la referencia ya liberada por el primero en el caso de fallo. Como tal, no es fácil identificar el objetivo correcto para la etiqueta de correcciones, así que mantengámoslo simple y simplemente continuemos la cadena. Mientras corregimos, también mejoramos el comentario y explicamos la razón para tomar la referencia y no soltarla.

References

Sources

SourceRecordLicence
CVE ListCVE-2025-40096 changed 2026-08-05CVE Terms of Use
NVDCVE-2025-40096 changed 2026-10-19Public domain