* [PATCH v2 00/11] Fix leaks in rc core
@ 2026-07-13 21:30 Sean Young
2026-07-13 21:30 ` [PATCH v2 01/11] media: streamzap: Add missing rc_unregister_device() Sean Young
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media; +Cc: Sean Young
Changes since v1:
- sashiko had many good review comments
- Added fix rc: Use after free in ir_raw_event_handle()
- Added fix meson-ir-tx: Ensure probe error is propagated
- Added fix redrat3: Ensure all urbs are suspended
- Added fix media: redrat3: Error path leaves device in transmitting state
- streamzap fix was incorrect
- Other minor fixes
Sean Young (11):
media: streamzap: Add missing rc_unregister_device()
media: redrat3: Ensure rc device is freed if enable_detector() fails
media: redrat3: Ensure we don't read beyond the end of the packet
media: redrat3: Ensure all urbs are suspended
media: redrat3: Error path leaves device in transmitting state
media: sunxi-cir: Ensure no more interrupts can occur before free
media: meson-ir-tx: Ensure clock is disabled on unbind
media: meson-ir-tx: Ensure rc_free_device() is called on unbind
media: meson-ir-tx: Ensure probe error is propagated
media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled
media: rc: Use after free in ir_raw_event_handle()
drivers/media/rc/ir-hix5hd2.c | 5 +++--
drivers/media/rc/meson-ir-tx.c | 14 ++++++--------
drivers/media/rc/rc-ir-raw.c | 8 ++++++--
drivers/media/rc/redrat3.c | 28 ++++++++++++++++++++++++----
drivers/media/rc/streamzap.c | 1 +
drivers/media/rc/sunxi-cir.c | 2 +-
6 files changed, 41 insertions(+), 17 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 01/11] media: streamzap: Add missing rc_unregister_device()
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
@ 2026-07-13 21:30 ` Sean Young
2026-07-13 21:30 ` [PATCH v2 02/11] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Oliver Neukum,
Hans Verkuil
Cc: linux-kernel
If usb_submit_urb() fails during probe, then the error path is missing a
call to rc_unregister_device(), which will leak various things like the
input device.
Fixes: 42844992664f ("media: rc: streamzap: Error handling in probe")
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/streamzap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/rc/streamzap.c b/drivers/media/rc/streamzap.c
index 307985d74fe8..41195ad82734 100644
--- a/drivers/media/rc/streamzap.c
+++ b/drivers/media/rc/streamzap.c
@@ -365,6 +365,7 @@ static int streamzap_probe(struct usb_interface *intf,
return 0;
rc_submit_fail:
+ rc_unregister_device(sz->rdev);
rc_free_device(sz->rdev);
usb_set_intfdata(intf, NULL);
rc_dev_fail:
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 02/11] media: redrat3: Ensure rc device is freed if enable_detector() fails
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
2026-07-13 21:30 ` [PATCH v2 01/11] media: streamzap: Add missing rc_unregister_device() Sean Young
@ 2026-07-13 21:30 ` Sean Young
2026-07-13 21:30 ` [PATCH v2 03/11] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Jarod Wilson; +Cc: linux-kernel
This particular error path does not free the rc device at all, with
its priv pointer still pointing at freed memory.
Fixes: 2154be651b90 ("[media] redrat3: new rc-core IR transceiver device driver")
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/redrat3.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 3f828a564e19..391d01143491 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -1111,17 +1111,20 @@ static int redrat3_dev_probe(struct usb_interface *intf,
/* might be all we need to do? */
retval = redrat3_enable_detector(rr3);
if (retval < 0)
- goto led_free;
+ goto rc_free;
/* we can register the device now, as it is ready */
usb_set_intfdata(intf, rr3);
return 0;
+rc_free:
+ rc_unregister_device(rr3->rc);
led_free:
led_classdev_unregister(&rr3->led);
redrat_free:
redrat3_delete(rr3, rr3->udev);
+ rc_free_device(rr3->rc);
no_endpoints:
return retval;
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 03/11] media: redrat3: Ensure we don't read beyond the end of the packet
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
2026-07-13 21:30 ` [PATCH v2 01/11] media: streamzap: Add missing rc_unregister_device() Sean Young
2026-07-13 21:30 ` [PATCH v2 02/11] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
@ 2026-07-13 21:30 ` Sean Young
2026-07-13 21:30 ` [PATCH v2 04/11] media: redrat3: Ensure all urbs are suspended Sean Young
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Jarod Wilson; +Cc: linux-kernel
The length and offset is provided by the usb device, so it should be
validated.
Fixes: 2154be651b90 ("[media] redrat3: new rc-core IR transceiver device driver")
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/redrat3.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 391d01143491..44678ee322c2 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -358,8 +358,24 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
/* process each rr3 encoded byte into an int */
sig_size = be16_to_cpu(rr3->irdata.sig_size);
+
+ /*
+ * Note we are not checking if we are reading beyond the end of the
+ * packet which was sent, and reading stale data. If the device
+ * sends a packet which is short then we get garbage IR, but no
+ * out of bounds read.
+ */
+ if (sig_size > RR3_MAX_SIG_SIZE) {
+ dev_err(dev, "length %u is incorrect\n", sig_size);
+ return;
+ }
+
for (i = 0; i < sig_size; i++) {
offset = rr3->irdata.sigdata[i];
+ if (offset >= RR3_DRIVER_MAXLENS) {
+ dev_err(dev, "offset %u is incorrect\n", offset);
+ return;
+ }
val = get_unaligned_be16(&rr3->irdata.lens[offset]);
/* we should always get pulse/space/pulse/space samples */
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 04/11] media: redrat3: Ensure all urbs are suspended
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (2 preceding siblings ...)
2026-07-13 21:30 ` [PATCH v2 03/11] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
@ 2026-07-13 21:30 ` Sean Young
2026-07-13 21:30 ` [PATCH v2 05/11] media: redrat3: Error path leaves device in transmitting state Sean Young
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab; +Cc: linux-kernel
Ensure that the learn urb is stopped before suspend.
Fixes: c49fcdde38cb ("[media] redrat3: enable carrier reports using wideband receiver")
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/redrat3.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 44678ee322c2..468907d6c3a8 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -1167,6 +1167,7 @@ static int redrat3_dev_suspend(struct usb_interface *intf, pm_message_t message)
usb_kill_urb(rr3->narrow_urb);
usb_kill_urb(rr3->wide_urb);
usb_kill_urb(rr3->flash_urb);
+ usb_kill_urb(rr3->learn_urb);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 05/11] media: redrat3: Error path leaves device in transmitting state
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (3 preceding siblings ...)
2026-07-13 21:30 ` [PATCH v2 04/11] media: redrat3: Ensure all urbs are suspended Sean Young
@ 2026-07-13 21:30 ` Sean Young
2026-07-13 21:31 ` [PATCH v2 06/11] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:30 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab; +Cc: linux-kernel
If the allocation fails, transmitting is left as true and the transmitter
cannot be used any more.
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/redrat3.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 468907d6c3a8..b64c6440b062 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -781,9 +781,6 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
if (count > RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN)
return -EINVAL;
- /* rr3 will disable rc detector on transmit */
- rr3->transmitting = true;
-
sample_lens = kzalloc_objs(*sample_lens, RR3_DRIVER_MAXLENS);
if (!sample_lens)
return -ENOMEM;
@@ -794,6 +791,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
goto out;
}
+ /* rr3 will disable rc detector on transmit */
+ rr3->transmitting = true;
+
for (i = 0; i < count; i++) {
cur_sample_len = redrat3_us_to_len(txbuf[i]);
if (cur_sample_len > 0xffff) {
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 06/11] media: sunxi-cir: Ensure no more interrupts can occur before free
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (4 preceding siblings ...)
2026-07-13 21:30 ` [PATCH v2 05/11] media: redrat3: Error path leaves device in transmitting state Sean Young
@ 2026-07-13 21:31 ` Sean Young
2026-07-13 21:31 ` [PATCH v2 07/11] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:31 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Patrice Chotard, Hans Verkuil
Cc: linux-arm-kernel, linux-sunxi, linux-kernel
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>
---
drivers/media/rc/sunxi-cir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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)
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 07/11] media: meson-ir-tx: Ensure clock is disabled on unbind
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (5 preceding siblings ...)
2026-07-13 21:31 ` [PATCH v2 06/11] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
@ 2026-07-13 21:31 ` Sean Young
2026-07-13 21:31 ` [PATCH v2 08/11] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
2026-07-13 21:31 ` [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated Sean Young
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:31 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
Viktor Prutyanov
Cc: Mauro Carvalho Chehab, linux-arm-kernel, linux-amlogic,
linux-kernel
clk_prepare_enable() needs a call to clk_disable_unprepare() on
driver unbind. Make it devm managed.
Fixes: 49be1c78d575 ("media: rc: introduce Meson IR TX driver")
Signed-off-by: Sean Young <sean@mess.org>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
drivers/media/rc/meson-ir-tx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c
index fded2c256f2a..e7bb107e6a84 100644
--- a/drivers/media/rc/meson-ir-tx.c
+++ b/drivers/media/rc/meson-ir-tx.c
@@ -288,8 +288,8 @@ static int meson_irtx_mod_clock_probe(struct meson_irtx *ir,
if (!np)
return -ENODEV;
- clock = devm_clk_get(ir->dev, "xtal");
- if (IS_ERR(clock) || clk_prepare_enable(clock))
+ clock = devm_clk_get_enabled(ir->dev, "xtal");
+ if (IS_ERR(clock))
return -ENODEV;
*clk_nr = IRB_MOD_XTAL3_CLK;
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 08/11] media: meson-ir-tx: Ensure rc_free_device() is called on unbind
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (6 preceding siblings ...)
2026-07-13 21:31 ` [PATCH v2 07/11] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
@ 2026-07-13 21:31 ` Sean Young
2026-07-13 21:31 ` [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated Sean Young
8 siblings, 0 replies; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:31 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil,
Patrice Chotard
Cc: linux-arm-kernel, linux-amlogic, linux-kernel
Make rc_dev devm managed.
Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
Signed-off-by: Sean Young <sean@mess.org>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
drivers/media/rc/meson-ir-tx.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c
index e7bb107e6a84..abb107d19e8c 100644
--- a/drivers/media/rc/meson-ir-tx.c
+++ b/drivers/media/rc/meson-ir-tx.c
@@ -345,7 +345,7 @@ static int meson_irtx_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "irq request failed\n");
- rc = rc_allocate_device(RC_DRIVER_IR_RAW_TX);
+ rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW_TX);
if (!rc)
return -ENOMEM;
@@ -358,10 +358,8 @@ static int meson_irtx_probe(struct platform_device *pdev)
rc->s_tx_duty_cycle = meson_irtx_set_duty_cycle;
ret = devm_rc_register_device(dev, rc);
- if (ret < 0) {
- rc_free_device(rc);
+ if (ret < 0)
return dev_err_probe(dev, ret, "rc_dev registration failed\n");
- }
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
` (7 preceding siblings ...)
2026-07-13 21:31 ` [PATCH v2 08/11] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
@ 2026-07-13 21:31 ` Sean Young
2026-07-14 5:12 ` Martin Blumenstingl
8 siblings, 1 reply; 11+ messages in thread
From: Sean Young @ 2026-07-13 21:31 UTC (permalink / raw)
To: linux-media, Sean Young, Mauro Carvalho Chehab, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
Viktor Prutyanov
Cc: Mauro Carvalho Chehab, linux-arm-kernel, linux-amlogic,
linux-kernel
devm_clk_get_enabled() may return -EPROBE_DEFER which needs to be
propagated else the probe will not be deferred, it will fail instead.
Fixes: 49be1c78d575 ("media: rc: introduce Meson IR TX driver")
Signed-off-by: Sean Young <sean@mess.org>
---
drivers/media/rc/meson-ir-tx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c
index abb107d19e8c..174d5135e1bb 100644
--- a/drivers/media/rc/meson-ir-tx.c
+++ b/drivers/media/rc/meson-ir-tx.c
@@ -290,7 +290,7 @@ static int meson_irtx_mod_clock_probe(struct meson_irtx *ir,
clock = devm_clk_get_enabled(ir->dev, "xtal");
if (IS_ERR(clock))
- return -ENODEV;
+ return PTR_ERR(clock);
*clk_nr = IRB_MOD_XTAL3_CLK;
ir->clk_rate = clk_get_rate(clock) / 3;
@@ -324,7 +324,7 @@ static int meson_irtx_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0);
if (irq < 0)
- return -ENODEV;
+ return irq;
ir->dev = dev;
ir->carrier = MIRTX_DEFAULT_CARRIER;
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated
2026-07-13 21:31 ` [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated Sean Young
@ 2026-07-14 5:12 ` Martin Blumenstingl
0 siblings, 0 replies; 11+ messages in thread
From: Martin Blumenstingl @ 2026-07-14 5:12 UTC (permalink / raw)
To: Sean Young
Cc: linux-media, Mauro Carvalho Chehab, Neil Armstrong, Kevin Hilman,
Jerome Brunet, Viktor Prutyanov, Mauro Carvalho Chehab,
linux-arm-kernel, linux-amlogic, linux-kernel
On Mon, Jul 13, 2026 at 11:31 PM Sean Young <sean@mess.org> wrote:
>
> devm_clk_get_enabled() may return -EPROBE_DEFER which needs to be
> propagated else the probe will not be deferred, it will fail instead.
>
> Fixes: 49be1c78d575 ("media: rc: introduce Meson IR TX driver")
> Signed-off-by: Sean Young <sean@mess.org>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Thank you for including this one!
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-07-14 5:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13 21:30 [PATCH v2 00/11] Fix leaks in rc core Sean Young
2026-07-13 21:30 ` [PATCH v2 01/11] media: streamzap: Add missing rc_unregister_device() Sean Young
2026-07-13 21:30 ` [PATCH v2 02/11] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
2026-07-13 21:30 ` [PATCH v2 03/11] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
2026-07-13 21:30 ` [PATCH v2 04/11] media: redrat3: Ensure all urbs are suspended Sean Young
2026-07-13 21:30 ` [PATCH v2 05/11] media: redrat3: Error path leaves device in transmitting state Sean Young
2026-07-13 21:31 ` [PATCH v2 06/11] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
2026-07-13 21:31 ` [PATCH v2 07/11] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
2026-07-13 21:31 ` [PATCH v2 08/11] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
2026-07-13 21:31 ` [PATCH v2 09/11] media: meson-ir-tx: Ensure probe error is propagated Sean Young
2026-07-14 5:12 ` Martin Blumenstingl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox