dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
@ 2026-09-02 12:30 Sajal Gupta
  2026-09-02 12:51 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sajal Gupta @ 2026-09-02 12:30 UTC (permalink / raw)
  To: rubenru09
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, noralf,
	dri-devel, linux-kernel, Sajal Gupta, Sashiko

The plane property loop uses req->properties[num_properties + i] as write
index while simultaneously incrementing `num_properties` inside the loop.
At iteration i, num_properties has also incremented by i, so the write
is done at `initial_num_properties + 2*i`, skipping every other index and
advancing by 2 per iteration.

With just 2 connector and 32 plane properties the last write happens at
index 64, one slot past the end of the 64-slot (indices 0–63)
allocation. A USB device can trigger OOB by advertising the maximum
number of properties.

Fix by dropping the redundant `+ i`; num_properties is already the correct
running index, as gud_connector_fill_properties() fills the preceding
slots.

Fixes: 40e1a70b4aed ("drm: Add GUD USB Display driver")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260821071812.16500-1-sajal2005gupta%40gmail.com?part=1
Signed-off-by: Sajal Gupta <sajal2005gupta@gmail.com>
---

Verified with KASAN using a raw-gadget fake GUD device reporting 2
connector properties and 32 plane properties:

  BUG: KASAN: slab-out-of-bounds in gud_plane_atomic_check+0x1352/0x1ba0
  Write of size 2 at addr ffff88800d029a9a by task temm/270

  Call Trace:
   <TASK>
   kasan_report+0xfa/0x120
   gud_plane_atomic_check+0x1352/0x1ba0
   drm_atomic_helper_check_planes+0x2f2/0x9b0
   drm_atomic_helper_check+0x72/0x140
   drm_atomic_check_only+0x127b/0x3420
   drm_atomic_commit+0x124/0x2e0
   drm_atomic_helper_set_config+0xd9/0x130
   drm_mode_setcrtc+0xcfd/0x1b20
   drm_ioctl_kernel+0x167/0x2d0
   drm_ioctl+0x53f/0xbe0
   __x64_sys_ioctl+0x137/0x1c0
   do_syscall_64+0xde/0x4b0
   </TASK>

  The buggy address is located 0 bytes to the right of
  allocated 666-byte region [ffff88800d029800, ffff88800d029a9a)


 drivers/gpu/drm/gud/gud_pipe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
index 5ef887d8485a..54adc401bc1b 100644
--- a/drivers/gpu/drm/gud/gud_pipe.c
+++ b/drivers/gpu/drm/gud/gud_pipe.c
@@ -562,8 +562,8 @@ int gud_plane_atomic_check(struct drm_plane *plane,
 			goto out;
 		}

-		req->properties[num_properties + i].prop = cpu_to_le16(prop);
-		req->properties[num_properties + i].val = cpu_to_le64(val);
+		req->properties[num_properties].prop = cpu_to_le16(prop);
+		req->properties[num_properties].val = cpu_to_le64(val);
 		num_properties++;
 	}

--
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
  2026-09-02 12:30 [PATCH] drm/gud: fix out-of-bounds write in gud_plane_atomic_check() Sajal Gupta
@ 2026-09-02 12:51 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-02 12:51 UTC (permalink / raw)
  To: Sajal Gupta; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-After-Free due to unsafe access to `connector->state` in the fallback logic without proper locking or addition to the atomic state.
- [Medium] Iterator variable `connector_state` leaks from the `for_each_new_connector_in_state` loop when no CRTC-bound connector is found, causing the wrong connector state to be used.
--

commit 0c2e0cfd22b820fc8dacf39a623bb3f5f21ff275
Author: Sajal Gupta <sajal2005gupta@gmail.com>

drm/gud: fix out-of-bounds write in gud_plane_atomic_check()

This commit fixes an out-of-bounds write in the plane property loop of
gud_plane_atomic_check(). It drops a redundant addition of the loop index
to num_properties, since num_properties is already the correct running
index.

Link: https://sashiko.dev/#/patchset/20260821071812.16500-1-sajal2005gupta%40gmail.com?part=1

> diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
> index 5ef887d8485a3..54adc401bc1ba 100644
> --- a/drivers/gpu/drm/gud/gud_pipe.c
> +++ b/drivers/gpu/drm/gud/gud_pipe.c

[ ... ]

> @@ -562,8 +562,8 @@ int gud_plane_atomic_check(struct drm_plane *plane,
>  			goto out;
>  		}
>  
> -		req->properties[num_properties + i].prop = cpu_to_le16(prop);
> -		req->properties[num_properties + i].val = cpu_to_le64(val);
> +		req->properties[num_properties].prop = cpu_to_le16(prop);
> +		req->properties[num_properties].val = cpu_to_le64(val);
>  		num_properties++;
>  	}

While reviewing this change, I noticed a couple of pre-existing issues earlier
in gud_plane_atomic_check():

drivers/gpu/drm/gud/gud_pipe.c:gud_plane_atomic_check() {
    ...
    for_each_new_connector_in_state(state, connector, connector_state, i) {
        if (connector_state->crtc)
            break;
    }

    /*
     * DRM_IOCTL_MODE_OBJ_SETPROPERTY on the rotation property will not have
     * the connector included in the state.
     */
    if (!connector_state) {

[Severity: Medium]
This is a pre-existing issue, but I noticed the iterator variable
connector_state is not cleared if the loop completes without hitting the
break statement.

If userspace submits an atomic commit updating a plane property while
simultaneously modifying a disconnected connector, the loop evaluates the
disconnected connector and finishes without breaking. This leaves
connector_state retaining the disconnected state.

Since connector_state is no longer NULL, the fallback check is skipped.
Could this cause the hardware check command GUD_REQ_SET_STATE_CHECK to
receive the ID of a disconnected connector and misconfigure the display?

        struct drm_connector_list_iter conn_iter;

        drm_connector_list_iter_begin(plane->dev, &conn_iter);
        drm_for_each_connector_iter(connector, &conn_iter) {
            if (connector->state->crtc) {
                connector_state = connector->state;
                break;
            }
        }
        drm_connector_list_iter_end(&conn_iter);
    }

[Severity: High]
This is also a pre-existing issue, but does this fallback logic risk a
use-after-free by directly accessing connector->state?

When an atomic commit updates only a plane property, the fallback logic
iterates all system connectors and directly assigns connector_state to
connector->state. Because the connector is not added to the atomic state
via drm_atomic_get_connector_state(), its lock is not held by the current
thread.

If a concurrent userspace thread issues a property update on this connector,
could it swap and free the old state while gud_connector_fill_properties()
is simultaneously reading from it?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902123254.36987-1-sajal2005gupta@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-03  7:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 12:30 [PATCH] drm/gud: fix out-of-bounds write in gud_plane_atomic_check() Sajal Gupta
2026-09-02 12:51 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox