| Message ID | 20260717-drm_refcount_wiring-v3-1-023900c32e01@redhat.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-24484-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 9FF801C2B6A for <noreply@patchwork.local>; Fri, 17 Jul 2026 16:03:41 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=redhat.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-24484-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-24484-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 7BE0F3000580 for <noreply@patchwork.local>; Fri, 17 Jul 2026 14:03:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FFE23DDAEC; Fri, 17 Jul 2026 14:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tp1Ny1sh" X-Original-To: linux-sunxi@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0210642902C for <linux-sunxi@lists.linux.dev>; Fri, 17 Jul 2026 14:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784297000; cv=none; b=VX9VwlGMh4kKJQ29z4nx4q2iqgcyOSy+BLVWyfV/eh6kD05+Er7fo6cFEdQ7AX/vgvamKMKg1w2rzaW+F+F0rgOBc50SmPaQ3bJixsp8Q0pwv29P6l03UYKk+V0EMcG0hoUnWLXCtT4Jkxo3ap+jDpNhPxmKw97w0N93kSF3yl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784297000; c=relaxed/simple; bh=FTIUpYJulTDPMntpPJg3cHAwQl8IpGYir+ZH1v5UeXQ=; h=From:Date:Subject:MIME-Version:Message-Id:References:In-Reply-To: To:Cc:Content-Type; b=PDIB1MhxWYOc4prLJrB+4DOuMcZCTb8/BEjnT3u5sXTJKoNXTXWd4rRKzwI29eJvbjpJB4khW3KA2620n7p89mSLF+LlIKRuDGtx2KVuEbAT2QfTywvcOgocWA9ln80xabDMw/y40XcDp4/M0dvWUe4WCo5ugteSQFXFb87+ozs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tp1Ny1sh; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784296988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGJka35hl1u+NTZhYLLi9zxEwwQ2DlQIwAaKGDObA0o=; b=Tp1Ny1shhyRLAmBWt0fPAJiWkBvxTPbYEf5Bq5XJFtnrrAE+KtK872rBrQmPz+PPa6UGv9 J8/d2i4neIXX5DoaDUnkYqTn3RVL1jHIvO6Fzt9mMlKF5tt8zbCPO/z98AeKQNzqUxrxvI G6XJuXeQC8xX+yV16FnQhlRmcFUvQP8= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-xZKcB7tRNWWXh1oZfo_uWA-1; Fri, 17 Jul 2026 10:03:04 -0400 X-MC-Unique: xZKcB7tRNWWXh1oZfo_uWA-1 X-Mimecast-MFC-AGG-ID: xZKcB7tRNWWXh1oZfo_uWA_1784296976 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0FDE8180074B; Fri, 17 Jul 2026 14:02:55 +0000 (UTC) Received: from [192.168.1.153] (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 39396180025B; Fri, 17 Jul 2026 14:02:38 +0000 (UTC) From: Albert Esteve <aesteve@redhat.com> Date: Fri, 17 Jul 2026 16:02:04 +0200 Subject: [PATCH v3 1/4] drm/panel: have drm_panel_add/remove manage a list reference Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 Message-Id: <20260717-drm_refcount_wiring-v3-1-023900c32e01@redhat.com> References: <20260717-drm_refcount_wiring-v3-0-023900c32e01@redhat.com> In-Reply-To: <20260717-drm_refcount_wiring-v3-0-023900c32e01@redhat.com> To: Neil Armstrong <neil.armstrong@linaro.org>, Jessica Zhang <jesszhan0024@gmail.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>, Andrzej Hajda <andrzej.hajda@intel.com>, Robert Foss <rfoss@kernel.org>, Laurent Pinchart <Laurent.pinchart@ideasonboard.com>, Jonas Karlman <jonas@kwiboo.se>, Jernej Skrabec <jernej.skrabec@gmail.com>, Luca Ceresoli <luca.ceresoli@bootlin.com>, Inki Dae <inki.dae@samsung.com>, Jagan Teki <jagan@amarulasolutions.com>, Marek Szyprowski <m.szyprowski@samsung.com>, Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>, Lucas Stach <l.stach@pengutronix.de>, Frank Li <Frank.Li@nxp.com>, Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix Kernel Team <kernel@pengutronix.de>, Fabio Estevam <festevam@gmail.com>, Paul Cercueil <paul@crapouillou.net>, Linus Walleij <linusw@kernel.org>, Marek Vasut <marex@denx.de>, Stefan Agner <stefan@agner.ch>, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>, Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>, Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>, Geert Uytterhoeven <geert+renesas@glider.be>, Magnus Damm <magnus.damm@gmail.com>, Biju Das <biju.das.jz@bp.renesas.com>, Sandy Huang <hjc@rock-chips.com>, =?utf-8?q?Heiko_St=C3=BCbner?= <heiko@sntech.de>, Andy Yan <andy.yan@rock-chips.com>, Yannick Fertre <yannick.fertre@foss.st.com>, Raphael Gallais-Pou <raphael.gallais-pou@foss.st.com>, Philippe Cornu <philippe.cornu@foss.st.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, Chen-Yu Tsai <wens@kernel.org>, Samuel Holland <samuel@sholland.org>, Jyri Sarha <jyri.sarha@iki.fi>, Jingoo Han <jingoohan1@gmail.com>, Seung-Woo Kim <sw0312.kim@samsung.com>, Kyungmin Park <kyungmin.park@samsung.com>, Krzysztof Kozlowski <krzk@kernel.org>, Peter Griffin <peter.griffin@linaro.org>, Alim Akhtar <alim.akhtar@samsung.com>, Alison Wang <alison.wang@nxp.com>, Paul Kocialkowski <paulk@sys-base.io>, Alain Volmat <alain.volmat@foss.st.com>, Raphael Gallais-Pou <rgallaispou@gmail.com>, Thierry Reding <thierry.reding@kernel.org>, Mikko Perttunen <mperttunen@nvidia.com>, Jonathan Hunter <jonathanh@nvidia.com> Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Albert Esteve <aesteve@redhat.com> X-Developer-Signature: v=1; a=ed25519-sha256; t=1784296938; l=1577; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=FTIUpYJulTDPMntpPJg3cHAwQl8IpGYir+ZH1v5UeXQ=; b=YrbusurGGSB7YvjF6ZccKN+vcKVUHQpfLac942+Cranf6atmGaR9SI9po6YBiflKgqH3V3Uoc fE7eQSMY2CcDc+mWaONJx9YbrBOGvZ4cSQGsIw9XOJoVNKgKBXhpN1g X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -B74fcN81Ou7cIBVg-pRgtSEIitygmU53z815yId_gI_1784296976 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
drm/panel: refcounting panel lookups and references
|
|
Commit Message
Albert Esteve
July 17, 2026, 2:02 p.m. UTC
The global panel_list holds raw pointers to drm_panel objects. Nothing prevents a panel from being freed while it is still linked in the list: if a driver's probe calls drm_panel_add() and then fails at a later step, panel->list remains in panel_list. Any subsequent call to of_drm_find_panel() that iterates the list will dereference freed memory. Have drm_panel_add() acquire a reference via drm_panel_get() before inserting the panel into the list, and have drm_panel_remove() drop it via drm_panel_put() after removing the panel from the list. The global registry now holds a counted reference for as long as the panel is listed, ensuring the object outlives any concurrent lookup. Reviewed-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Albert Esteve <aesteve@redhat.com> --- drivers/gpu/drm/drm_panel.c | 2 ++ 1 file changed, 2 insertions(+)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: New issues: - [High] Modifying drm_panel_add() to take a reference replaces a list-iteration crash with a memory leak and a devres Use-After-Free for drivers that fail to call drm_panel_remove(). Pre-existing issues: - [High] Lookup functions return raw pointers without acquiring references, failing to protect the caller from concurrent panel removal. - [High] Use-After-Free in the drm_panel_follower API when a panel is unbound. -- --- Patch [1]: [PATCH v3 1/4] drm/panel: have drm_panel_add/remove manage a list reference --- commit 2e9c2d76403b7b7e3caee78c96bffbb1f61d8df7 Author: Albert Esteve <aesteve@redhat.com> drm/panel: have drm_panel_add/remove manage a list reference The commit adds a reference acquisition to drm_panel_add() and a release to drm_panel_remove() to prevent the panel from being freed while still linked in panel_list. The global registry now holds a counted reference for as long as the panel is listed. > diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c > index 2c5649e433dfb..545fe93dc28fe 100644 > --- a/drivers/gpu/drm/drm_panel.c > +++ b/drivers/gpu/drm/drm_panel.c > @@ -81,6 +81,7 @@ static void drm_panel_init(struct drm_panel *panel, struct device *dev, > */ > void drm_panel_add(struct drm_panel *panel) > { > + drm_panel_get(panel); [Severity: High] Does taking a reference here replace a list-iteration crash with a memory leak and a devres use-after-free for drivers that fail to call drm_panel_remove()? If a driver calls drm_panel_add() but fails to call drm_panel_remove() on unbind, the new drm_panel_get() reference prevents the struct drm_panel from being freed, leaving it in panel_list. However, the driver's devres teardown still executes, freeing all underlying hardware resources like clocks, regulators, and GPIOs. If another driver later discovers this 'zombie' panel via of_drm_find_panel() and invokes its callbacks, will the panel driver access freed devres resources, causing a use-after-free or hardware lockup? > mutex_lock(&panel_lock); > list_add_tail(&panel->list, &panel_list); > mutex_unlock(&panel_lock); > } This isn't a bug introduced by this patch, but lookup functions return raw pointers without acquiring references, failing to protect the caller from concurrent panel removal: drivers/gpu/drm/drm_panel.c:of_drm_find_panel() { ... list_for_each_entry(panel, &panel_list, list) { if (panel->dev->of_node == np) { mutex_unlock(&panel_lock); return panel; } } ... } [Severity: High] While the commit message claims holding a reference in the registry ensures the object outlives concurrent lookups, does this only protect the list iteration? Once the mutex is unlocked, if a concurrent thread executes drm_panel_remove() (e.g. due to driver unbind), could it drop the registry's reference and potentially free the panel memory while the caller is actively using the unprotected pointer? This is also a pre-existing issue, but there appears to be a use-after-free in the follower API when a panel is unbound: drivers/gpu/drm/drm_panel.c:drm_panel_add_follower() { ... panel = find_panel_by_dev(follower_dev); if (IS_ERR(panel)) return PTR_ERR(panel); get_device(panel->dev); follower->panel = panel; mutex_lock(&panel->follower_lock); ... } [Severity: High] Does acquiring a reference to the panel's underlying device via get_device(panel->dev) fail to keep the devres-allocated struct drm_panel alive? Because the panel is allocated via devm_drm_panel_alloc(), its memory is tied to the driver's devres lifecycle, not the struct device refcount. If the panel driver unbinds, devres frees the struct drm_panel memory regardless of the device refcount, leaving the follower driver with a dangling follower->panel pointer. When the follower unbinds, it calls drm_panel_remove_follower(): drivers/gpu/drm/drm_panel.c:drm_panel_remove_follower() { struct drm_panel *panel = follower->panel; int ret; mutex_lock(&panel->follower_lock); ... } Won't attempting to lock the freed memory (mutex_lock(&panel->follower_lock)) cause a direct use-after-free?
On Fri, 17 Jul 2026 16:02:04 +0200, Albert Esteve <aesteve@redhat.com> wrote: > The global panel_list holds raw pointers to drm_panel objects. > Nothing prevents a panel from being freed while it is still linked > in the list: if a driver's probe calls drm_panel_add() and then > fails at a later step, panel->list remains in panel_list. Any > subsequent call to of_drm_find_panel() that iterates the list will > dereference freed memory. > > [...] Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 2c5649e433dfb..545fe93dc28fe 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -81,6 +81,7 @@ static void drm_panel_init(struct drm_panel *panel, struct device *dev, */ void drm_panel_add(struct drm_panel *panel) { + drm_panel_get(panel); mutex_lock(&panel_lock); list_add_tail(&panel->list, &panel_list); mutex_unlock(&panel_lock); @@ -98,6 +99,7 @@ void drm_panel_remove(struct drm_panel *panel) mutex_lock(&panel_lock); list_del_init(&panel->list); mutex_unlock(&panel_lock); + drm_panel_put(panel); } EXPORT_SYMBOL(drm_panel_remove);