Re: [PATCH v2] thermal/drivers/rcar_thermal: disable the work before masking the interrupt
From: Niklas Söderlund
Date: Sun Nov 22 2026 - 09:09:16 EST
Hi Yaohan,
On 2026-11-20 17:43:19 +0800, Yaohan Li wrote:
> Hi Niklas,
>
> Thanks for offering to test this on Koelsch.
No worries. I was mostly offering to run a test, not create one ;-)
I know how to try and trigger it, my point was this is a very hard issue
to trigger and was wondering if you had anything already which do so.
Ideally I would like run a test see the old code fail and then apply
this fix and see it solved.
Triggering an interrupt by modifying the temperature, be it with cpuburn
or a hairdryer at the exact same time that the driver is being unbound
seems extremely tricky too me. Even if the bind/unbind operation is put
in a loop. And I though since you where fix lot of drivers you had
something from a hardware setup you had access too.
>
> I went through the Gen2 thermal driver again. One detail worth clarifying is
> that rcar_thermal_update_temp() programs INTCTRL from the current ctemp and
> ctemp - 1, not from the critical trip in the device tree.
>
> Gen2 reports the temperature in 5 C code steps. That does not mean the
> physical temperature has to move a full 5 C to trigger an interrupt: it
> depends on how close the sensor sits to a comparator boundary when the window
> is programmed.
>
> The handler masks the sensor source and schedules the work 300 ms later; the
> work updates the comparator and re-enables the interrupt. So this path
> normally limits how often successive sensor events are handled. Reading the
> zone also goes through the same function and reprograms the comparator, so I
> would avoid tight temperature polling while trying to observe interrupts.
>
> For the first step I would check the e61f0000 entry in /proc/interrupts. The
> line is shared and the handler reports it as handled either way, so the
> counter alone does not prove a thermal event. The driver has a dev_dbg() in
> rcar_thermal_had_changed() that prints rising/falling, so
>
> echo 'file rcar_thermal.c +p' > /proc/dynamic_debug/control
>
> should show whether it really saw an unmasked status change. That needs a
> kernel with dynamic debug enabled; if the file is not there but debugfs is
> mounted, the same control file is at
> /sys/kernel/debug/dynamic_debug/control.
>
> If real sensor interrupts show up during a controlled temperature change,
> then a small number of bind/unbind cycles comparing the original and the
> patched kernel would be the next step. I would not keep a sustained CPU load
> running while the driver is unbound: with it unbound there is no thermal
> monitoring from this driver, and the trip is only a shutdown.
>
> There is also a condition that may be easier to observe than the UAF: in the
> original code a work that is already running re-enables the source after
> ->remove() has masked it, because cancel_delayed_work_sync() waits for it.
> A test-only trace of the mask and enable in _rcar_thermal_irq_ctrl() would
> show that ordering:
>
> original: remove: mask / work: enable / remove: done
> patched: work: done / remove: mask / remove: done
>
> If the natural race turns out to be too rare, I can prepare a separate
> debug-only instrumentation patch to make the interleaving easier to see.
>
> Thanks again for offering the hardware,
> Yaohan
--
Kind Regards,
Niklas Söderlund