mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Yaohan Li <shunsheng1218@gmail.com>
Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] firewire: keep the request alive while the event is queued
Date: Sun, 22 Nov 2026 21:33:58 +0900	[thread overview]
Message-ID: <20261122123358.GA500423@sakamocchi.jp> (raw)
In-Reply-To: <20261119083205.3437874-1-shunsheng1218@gmail.com>

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@gmail.com>
> 
> ---
> (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

      reply	other threads:[~2026-11-22 12:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  8:32 Yaohan Li
2026-11-22 12:33 ` Takashi Sakamoto [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122123358.GA500423@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=shunsheng1218@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®