Re: [RFC PATCH] firewire: keep the request alive while the event is queued

From: Yaohan Li

Date: Sun Nov 22 2026 - 21:21:58 EST


Hi Takashi,

Yes. Both scenarios you describe are what this RFC is intended to cover.

The queued event has the handle in v[0] and a pointer into the fw_request
payload in v[1]. dequeue_event() removes the event from the list under
client->mutex, then drops the mutex and copies these two parts separately.
FW_CDEV_IOC_SEND_RESPONSE can release the client resource once it is given a
valid handle, without waiting for that copy to finish.

In the first scenario, another thread could observe the handle in the read
buffer and issue the ioctl before the payload copy. In the second, if a
speculative ioctl happens to hit the correct live handle, the resource may be
released even while the event is still queued. Depending on the request
state, that can release the fw_request holding the payload. An application
that waits for read(2) to return before responding would not encounter this;
both scenarios also require a registered address handler and an inbound
request on the bus.

The event currently has no request reference of its own. The RFC gives it one
with fw_request_get(), then drops it through free_event() after the event is
consumed or discarded, independently of the client resource.

For testing I compiled core-cdev.c into a controlled KASAN test with a
modeled request lifetime. Releasing the resource before dequeue_event()
produced a use-after-free in _copy_to_user with the original code, but not
with the patch. This tests the lifetime problem, not the exact two-thread
read/ioctl interleaving on hardware. I do not have a FireWire controller to
verify that timing.

Thanks,
Yaohan