summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Ripard <mripard@kernel.org>2026-09-07 15:23:38 +0200
committerMaxime Ripard <mripard@kernel.org>2026-09-15 10:04:51 +0200
commitb94bff92ec1dcc968f06428df8b22c3bfcdfaf5e (patch)
tree5821aafba61e1117e76da95b83d8615665300c2a
parent80161e76e339615edbaf900a3592e6672f8ae685 (diff)
downloadlinux-next-b94bff92ec1dcc968f06428df8b22c3bfcdfaf5e.tar.gz
linux-next-b94bff92ec1dcc968f06428df8b22c3bfcdfaf5e.zip
drm/atomic_helper: Skip over NULL private_obj pointers
Just like for all other objects, drm_atomic_commit contains an array of drm_private_state, with the number of states found in num_private_objs. If we are to clean up a state by hand for some reason before calling drm_atomic_commit_put(), chances are that the pointer to the affected drm_private_obj and drm_private_states would have been cleared to avoid any use-after-free. However, since it's just an array, as we progress and free the items, we can't update num_private_objs as we go since we would reduce the array size, preventing us to remove the final elements. And if the caller was to forget to update num_private_objs after it iterated over the whole array, we're left with a (valid) array with a non-zero number of NULL elements. If we were to call drm_atomic_commit_put() at this point, chances are that drm_atomic_commit_default_clear() would be called and it would iterate over all those empty NULL items. However, unlike what is found for connectors, crtcs and planes, we don't test that our pointers are non-NULL before dereferencing them, leading to a NULL pointer dereference. Such callers should obviously be fixed, but there's no reason to not do such a simple check, if only to be consistent. Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://lore.kernel.org/r/20260907-drm-state-readout-v5-2-5fa1ac7a5148@kernel.org Signed-off-by: Maxime Ripard <mripard@kernel.org>
-rw-r--r--drivers/gpu/drm/drm_atomic.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 5c0f7b7024d1..0ebbe10d497a 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -353,6 +353,9 @@ void drm_atomic_commit_default_clear(struct drm_atomic_commit *state)
for (i = 0; i < state->num_private_objs; i++) {
struct drm_private_obj *obj = state->private_objs[i].ptr;
+ if (!obj)
+ continue;
+
obj->funcs->atomic_destroy_state(obj,
state->private_objs[i].state_to_destroy);
state->private_objs[i].ptr = NULL;