Re: [RFC PATCH] firewire: keep the request alive while the event is queued
From: Takashi Sakamoto
Date: Sun Nov 22 2026 - 07:34:08 EST
Hi,
Thanks for the patch. However, I'm not convinced that I understand what
problem it is intended to address.
On Thu, Nov 19, 2026 at 04:32:05PM +0800, Yaohan Li wrote:
> handle_request() builds an event whose payload points into the
> fw_request that carries the packet. The reference that keeps that
> request alive belongs to the client resource, which can be released
> from another thread with FW_CDEV_IOC_SEND_RESPONSE as soon as the event
> header, including the handle, has been copied to userspace.
>
> dequeue_event() copies the header and the payload with two separate
> copy_to_user() calls, so the request can be freed between them and the
> payload copy then reads freed memory. The same happens for an event
> that is still on the client list when the request is released.
>
> Let the event hold its own reference to the request and release it in
> the event destructor, which the three paths that free an event now use.
> The other event types are allocated with kzalloc_obj() so that the new
> release hook is NULL for them.
>
> Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>
>
> ---
> (snip)
> ---
> drivers/firewire/core-cdev.c | 44 ++++++++++++++++++++++++++++--------
> 1 file changed, 35 insertions(+), 9 deletions(-)
In the UAPI design of this subsystem, FW_CDEV_IOC_SEND_RESPONSE works
correctly as long as its argument, struct fw_cdev_send_response.handle,
contains the correct handle for the target client resource.
The client resource is allocated in handle_request(), which queues a
struct fw_cdev_event_request{,2,3} event containing the handle. Once a
userspace application retrieves this event through read(2), it can proceed
to issue the FW_CDEV_IOC_SEND_RESPONSE ioctl(2).
At first glance, I see little opportunity for a well-behaved application
to issue FW_CDEV_IOC_SEND_RESPONSE between the two copy_to_user() calls.
However, I can imagine two ways to trigger this situation:
* Busy-polling the memory region used by read(2) and immediately issuing the
ioctl when the event data becomes visible, before the second
copy_to_user() is executed.
* Repeatedly issuing FW_CDEV_IOC_SEND_RESPONSE speculatively with
arbitrary handle values.
In both cases, an address handler must be allocated in advance, and
another node (or application) on the IEEE 1394 bus must send an
asynchronous request to that address region.
Is the patch intended to address this scenario?
Thanks
Takashi Sakamoto