(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

rust: module_param: Fix potentially incorrect access of `SetOnce<T>`

The `set_param` function casts `kernel_param.arg` to `*const SetOnce<T>` But the Rust module macro in rust/macros/module.rs initializes `arg` with `#param_name.as_void_ptr()`, and `#param_name` is a `ModuleParamAccess<T>`, not a `SetOnce<T>`. ModuleParamAccess<T> has default Rust layout but `set_param` accesses its first field SetOnce<T> assuming it to be at offset 0. This is not guaranteed by Rust and could cause type confusion leading to data corruption. Fix this by casting `kernel_param.arg` to `ModuleParamAccess<T>` and then accessing the `value: SetOnce<T>` field. Fixes: 0b08fc292842 ("rust: introduce module_param module") Cc: stable@vger.kernel.org Reported-by: Dylan Zueck <dzueck@uci.edu> Assisted-by: LLM Suggested-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Priya Bala Govindasamy <pgovind2@uci.edu> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>


Author Priya Bala Govindasamy Committer Petr Pavlu Date Commit Parent ff7360c5
+7 -2
1 changed file
+7 -2
1 changed file