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: Mon, 23 Nov 2026 18:49:49 +0900 [thread overview]
Message-ID: <20261123094949.GA545623@sakamocchi.jp> (raw)
In-Reply-To: <179540050657.417371.5230551399496711422@gmail.com>
Hi,
On Mon, Nov 23, 2026 at 10:21:46AM +0800, Yaohan Li wrote:
> 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
Indeed. The main cause of this issue is that the ownership of fw_request
is shared between the `inbound_transaction_event` and
`inbound_transaction_resource` structures. The latter owns the object and
is responsible for releasing it, while the former holds an indirect
reference to it.
```
fw_request event client_resource
========================= | ========== | ===== | ===============
fw_core_handle_request() *
|
handle_request() | * *
| <--------| |
dequeue_event() | access v |
| |
ioctl_send_response() v <--------------------v
| access (releasing in some cases)
:
:
free_response_callback() v
released (in the other cases)
```
This shared ownership works correctly as long as the lifetime of the event
is shorter than that of the client_resource. However, as reported, there
is an edge case in which this assumption does not hold.
The `fw_request` structure already supports reference counting [1], and
this patch leverages that functionality to properly manage the shared
ownership. This seems to be a reasonable solution to the issue.
However, as you may have already realized, this issue is highly unlikely
to occur and poses little risk in practice. IEEE 1394 is already a legacy
technology and is rarely supported in modern commercial enterprise
systems. It is used by relatively few users, primarily with legacy
consumer devices in desktop environments. Therefore, the potential attack
surface is quite limited.
I don't think this issue is particularly urgent, so I'd like to defer it
and focus on more critical issues for now. It might also be worth
exploring alternative approach in the meantime.
[1] 13a55d6bb15f ("firewire: core: use kref structure to maintain lifetime
of data for fw_request structure")
Thanks
Takashi Sakamoto
prev parent reply other threads:[~2026-11-23 9:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:32 Yaohan Li
2026-11-22 12:33 ` Takashi Sakamoto
2026-11-23 2:21 ` Yaohan Li
2026-11-23 9:49 ` 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=20261123094949.GA545623@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®