All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v6 08/28] drm/atomic_sro: Add atomic state readout infrastructure
Date: Thu, 15 Oct 2026 15:52:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-173109@kernel.org> (raw)
In-Reply-To: <20261015-drm-state-readout-v6-8-6cc02cd10998@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] drm: NULL pointer dereference in SRO readout and compare hooks
- [High] drm: Buffer overflow in atomic SRO state due to dynamic connector counts
--

commit 419b43474568c97f2e2b083e992fc05ff840db52
Author: Maxime Ripard <mripard@kernel.org>

drm/atomic_sro: Add atomic state readout infrastructure

This patch introduces the atomic state readout (SRO) infrastructure by
adding readout hooks to KMS object vtables and providing top-level entry
points for hardware state readout at initialization.

> diff --git a/drivers/gpu/drm/drm_atomic_sro.c b/drivers/gpu/drm/drm_atomic_sro.c
> index 1551f6de6c89a..6921af73eb697 100644
> --- a/drivers/gpu/drm/drm_atomic_sro.c
> +++ b/drivers/gpu/drm/drm_atomic_sro.c
[ ... ]
> @@ -25,6 +26,59 @@ module_param_unsafe(atomic_readout, uint, 0400);
>  MODULE_PARM_DESC(atomic_readout,
>  		 "Enable Hardware State Readout (0 = disabled, 1 = enabled, 2 = ignore missing compares, 3 = ignore missing readouts and compares, default = 1)");
>  
> +static bool drm_atomic_sro_can_readout(struct drm_device *dev)
> +{
> +	struct drm_crtc *crtc;
> +	struct drm_plane *plane;
> +	struct drm_connector *connector;
> +	struct drm_private_obj *privobj;
> +	struct drm_connector_list_iter conn_iter;
> +
> +	if (atomic_readout == DRM_ATOMIC_READOUT_SKIP_MISSING_READOUT)
> +		return true;

[Severity: Critical]
If atomic_readout is set to DRM_ATOMIC_READOUT_SKIP_MISSING_READOUT (3), this
bypasses driver capability checks and returns true. Can this cause a NULL
pointer dereference?

Looking at drm_atomic_sro_readout_and_compare() and
drm_atomic_helper_sro_readout_state(), they unconditionally dereference
dev->mode_config.helper_private (as funcs) and call
funcs->atomic_sro_build_state(dev):

    const struct drm_mode_config_helper_funcs *funcs =
        dev->mode_config.helper_private;
    ...
    readout_state = funcs->atomic_sro_build_state(dev);

Since most existing atomic drivers do not implement SRO and leave
atomic_sro_build_state NULL (or lack helper_private entirely), wouldn't
bypassing this capability check cause an immediate NULL pointer dereference on
any modeset or blocking commit for those drivers?

Also, doesn't drm_atomic_helper_commit_hw_done() unconditionally call
drm_atomic_sro_readout_and_compare() for all blocking commits across all
atomic drivers, triggering this crash even without the module parameter?

    if (!nonblock)
        drm_atomic_sro_readout_and_compare(state);

Looking at the state allocation in drm_atomic_sro_state_init():

    state->connectors = kzalloc_objs(*state->connectors,
                                     dev->mode_config.num_connector);

[Severity: High]
Can this array overflow when DP MST connectors are dynamically added?

Since MST connectors can be added or removed dynamically, a connector's
IDA-allocated index (conn->index) can exceed the originally allocated
dev->mode_config.num_connector count.

Later in drm_atomic_sro_set_connector_state(), the code writes to this array
without a bounds check or dynamic reallocation:

    unsigned int index = drm_connector_index(conn);
    drm_connector_get(conn);
    state->connectors[index].ptr = conn;
    state->connectors[index].state = conn_state;

Does this lead to an out-of-bounds write?

Additionally, drm_atomic_sro_state_free() iterates using the live
dev->mode_config.num_connector value instead of the allocated capacity:

    for (i = 0; i < state->dev->mode_config.num_connector; i++) {
        struct drm_connector *conn = state->connectors[i].ptr;

If the number of connectors increased or decreased since allocation, could this
lead to an out-of-bounds read or a memory leak respectively?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-drm-state-readout-v6-0-6cc02cd10998@kernel.org?part=8

  reply	other threads:[~2026-10-15 15:52 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 15:08 [PATCH v6 00/28] drm: Implement state readout support Maxime Ripard
2026-10-15 15:08 ` [PATCH v6 01/28] drm/atomic: Fix private obj error handling Maxime Ripard
2026-10-15 15:23   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 02/28] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-10-15 15:23   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 03/28] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-10-15 15:34   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 04/28] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-10-15 15:28   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 05/28] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-10-15 15:33   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 06/28] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-10-15 15:41   ` sashiko-bot
2026-10-15 15:08 ` [PATCH v6 07/28] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-10-15 15:46   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 08/28] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-10-15 15:52   ` sashiko-bot [this message]
2026-10-15 15:09 ` [PATCH v6 09/28] drm/atomic_sro: Add function to install state into drm objects Maxime Ripard
2026-10-15 15:56   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 10/28] drm/atomic_sro: Create documentation Maxime Ripard
2026-10-15 15:59   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 11/28] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-10-15 16:05   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 12/28] drm/mode-config: Read out hardware state in drm_mode_config_create_state Maxime Ripard
2026-10-15 16:14   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 13/28] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-10-15 16:21   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 14/28] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-10-15 15:09 ` [PATCH v6 15/28] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-10-15 15:09 ` [PATCH v6 16/28] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-10-15 16:31   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 17/28] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-10-15 16:39   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 18/28] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-10-15 16:50   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 19/28] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-10-15 16:53   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 20/28] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-10-15 15:09 ` [PATCH v6 21/28] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-10-15 16:59   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 22/28] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-10-15 16:59   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 23/28] drm/tidss: crtc: Add atomic_print_state implementation Maxime Ripard
2026-10-15 15:09 ` [PATCH v6 24/28] drm/tidss: dispc: Improve mode checking logs Maxime Ripard
2026-10-15 17:02   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 25/28] drm/tidss: Implement hw_reset Maxime Ripard
2026-10-15 17:09   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 26/28] drm/tidss: Implement readout support Maxime Ripard
2026-10-15 17:13   ` sashiko-bot
2026-10-15 15:09 ` [PATCH v6 27/28] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-10-15 15:09 ` [PATCH v6 28/28] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-10-15 17:20   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-173109@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mripard@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.