* [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions
@ 2026-06-29 9:04 Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 1/3] drm/amd/display: Fix dangling pointer in plane reset function Evgenii Burenchev
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Evgenii Burenchev @ 2026-06-29 9:04 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Evgenii Burenchev, harry.wentland, sunpeng.li, siqueira,
alexander.deucher, christian.koenig, airlied, simona,
mario.limonciello, alex.hung, superm1, timur.kristof,
ivan.lipski, ray.wu, aurabindo.pillai, chen-yu.chen, mripard,
Dillon.Varone, mwen, chiahsuan.chung, kenneth.feng,
srinivasan.shanmugam, tzimmermann, Alvin.Lee2, dmitry.baryshkov,
chaitanya.kumar.borah, ekurzinger, pierre-eric.pelloux-prayer,
HaoPing.Liu, Tony.Cheng, amd-gfx, dri-devel, linux-kernel,
lvc-project
This series fixes a dangling pointer issue in three reset functions:
- amdgpu_dm_plane_drm_plane_reset()
- amdgpu_dm_crtc_reset_state()
- amdgpu_dm_connector_funcs_reset()
Each function frees the old state before allocating a new one. If
kzalloc_obj() fails, the function returns without updating the state
pointer, leaving a dangling pointer to already freed memory.
The fix is to allocate the new state first. On allocation failure,
the old state remains untouched and the function safely returns.
For the connector function, additionally restore the explicit
kfree(old_state) which was lost during refactoring.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
---
Evgenii Burenchev (3):
drm/amd/display: Fix dangling pointer in plane reset function
drm/amd/display: Fix dangling pointer in CRTC reset function
drm/amd/display: Fix dangling pointer in connector reset function
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 ++++++++++---------
.../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++--
.../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 ++---
3 files changed, 28 insertions(+), 29 deletions(-)
---
Changes in v4:
- Split into three separate patches as requested (reviewer Fedor Pchelkin)
- Remove WARN_ON on memory allocation failure (reviewer Fedor Pchelkin)
- Remove redundant comments (reviewer Fedor Pchelkin)
- Fix empty line in local variable declaration block (reviewer Fedor Pchelkin)
Changes in v3:
- Restore explicit kfree(old_state) in amdgpu_dm_connector_funcs_reset()
to prevent memory leak (reviewer Mario Limonciello)
Changes in v2:
- Also fix amdgpu_dm_crtc_reset_state() and amdgpu_dm_connector_funcs_reset()
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/3] drm/amd/display: Fix dangling pointer in plane reset function
2026-06-29 9:04 [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Evgenii Burenchev
@ 2026-06-29 9:04 ` Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 2/3] drm/amd/display: Fix dangling pointer in CRTC " Evgenii Burenchev
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Evgenii Burenchev @ 2026-06-29 9:04 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Evgenii Burenchev, harry.wentland, sunpeng.li, siqueira,
alexander.deucher, christian.koenig, airlied, simona,
mario.limonciello, alex.hung, superm1, timur.kristof,
ivan.lipski, ray.wu, aurabindo.pillai, chen-yu.chen, mripard,
Dillon.Varone, mwen, chiahsuan.chung, kenneth.feng,
srinivasan.shanmugam, tzimmermann, Alvin.Lee2, dmitry.baryshkov,
chaitanya.kumar.borah, ekurzinger, pierre-eric.pelloux-prayer,
HaoPing.Liu, Tony.Cheng, amd-gfx, dri-devel, linux-kernel,
lvc-project
amdgpu_dm_plane_drm_plane_reset() frees the old state before allocating
a new one. If kzalloc_obj() fails, the function returns without updating
the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the
old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 5d945cbcd4b1 ("drm/amd/display: Create a file dedicated to planes")
Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index c7f8e08feaf4..cfd76c54f652 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -1488,17 +1488,15 @@ static const struct drm_plane_helper_funcs dm_primary_plane_helper_funcs = {
static void amdgpu_dm_plane_drm_plane_reset(struct drm_plane *plane)
{
- struct dm_plane_state *amdgpu_state = NULL;
-
- if (plane->state)
- plane->funcs->atomic_destroy_state(plane, plane->state);
+ struct dm_plane_state *amdgpu_state;
amdgpu_state = kzalloc_obj(*amdgpu_state);
- WARN_ON(amdgpu_state == NULL);
-
if (!amdgpu_state)
return;
+ if (plane->state)
+ plane->funcs->atomic_destroy_state(plane, plane->state);
+
__drm_atomic_helper_plane_reset(plane, &amdgpu_state->base);
amdgpu_state->degamma_tf = AMDGPU_TRANSFER_FUNCTION_DEFAULT;
amdgpu_state->hdr_mult = AMDGPU_HDR_MULT_DEFAULT;
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/3] drm/amd/display: Fix dangling pointer in CRTC reset function
2026-06-29 9:04 [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 1/3] drm/amd/display: Fix dangling pointer in plane reset function Evgenii Burenchev
@ 2026-06-29 9:04 ` Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 3/3] drm/amd/display: Fix dangling pointer in connector " Evgenii Burenchev
2026-06-29 20:52 ` [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Mario Limonciello
3 siblings, 0 replies; 5+ messages in thread
From: Evgenii Burenchev @ 2026-06-29 9:04 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Evgenii Burenchev, harry.wentland, sunpeng.li, siqueira,
alexander.deucher, christian.koenig, airlied, simona,
mario.limonciello, alex.hung, superm1, timur.kristof,
ivan.lipski, ray.wu, aurabindo.pillai, chen-yu.chen, mripard,
Dillon.Varone, mwen, chiahsuan.chung, kenneth.feng,
srinivasan.shanmugam, tzimmermann, Alvin.Lee2, dmitry.baryshkov,
chaitanya.kumar.borah, ekurzinger, pierre-eric.pelloux-prayer,
HaoPing.Liu, Tony.Cheng, amd-gfx, dri-devel, linux-kernel,
lvc-project, mdaenzer
amdgpu_dm_crtc_reset_state() frees the old state before allocating
a new one. If kzalloc_obj() fails, the function returns without updating
the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the
old state remains untouched and the function safely returns.
Fixes: 473683a03495 ("drm/amd/display: Create a file dedicated for CRTC")
Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
---
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
index 3dcedaa67ed8..5b5c4023a514 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
@@ -437,13 +437,13 @@ static void amdgpu_dm_crtc_reset_state(struct drm_crtc *crtc)
{
struct dm_crtc_state *state;
- if (crtc->state)
- amdgpu_dm_crtc_destroy_state(crtc, crtc->state);
-
state = kzalloc_obj(*state);
- if (WARN_ON(!state))
+ if (!state)
return;
+ if (crtc->state)
+ amdgpu_dm_crtc_destroy_state(crtc, crtc->state);
+
__drm_atomic_helper_crtc_reset(crtc, &state->base);
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 3/3] drm/amd/display: Fix dangling pointer in connector reset function
2026-06-29 9:04 [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 1/3] drm/amd/display: Fix dangling pointer in plane reset function Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 2/3] drm/amd/display: Fix dangling pointer in CRTC " Evgenii Burenchev
@ 2026-06-29 9:04 ` Evgenii Burenchev
2026-06-29 20:52 ` [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Mario Limonciello
3 siblings, 0 replies; 5+ messages in thread
From: Evgenii Burenchev @ 2026-06-29 9:04 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Evgenii Burenchev, harry.wentland, sunpeng.li, siqueira,
alexander.deucher, christian.koenig, airlied, simona,
mario.limonciello, alex.hung, superm1, timur.kristof,
ivan.lipski, ray.wu, aurabindo.pillai, chen-yu.chen, mripard,
Dillon.Varone, mwen, chiahsuan.chung, kenneth.feng,
srinivasan.shanmugam, tzimmermann, Alvin.Lee2, dmitry.baryshkov,
chaitanya.kumar.borah, ekurzinger, pierre-eric.pelloux-prayer,
HaoPing.Liu, Tony.Cheng, amd-gfx, dri-devel, linux-kernel,
lvc-project
amdgpu_dm_connector_funcs_reset() frees the old state before allocating
a new one. If kzalloc_obj() fails, the function returns without updating
the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the
old state remains untouched and the function safely returns.
Additionally restore the explicit kfree(old_state) which was lost when
the function was refactored, as __drm_atomic_helper_connector_destroy_state()
only frees resources but not the state structure itself.
Fixes: e7b07ceef2a6 ("drm/amd/display: Merge amdgpu_dm_types and amdgpu_dm")
Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 ++++++++++---------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index d3a8d681227a..b1f91dd0ab61 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8151,33 +8151,34 @@ static void amdgpu_dm_connector_destroy(struct drm_connector *connector)
void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector)
{
- struct dm_connector_state *state =
+ struct dm_connector_state *old_state =
to_dm_connector_state(connector->state);
+ struct dm_connector_state *state;
+
+ state = kzalloc_obj(*state);
+ if (!state)
+ return;
if (connector->state)
__drm_atomic_helper_connector_destroy_state(connector->state);
- kfree(state);
+ kfree(old_state);
- state = kzalloc_obj(*state);
+ __drm_atomic_helper_connector_reset(connector, &state->base);
- if (state) {
- state->scaling = RMX_OFF;
- state->underscan_enable = false;
- state->underscan_hborder = 0;
- state->underscan_vborder = 0;
- state->base.max_requested_bpc = 8;
- state->vcpi_slots = 0;
- state->pbn = 0;
-
- if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
- if (amdgpu_dm_abm_level <= 0)
- state->abm_level = ABM_LEVEL_IMMEDIATE_DISABLE;
- else
- state->abm_level = amdgpu_dm_abm_level;
- }
+ state->scaling = RMX_OFF;
+ state->underscan_enable = false;
+ state->underscan_hborder = 0;
+ state->underscan_vborder = 0;
+ state->base.max_requested_bpc = 8;
+ state->vcpi_slots = 0;
+ state->pbn = 0;
- __drm_atomic_helper_connector_reset(connector, &state->base);
+ if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
+ if (amdgpu_dm_abm_level <= 0)
+ state->abm_level = ABM_LEVEL_IMMEDIATE_DISABLE;
+ else
+ state->abm_level = amdgpu_dm_abm_level;
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions
2026-06-29 9:04 [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Evgenii Burenchev
` (2 preceding siblings ...)
2026-06-29 9:04 ` [PATCH v4 3/3] drm/amd/display: Fix dangling pointer in connector " Evgenii Burenchev
@ 2026-06-29 20:52 ` Mario Limonciello
3 siblings, 0 replies; 5+ messages in thread
From: Mario Limonciello @ 2026-06-29 20:52 UTC (permalink / raw)
To: Evgenii Burenchev, stable, Greg Kroah-Hartman
Cc: harry.wentland, sunpeng.li, siqueira, alexander.deucher,
christian.koenig, airlied, simona, alex.hung, superm1,
timur.kristof, ivan.lipski, ray.wu, aurabindo.pillai,
chen-yu.chen, mripard, Dillon.Varone, mwen, chiahsuan.chung,
kenneth.feng, srinivasan.shanmugam, tzimmermann, Alvin.Lee2,
dmitry.baryshkov, chaitanya.kumar.borah, ekurzinger,
pierre-eric.pelloux-prayer, HaoPing.Liu, Tony.Cheng, amd-gfx,
dri-devel, linux-kernel, lvc-project
On 6/29/26 04:04, Evgenii Burenchev wrote:
> This series fixes a dangling pointer issue in three reset functions:
> - amdgpu_dm_plane_drm_plane_reset()
> - amdgpu_dm_crtc_reset_state()
> - amdgpu_dm_connector_funcs_reset()
>
> Each function frees the old state before allocating a new one. If
> kzalloc_obj() fails, the function returns without updating the state
> pointer, leaving a dangling pointer to already freed memory.
>
> The fix is to allocate the new state first. On allocation failure,
> the old state remains untouched and the function safely returns.
>
> For the connector function, additionally restore the explicit
> kfree(old_state) which was lost during refactoring.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
> ---
> Evgenii Burenchev (3):
> drm/amd/display: Fix dangling pointer in plane reset function
> drm/amd/display: Fix dangling pointer in CRTC reset function
> drm/amd/display: Fix dangling pointer in connector reset function
>
> .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 ++++++++++---------
> .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++--
> .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 ++---
> 3 files changed, 28 insertions(+), 29 deletions(-)
> ---
> Changes in v4:
> - Split into three separate patches as requested (reviewer Fedor Pchelkin)
> - Remove WARN_ON on memory allocation failure (reviewer Fedor Pchelkin)
> - Remove redundant comments (reviewer Fedor Pchelkin)
> - Fix empty line in local variable declaration block (reviewer Fedor Pchelkin)
>
> Changes in v3:
> - Restore explicit kfree(old_state) in amdgpu_dm_connector_funcs_reset()
> to prevent memory leak (reviewer Mario Limonciello)
>
> Changes in v2:
> - Also fix amdgpu_dm_crtc_reset_state() and amdgpu_dm_connector_funcs_reset()
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
I will apply the series to amd-staging-drm-next and it will come in a
future to drm-fixes.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-29 20:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-29 9:04 [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 1/3] drm/amd/display: Fix dangling pointer in plane reset function Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 2/3] drm/amd/display: Fix dangling pointer in CRTC " Evgenii Burenchev
2026-06-29 9:04 ` [PATCH v4 3/3] drm/amd/display: Fix dangling pointer in connector " Evgenii Burenchev
2026-06-29 20:52 ` [PATCH v4 0/3] drm/amd/display: Fix dangling pointers in state reset functions Mario Limonciello
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®