FAILED: patch "[PATCH] modules: fix longstanding /proc/kallsyms vs module insertion" failed to apply to 4.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
8244062ef1e54502ef55f54cced659913f244c3eMon Sep 17 00:00:00 2001
From: Rusty Russell <[email protected]>
Date: Wed, 3 Feb 2016 16:55:26 +1030
Subject: [PATCH] modules: fix longstanding /proc/kallsyms vs module insertion
race.
For CONFIG_KALLSYMS, we keep two symbol tables and two string tables. There's one full copy, marked SHF_ALLOC and laid out at the end of the module's init section. There's also a cut-down version that only contains core symbols and strings, and lives in the module's core section.
After module init (and before we free the module memory), we switch the mod->symtab, mod->num_symtab and mod->strtab to point to the core versions. We do this under the module_mutex.
However, kallsyms doesn't take the module_mutex: it uses preempt_disable() and rcu tricks to walk through the modules, because it's used in the oops path. It's also used in /proc/kallsyms. There's nothing atomic about the change of these variables, so we can get the old (larger!) num_symtab and the new symtab pointer; in fact this is what I saw when trying to reproduce.
By grouping these variables together, we can use a carefully-dereferenced pointer to ensure we always get one or the other (the free of the module init section is already done in an RCU callback, so that's safe). We allocate the init one at the end of the module init section, and keep the core one inside the struct module itself (it could also have been allocated at the end of the module core, but that's probably overkill).
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=111541
include/linux/module.h +10 -9
@@ -324,6 +324,12 @@ struct module_layout {#define __module_layout_align#endif +struct mod_kallsyms { +Elf_Sym *symtab; +unsigned int num_symtab; +char *strtab; +}; +struct module {enum module_state state;
@@ -405,15 +411,10 @@ struct module {#endif #ifdef CONFIG_KALLSYMS -/* -* We keep the symbol and string tables for kallsyms. -* The core_* fields below are temporary, loader-only (they -* could really be discarded after module init). -*/ -Elf_Sym *symtab, *core_symtab; -unsigned int num_symtab, core_num_syms; -char *strtab, *core_strtab; - +/* Protected by RCU and/or module_mutex: use rcu_dereference() */ +struct mod_kallsyms *kallsyms; +struct mod_kallsyms core_kallsyms; +/* Section attributes */ struct module_sect_attrs *sect_attrs;
kernel/module.c +69 -43
210 lines not on this page · raw message
Quoted 4 lines · [email protected] writes:
The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Rebased. Fairly trivial, but CC'd Jessica in case she wants to double-check my work.
Thanks,
Rusty.
---
Quoted 1 line
From
012da5da44429f685ea4a689f8bc516cb230c99fMon Sep 17 00:00:00 2001
From: Rusty Russell <[email protected]>
Date: Sun, 6 Mar 2016 15:27:02 +1030
Subject: [PATCH] modules: fix longstanding /proc/kallsyms vs module insertion
[ Rebased for 4.4-stable and older, because the following changes aren't
in the older trees:
- e0224418516b4d8a6c2160574bac18447c354ef0: adds arg to is_core_symbol
- 7523e4dc5057e157212b4741abd6256e03404cf1: module_init/module_core/init_size/core_size become init_layout.base/core_layout.base/init_layout.size/core_layout.size.
Original commit: 8244062ef1e54502ef55f54cced659913f244c3e
]
For CONFIG_KALLSYMS, we keep two symbol tables and two string tables. There's one full copy, marked SHF_ALLOC and laid out at the end of the module's init section. There's also a cut-down version that only contains core symbols and strings, and lives in the module's core section.
After module init (and before we free the module memory), we switch the mod->symtab, mod->num_symtab and mod->strtab to point to the core versions. We do this under the module_mutex.
However, kallsyms doesn't take the module_mutex: it uses preempt_disable() and rcu tricks to walk through the modules, because it's used in the oops path. It's also used in /proc/kallsyms. There's nothing atomic about the change of these variables, so we can get the old (larger!) num_symtab and the new symtab pointer; in fact this is what I saw when trying to reproduce.
By grouping these variables together, we can use a carefully-dereferenced pointer to ensure we always get one or the other (the free of the module init section is already done in an RCU callback, so that's safe). We allocate the init one at the end of the module init section, and keep the core one inside the struct module itself (it could also have been allocated at the end of the module core, but that's probably overkill).
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=111541
include/linux/module.h +10 -9
@@ -302,6 +302,12 @@ struct mod_tree_node {struct latch_tree_node node; }; +struct mod_kallsyms { +Elf_Sym *symtab; +unsigned int num_symtab; +char *strtab; +}; +struct module {enum module_state state;
@@ -411,15 +417,10 @@ struct module {#endif #ifdef CONFIG_KALLSYMS -/* -* We keep the symbol and string tables for kallsyms. -* The core_* fields below are temporary, loader-only (they -* could really be discarded after module init). -*/ -Elf_Sym *symtab, *core_symtab; -unsigned int num_symtab, core_num_syms; -char *strtab, *core_strtab; - +/* Protected by RCU and/or module_mutex: use rcu_dereference() */ +struct mod_kallsyms *kallsyms; +struct mod_kallsyms core_kallsyms; +/* Section attributes */ struct module_sect_attrs *sect_attrs;
kernel/module.c +69 -43
209 lines not on this page · raw message
Greg KH
maintainerQuoted 9 lines · Rusty Russell
Quoted 4 lines · [email protected] writes:
The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Rebased. Fairly trivial, but CC'd Jessica in case she wants to double-check my work.
Thanks, I've queued this up for 4.4-stable. Should it go to any older kernels as well?
greg k-h
Quoted 8 lines · Greg KH
Quoted 7 lines · Rusty Russell
Quoted 4 lines · [email protected] writes:
The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Quoted 5 lines
Quoted 2 lines
Rebased. Fairly trivial, but CC'd Jessica in case she wants to double-check my work.
Thanks, I've queued this up for 4.4-stable. Should it go to any older kernels as well?
Yes, definitely, but this version should apply to them with minimal fuss.
Thanks,
Rusty.
Hi
Can this patch be add to stable-3.10.y?
Actually we got the bug on it.
Thanks!
Quoted 22 lines · Rusty Russell
Quoted 8 lines · Greg KH
Quoted 7 lines · Rusty Russell
Quoted 4 lines · [email protected] writes:
The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Quoted 5 lines
Quoted 2 lines
Rebased. Fairly trivial, but CC'd Jessica in case she wants to double-check my work.
Thanks, I've queued this up for 4.4-stable. Should it go to any older kernels as well?
Yes, definitely, but this version should apply to them with minimal fuss.
Thanks,
Rusty..
Greg KH
maintainerQuoted 3 lines · Weilong Chen
Hi
Can this patch be add to stable-3.10.y?
Actually we got the bug on it.
Ok, now queued up.
thanks,
greg k-h
+++ Rusty Russell [06/03/16 15:35 +1030]:
Quoted 9 lines
Quoted 4 lines · [email protected] writes:
The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Rebased. Fairly trivial, but CC'd Jessica in case she wants to double-check my work.
Thanks for the CC. FWIW I looked over both the backport and the original patch and they both look good to me.
Jessica