| Message ID | 9c73eb433ce34de243d5be7a5e81e38fe26d39c5.1785158244.git.sean@mess.org (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-24775-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 ACAFD1C1F60 for <noreply@patchwork.local>; Mon, 27 Jul 2026 15:24:39 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=mess.org; dkim=pass header.d=mess.org; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-24775-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-24775-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 565E83020B7F for <noreply@patchwork.local>; Mon, 27 Jul 2026 13:20:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 692944156FB; Mon, 27 Jul 2026 13:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mess.org header.i=@mess.org header.b="jFqJZ33+"; dkim=pass (2048-bit key) header.d=mess.org header.i=@mess.org header.b="jFqJZ33+" X-Original-To: linux-sunxi@lists.linux.dev Received: from extorris.mess.org (extorris.mess.org [92.243.27.206]) (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 A3D11412BE3 for <linux-sunxi@lists.linux.dev>; Mon, 27 Jul 2026 13:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.243.27.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785158364; cv=none; b=ESxXyRHVBTUzhQfJVI4cKj0i8K3ePRMdr/JDhbMuokjldw2fiIYrEReA6F67Fig5+PFZ6nKDjceRwMK0N9mQWhVcOozxV5GADb46GTCvrmx5VDVPxmw3dHHTC0ymlLRITvHuzeSSU1hoZJVhmgG3ElBVMe74kd8ZgIKYYWtzPNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785158364; c=relaxed/simple; bh=jyAFNCAff7ONHFxb/FIrT3odoLHFfMrGUvGh9kBzBcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ah8GDfePH0kDfPUMp+y4UrEw+L22j+naZWxA0JJcacKVgn4I21Ggh0ODh+BxyFybelPTfkCBYtgLvWVfAf7gwUbpAy+eIWjDcgO6vNDqyAq8KBSvfxeKGrXYRokUDwe/Sn8c5WET7V7dQuQN25cnuJ11KFBc5uj2DPklHjiLGOg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mess.org; spf=pass smtp.mailfrom=mess.org; dkim=pass (2048-bit key) header.d=mess.org header.i=@mess.org header.b=jFqJZ33+; dkim=pass (2048-bit key) header.d=mess.org header.i=@mess.org header.b=jFqJZ33+; arc=none smtp.client-ip=92.243.27.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mess.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mess.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mess.org; s=2020; t=1785158355; bh=jyAFNCAff7ONHFxb/FIrT3odoLHFfMrGUvGh9kBzBcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jFqJZ33+EK/wtLp1/Le/Xf5wB8zK76uiViXw5cnYBcdV3uJPkK8NGBfJ3ujFQkpEf CMU6sEPzF0LQh4t7oJPMEuHhFZJmga2Vaw90ylrFY+6Z6CqkXN78TJfitNwoqcuKwY 1gq06t19XundoiqmCpalCues+vKRIjpainKF84Mxj4g9ABDRAKthOFU+Tq7XOkfx+Q fTk4vcUJRMbaoaZEY2B+UtFDnP0WARfjeDGjADp6PZYkAFLN4huiC6x8CS6tfuJ7CR LVf2S8Iapg16L1FVOM243xBrt+vCAITdUlnUe9YTeFcBYpzJNIt+tzgQEcbSdcYX1b qiCgpugUXqppw== Received: by extorris.mess.org (Postfix, from userid 1004) id 9A78842542; Mon, 27 Jul 2026 14:19:15 +0100 (BST) X-Spam-Level: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mess.org; s=2020; t=1785158355; bh=jyAFNCAff7ONHFxb/FIrT3odoLHFfMrGUvGh9kBzBcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jFqJZ33+EK/wtLp1/Le/Xf5wB8zK76uiViXw5cnYBcdV3uJPkK8NGBfJ3ujFQkpEf CMU6sEPzF0LQh4t7oJPMEuHhFZJmga2Vaw90ylrFY+6Z6CqkXN78TJfitNwoqcuKwY 1gq06t19XundoiqmCpalCues+vKRIjpainKF84Mxj4g9ABDRAKthOFU+Tq7XOkfx+Q fTk4vcUJRMbaoaZEY2B+UtFDnP0WARfjeDGjADp6PZYkAFLN4huiC6x8CS6tfuJ7CR LVf2S8Iapg16L1FVOM243xBrt+vCAITdUlnUe9YTeFcBYpzJNIt+tzgQEcbSdcYX1b qiCgpugUXqppw== Received: from maru.local (unknown [62.232.99.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by extorris.mess.org (Postfix) with ESMTPSA id BD6A74252E; Mon, 27 Jul 2026 14:19:14 +0100 (BST) From: Sean Young <sean@mess.org> To: linux-media@vger.kernel.org, Sean Young <sean@mess.org>, Mauro Carvalho Chehab <mchehab@kernel.org>, Chen-Yu Tsai <wens@kernel.org>, Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, Hans Verkuil <hverkuil+cisco@kernel.org>, Patrice Chotard <patrice.chotard@foss.st.com> Cc: stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/15] media: sunxi-cir: Ensure no more interrupts can occur before free Date: Mon, 27 Jul 2026 14:18:49 +0100 Message-ID: <9c73eb433ce34de243d5be7a5e81e38fe26d39c5.1785158244.git.sean@mess.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <cover.1785158244.git.sean@mess.org> References: <cover.1785158244.git.sean@mess.org> 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 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.84 / 15.00]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; MAILLIST(-0.15)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; R_DKIM_ALLOW(0.00)[mess.org:s=2020]; PRECEDENCE_BULK(0.00)[]; TAGGED_RCPT(0.00)[cisco]; DBL_BLOCKED_OPENRESOLVER(0.00)[mess.org:email,mess.org:dkim]; RCPT_COUNT_TWELVE(0.00)[12]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[sean@mess.org,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-24775-noreply=patchwork.local]; DKIM_TRACE(0.00)[mess.org:+]; DMARC_POLICY_ALLOW(0.00)[mess.org,none]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4]; TO_DN_SOME(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; FREEMAIL_TO(0.00)[vger.kernel.org,mess.org,kernel.org,gmail.com,sholland.org,foss.st.com]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: ACAFD1C1F60 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 |
None
|
|
Commit Message
Sean Young
July 27, 2026, 1:18 p.m. UTC
Only call rc_free_device() once the hardware has been stopped.
Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
Signed-off-by: Sean Young <sean@mess.org>
Cc: stable@vger.kernel.org
---
drivers/media/rc/sunxi-cir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch attempts to fix a use-after-free by delaying `rc_free_device()` until after `sunxi_ir_hw_exit()`. However, `sunxi_ir_hw_exit()` only disables the hardware clocks and asserts reset; it does not mask the devm-managed IRQ or wait for in-flight interrupt handlers to complete via `synchronize_irq()`. This leaves the driver vulnerable to two fatal issues: 1) If an IRQ handler is executing concurrently, disabling the APB clock while it accesses memory-mapped registers will cause a synchronous external abort (bus hang). 2) If the handler continues executing after `sunxi_ir_hw_exit()` returns, it will access `ir->rc` while it is being freed by `rc_free_device()`, resulting in a use-after-free.
- [High] The IRQ is requested via `devm_request_irq()` before the hardware clocks are initialized by `sunxi_ir_hw_init()`, risking a synchronous external abort (bus hang) on spurious or pending interrupts during probe.
- [High] The devm-managed IRQ handler can execute and access a freed RC device if `sunxi_ir_hw_init()` fails in `sunxi_ir_probe()`.
--
--- Patch [6]: [PATCH v4 06/15] media: sunxi-cir: Ensure no more interrupts can occur before free ---
commit 6e49e6c93b7dee54eb10aca37f27b9448afeb67a
Author: Sean Young <sean@mess.org>
media: sunxi-cir: Ensure no more interrupts can occur before free
Only call rc_free_device() once the hardware has been stopped.
Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
Cc: stable@vger.kernel.org
> diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
> index 28e840a7e5b8c..af1ee08ffdbec 100644
> --- a/drivers/media/rc/sunxi-cir.c
> +++ b/drivers/media/rc/sunxi-cir.c
> @@ -374,8 +374,8 @@ static void sunxi_ir_remove(struct platform_device *pdev)
> struct sunxi_ir *ir = platform_get_drvdata(pdev);
>
> rc_unregister_device(ir->rc);
> - rc_free_device(ir->rc);
> sunxi_ir_hw_exit(&pdev->dev);
> + rc_free_device(ir->rc);
[Severity: High]
This is a pre-existing issue, but does sunxi_ir_hw_exit() adequately prevent
further interrupts from executing?
sunxi_ir_hw_exit() disables clocks and asserts reset, but it doesn't appear
to mask the devm-managed IRQ or wait for in-flight handlers to finish via
synchronize_irq().
If an interrupt fires concurrently or an IRQ handler is already running:
drivers/media/rc/sunxi-cir.c:sunxi_ir_irq() {
...
status = readl(ir->base + SUNXI_IR_RXSTA_REG);
...
}
Could disabling the APB clock while this handler is accessing memory-mapped
registers cause a synchronous external abort? Furthermore, if the handler
continues executing after sunxi_ir_hw_exit() returns, could it access the
freed ir->rc device pointer?
> }
Looking at the probe function in the same file:
drivers/media/rc/sunxi-cir.c:sunxi_ir_probe() {
...
ret = devm_request_irq(dev, ir->irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir);
if (ret) {
dev_err(dev, "failed request irq\n");
goto exit_unregister_dev;
}
ret = sunxi_ir_hw_init(dev);
if (ret)
goto exit_unregister_dev;
...
exit_unregister_dev:
rc_unregister_device(ir->rc);
exit_free_dev:
rc_free_device(ir->rc);
}
[Severity: High]
This is a pre-existing issue, but is it safe to request the IRQ before the
hardware clocks are initialized?
If a pending interrupt from the bootloader or a spurious IRQ triggers
sunxi_ir_irq() before sunxi_ir_hw_init() enables the clock, could this lead
to a synchronous external abort when the handler reads ir->base?
[Severity: High]
This is another pre-existing issue, but does the error path for a failed
sunxi_ir_hw_init() leave the devm-managed IRQ active until the probe function
returns?
If an interrupt fires during this window, could the handler dereference
ir->rc after it has been freed by rc_free_device() at the exit_free_dev
label?
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c index 28e840a7e5b8..af1ee08ffdbe 100644 --- a/drivers/media/rc/sunxi-cir.c +++ b/drivers/media/rc/sunxi-cir.c @@ -374,8 +374,8 @@ static void sunxi_ir_remove(struct platform_device *pdev) struct sunxi_ir *ir = platform_get_drvdata(pdev); rc_unregister_device(ir->rc); - rc_free_device(ir->rc); sunxi_ir_hw_exit(&pdev->dev); + rc_free_device(ir->rc); } static void sunxi_ir_shutdown(struct platform_device *pdev)