* [PATCH] firewire: core: defer old_rom assignment until kmemdup() succeeds
@ 2026-12-02 11:02 Ziheng Wei
2026-12-03 13:37 ` Takashi Sakamoto
0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-12-02 11:02 UTC (permalink / raw)
To: Takashi Sakamoto; +Cc: linux1394-devel, linux-kernel, stable
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(-)
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] firewire: core: defer old_rom assignment until kmemdup() succeeds
2026-12-02 11:02 [PATCH] firewire: core: defer old_rom assignment until kmemdup() succeeds Ziheng Wei
@ 2026-12-03 13:37 ` Takashi Sakamoto
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Sakamoto @ 2026-12-03 13:37 UTC (permalink / raw)
To: Ziheng Wei; +Cc: linux1394-devel, linux-kernel, stable
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 13:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 11:02 [PATCH] firewire: core: defer old_rom assignment until kmemdup() succeeds Ziheng Wei
2026-12-03 13:37 ` Takashi Sakamoto
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®