Skip to content

mel: fix use-after-free of the window tensor on device backends - #121

Open
roelaaij wants to merge 1 commit into
mudler:masterfrom
roelaaij:fix/streaming-gpu-window-uaf
Open

roelaaij wants to merge 1 commit into
mudler:masterfrom
roelaaij:fix/streaming-gpu-window-uaf

Conversation

@roelaaij

Copy link
Copy Markdown
Contributor

MelKernel::MelKernel fetched the window tensor pointer, then called weight_to_host_f32, then dereferenced the pointer for its shape. On a device backend the first weight_to_host_f32 realizes the weights. The loader then swaps its tensor map to device tensors and ggml_free()s the host ctx, resulting in the w pointer is dangling and w->ne[0] reading freed memory.

To fix this: capture the shape before the realize call. weight_to_host_f32 re-fetches the (device) tensor internally, so nothing else holds the old pointer.

Assisted-by: Hermes:mistral-glm-5-3

MelKernel::MelKernel fetched the window tensor pointer, then called
weight_to_host_f32, then dereferenced the pointer for its shape. On a
device backend the first weight_to_host_f32 realizes the weights. The
loader then swaps its tensor map to device tensors and ggml_free()s
the host ctx, resulting in the w pointer is dangling and w->ne[0]
reading freed memory.

To fix this: capture the shape before the realize call.
weight_to_host_f32 re-fetches the (device) tensor internally, so
nothing else holds the old pointer.

Assisted-by: Hermes:mistral-glm-5-3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant