Fix module_control0 double-free via unsynchronized ctl_args lifecycle - #296
Open
Admirepowered with Copilot wants to merge 7 commits into
Open
Fix module_control0 double-free via unsynchronized ctl_args lifecycle#296Admirepowered with Copilot wants to merge 7 commits into
Admirepowered with Copilot wants to merge 7 commits into
Conversation
Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
…utex Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
…_lock Co-authored-by: Admirepowered <43035036+Admirepowered@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix double-free issue in module_control0 during concurrent supercalls
Fix module_control0 double-free via unsynchronized ctl_args lifecycle
Aug 10, 2026
Admirepowered
marked this pull request as ready for review
August 10, 2026 07:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
module_control0()freed and re-allocated the shared per-modulemod->ctl_argsbuffer without any locking. Two threads issuingSUPERCALL_KPM_CONTROLagainst the same module could both pass thekvfree(mod->ctl_args)check before either reassigned the pointer, causing a double-free, vmalloc metadata corruption, and a kernel panic.Changes
module_ctl_lockmutex (kernel module code,mod->ctl0may sleep so a mutex is required, not a spinlock) to serialize the free → vmalloc → copy →ctl0()sequence inmodule_control0().unload_module()with the same lock aroundfind_module(),list_del(),mod->exit(), and freeingmod->args/mod->ctl_args/mod, so a module can't be unloaded and freed while a concurrentmodule_control0()is still using it.load_module()with the same lock around the existence-check andlist_add_tail()(plus cleanup paths), so all three module-list mutators (load/unload/control) are mutually exclusive on the shared list and per-module buffers.rcu_read_lock()/rcu_read_unlock()inunload_module()/module_control0()— now redundant since the mutex fully serializes these paths, and the prior usage was itself unsound (structurallist_del()under a read lock, and sleeping viactl0()/mod->exit()inside an RCU read-side critical section).module_lockspinlock — it was declared/initialized but never actually locked anywhere, and would have been confusing alongside the new mutex.