From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Ziheng Wei <zihengw03@163.com>
Cc: linux1394-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] firewire: core: defer old_rom assignment until kmemdup() succeeds
Date: Thu, 3 Dec 2026 22:37:02 +0900 [thread overview]
Message-ID: <20261203133702.GA389607@sakamocchi.jp> (raw)
In-Reply-To: <20261202110250.1641372-1-zihengw03@163.com>
On Wed, Dec 02, 2026 at 07:02:50PM +0800, Ziheng Wei wrote:
> In read_config_rom(), old_rom is declared with __free(kfree) and assigned
> device->config_rom before calling kmemdup(). If kmemdup() fails and returns
> -ENOMEM during fw_device_refresh(), the cleanup handler frees old_rom while
> device->config_rom still points to the freed buffer. Subsequent config ROM
> reads (via sysfs or refresh retry) then hit a use-after-free, and
> fw_device_release() double-frees device->config_rom.
>
> Defer the assignment of old_rom until after kmemdup() succeeds, inside the
> fw_device_rwsem write lock where device->config_rom is replaced.
>
> Found by LLM-assisted static analysis. Compile-tested on x86_64.
>
> Fixes: b330f98ff238 ("firewire: core: use cleanup function to release cached configuration ROM")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ziheng Wei <zihengw03@163.com>
> ---
> drivers/firewire/core-device.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Good catch. Applied to for-linus branch.
> diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
> index a68100d3d..130c15b07 100644
> --- a/drivers/firewire/core-device.c
> +++ b/drivers/firewire/core-device.c
> @@ -797,12 +797,12 @@ static int read_config_rom(struct fw_device *device, int generation)
>
> device->max_speed = speed;
>
> - old_rom = device->config_rom;
> new_rom = kmemdup(rom, length * 4, GFP_KERNEL);
> if (new_rom == NULL)
> return -ENOMEM;
>
> scoped_guard(rwsem_write, &fw_device_rwsem) {
> + old_rom = device->config_rom;
> device->config_rom = new_rom;
> device->config_rom_length = length;
> }
>
> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
> --
> 2.43.0
Thanks
Takashi Sakamoto
prev parent reply other threads:[~2026-12-03 13:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 11:02 Ziheng Wei
2026-12-03 13:37 ` 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=20261203133702.GA389607@sakamocchi.jp \
--to=o-takashi@sakamocchi.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=stable@vger.kernel.org \
--cc=zihengw03@163.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®