aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-08-04 09:14:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-04 09:14:38 -0400
commitfb1b83d3ff78168e10799627f231cf0c05c9d80d (patch)
tree57feaa178322a776825329c3c7c170aee2ded837
parentd597690eef4142cf622fd469859ecc56506119b5 (diff)
parent49aadcf1b6f4240751921dad52e86c760d70a5f1 (diff)
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull module updates from Rusty Russell: "The only interesting thing here is Jessica's patch to add ro_after_init support to modules. The rest are all trivia" * tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: extable.h: add stddef.h so "NULL" definition is not implicit modules: add ro_after_init support jump_label: disable preemption around __module_text_address(). exceptions: fork exception table content from module.h into extable.h modules: Add kernel parameter to blacklist modules module: Do a WARN_ON_ONCE() for assert module mutex not held Documentation/module-signing.txt: Note need for version info if reusing a key module: Invalidate signatures on force-loaded modules module: Issue warnings when tainting kernel module: fix redundant test. module: fix noreturn attribute for __module_put_and_exit()
-rw-r--r--Documentation/kernel-parameters.txt3
-rw-r--r--Documentation/module-signing.txt6
-rw-r--r--include/linux/extable.h32
-rw-r--r--include/linux/module.h37
-rw-r--r--include/uapi/linux/elf.h1
-rw-r--r--kernel/jump_label.c5
-rw-r--r--kernel/livepatch/core.c2
-rw-r--r--kernel/module.c121
8 files changed, 155 insertions, 52 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 00e4c2f615a8..1a855d0c11fa 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2320,6 +2320,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2320 Note that if CONFIG_MODULE_SIG_FORCE is set, that 2320 Note that if CONFIG_MODULE_SIG_FORCE is set, that
2321 is always true, so this option does nothing. 2321 is always true, so this option does nothing.
2322 2322
2323 module_blacklist= [KNL] Do not load a comma-separated list of
2324 modules. Useful for debugging problem modules.
2325
2323 mousedev.tap_time= 2326 mousedev.tap_time=
2324 [MOUSE] Maximum time between finger touching and 2327 [MOUSE] Maximum time between finger touching and
2325 leaving touchpad surface for touch to be considered 2328 leaving touchpad surface for touch to be considered
diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
index 696d5caf4fd8..f0e3361db20c 100644
--- a/Documentation/module-signing.txt
+++ b/Documentation/module-signing.txt
@@ -271,3 +271,9 @@ Since the private key is used to sign modules, viruses and malware could use
271the private key to sign modules and compromise the operating system. The 271the private key to sign modules and compromise the operating system. The
272private key must be either destroyed or moved to a secure location and not kept 272private key must be either destroyed or moved to a secure location and not kept
273in the root node of the kernel source tree. 273in the root node of the kernel source tree.
274
275If you use the same private key to sign modules for multiple kernel
276configurations, you must ensure that the module version information is
277sufficient to prevent loading a module into a different kernel. Either
278set CONFIG_MODVERSIONS=y or ensure that each configuration has a different
279kernel release string by changing EXTRAVERSION or CONFIG_LOCALVERSION.
diff --git a/include/linux/extable.h b/include/linux/extable.h
new file mode 100644
index 000000000000..7effea4b257d
--- /dev/null
+++ b/include/linux/extable.h
@@ -0,0 +1,32 @@
1#ifndef _LINUX_EXTABLE_H
2#define _LINUX_EXTABLE_H
3
4#include <linux/stddef.h> /* for NULL */
5
6struct module;
7struct exception_table_entry;
8
9const struct exception_table_entry *
10search_extable(const struct exception_table_entry *first,
11 const struct exception_table_entry *last,
12 unsigned long value);
13void sort_extable(struct exception_table_entry *start,
14 struct exception_table_entry *finish);
15void sort_main_extable(void);
16void trim_init_extable(struct module *m);
17
18/* Given an address, look for it in the exception tables */
19const struct exception_table_entry *search_exception_tables(unsigned long add);
20
21#ifdef CONFIG_MODULES
22/* For extable.c to search modules' exception tables. */
23const struct exception_table_entry *search_module_extables(unsigned long addr);
24#else
25static inline const struct exception_table_entry *
26search_module_extables(unsigned long addr)
27{
28 return NULL;
29}
30#endif /*CONFIG_MODULES*/
31
32#endif /* _LINUX_EXTABLE_H */
diff --git a/include/linux/module.h b/include/linux/module.h
index 3daf2b3a09d2..0c3207d26ac0 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -18,6 +18,7 @@
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/jump_label.h> 19#include <linux/jump_label.h>
20#include <linux/export.h> 20#include <linux/export.h>
21#include <linux/extable.h> /* only as arch move module.h -> extable.h */
21#include <linux/rbtree_latch.h> 22#include <linux/rbtree_latch.h>
22 23
23#include <linux/percpu.h> 24#include <linux/percpu.h>
@@ -37,6 +38,7 @@ struct modversion_info {
37}; 38};
38 39
39struct module; 40struct module;
41struct exception_table_entry;
40 42
41struct module_kobject { 43struct module_kobject {
42 struct kobject kobj; 44 struct kobject kobj;
@@ -155,18 +157,6 @@ extern void cleanup_module(void);
155#define __INITRODATA_OR_MODULE __INITRODATA 157#define __INITRODATA_OR_MODULE __INITRODATA
156#endif /*CONFIG_MODULES*/ 158#endif /*CONFIG_MODULES*/
157 159
158/* Archs provide a method of finding the correct exception table. */
159struct exception_table_entry;
160
161const struct exception_table_entry *
162search_extable(const struct exception_table_entry *first,
163 const struct exception_table_entry *last,
164 unsigned long value);
165void sort_extable(struct exception_table_entry *start,
166 struct exception_table_entry *finish);
167void sort_main_extable(void);
168void trim_init_extable(struct module *m);
169
170/* Generic info of form tag = "info" */ 160/* Generic info of form tag = "info" */
171#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) 161#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
172 162
@@ -268,9 +258,6 @@ extern const typeof(name) __mod_##type##__##name##_device_table \
268 * files require multiple MODULE_FIRMWARE() specifiers */ 258 * files require multiple MODULE_FIRMWARE() specifiers */
269#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) 259#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
270 260
271/* Given an address, look for it in the exception tables */
272const struct exception_table_entry *search_exception_tables(unsigned long add);
273
274struct notifier_block; 261struct notifier_block;
275 262
276#ifdef CONFIG_MODULES 263#ifdef CONFIG_MODULES
@@ -311,6 +298,8 @@ struct module_layout {
311 unsigned int text_size; 298 unsigned int text_size;
312 /* Size of RO section of the module (text+rodata) */ 299 /* Size of RO section of the module (text+rodata) */
313 unsigned int ro_size; 300 unsigned int ro_size;
301 /* Size of RO after init section */
302 unsigned int ro_after_init_size;
314 303
315#ifdef CONFIG_MODULES_TREE_LOOKUP 304#ifdef CONFIG_MODULES_TREE_LOOKUP
316 struct mod_tree_node mtn; 305 struct mod_tree_node mtn;
@@ -575,8 +564,8 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
575 struct module *, unsigned long), 564 struct module *, unsigned long),
576 void *data); 565 void *data);
577 566
578extern void __module_put_and_exit(struct module *mod, long code) 567extern void __noreturn __module_put_and_exit(struct module *mod,
579 __attribute__((noreturn)); 568 long code);
580#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code) 569#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
581 570
582#ifdef CONFIG_MODULE_UNLOAD 571#ifdef CONFIG_MODULE_UNLOAD
@@ -630,9 +619,6 @@ const char *module_address_lookup(unsigned long addr,
630int lookup_module_symbol_name(unsigned long addr, char *symname); 619int lookup_module_symbol_name(unsigned long addr, char *symname);
631int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 620int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
632 621
633/* For extable.c to search modules' exception tables. */
634const struct exception_table_entry *search_module_extables(unsigned long addr);
635
636int register_module_notifier(struct notifier_block *nb); 622int register_module_notifier(struct notifier_block *nb);
637int unregister_module_notifier(struct notifier_block *nb); 623int unregister_module_notifier(struct notifier_block *nb);
638 624
@@ -657,13 +643,6 @@ static inline bool is_livepatch_module(struct module *mod)
657 643
658#else /* !CONFIG_MODULES... */ 644#else /* !CONFIG_MODULES... */
659 645
660/* Given an address, look for it in the exception tables. */
661static inline const struct exception_table_entry *
662search_module_extables(unsigned long addr)
663{
664 return NULL;
665}
666
667static inline struct module *__module_address(unsigned long addr) 646static inline struct module *__module_address(unsigned long addr)
668{ 647{
669 return NULL; 648 return NULL;
@@ -788,12 +767,12 @@ extern int module_sysfs_initialized;
788#ifdef CONFIG_DEBUG_SET_MODULE_RONX 767#ifdef CONFIG_DEBUG_SET_MODULE_RONX
789extern void set_all_modules_text_rw(void); 768extern void set_all_modules_text_rw(void);
790extern void set_all_modules_text_ro(void); 769extern void set_all_modules_text_ro(void);
791extern void module_enable_ro(const struct module *mod); 770extern void module_enable_ro(const struct module *mod, bool after_init);
792extern void module_disable_ro(const struct module *mod); 771extern void module_disable_ro(const struct module *mod);
793#else 772#else
794static inline void set_all_modules_text_rw(void) { } 773static inline void set_all_modules_text_rw(void) { }
795static inline void set_all_modules_text_ro(void) { } 774static inline void set_all_modules_text_ro(void) { }
796static inline void module_enable_ro(const struct module *mod) { } 775static inline void module_enable_ro(const struct module *mod, bool after_init) { }
797static inline void module_disable_ro(const struct module *mod) { } 776static inline void module_disable_ro(const struct module *mod) { }
798#endif 777#endif
799 778
diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
index cb4a72f888d5..70b172ba41ce 100644
--- a/include/uapi/linux/elf.h
+++ b/include/uapi/linux/elf.h
@@ -286,6 +286,7 @@ typedef struct elf64_phdr {
286#define SHF_ALLOC 0x2 286#define SHF_ALLOC 0x2
287#define SHF_EXECINSTR 0x4 287#define SHF_EXECINSTR 0x4
288#define SHF_RELA_LIVEPATCH 0x00100000 288#define SHF_RELA_LIVEPATCH 0x00100000
289#define SHF_RO_AFTER_INIT 0x00200000
289#define SHF_MASKPROC 0xf0000000 290#define SHF_MASKPROC 0xf0000000
290 291
291/* special section indexes */ 292/* special section indexes */
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index f19aa02a8f48..20400055f177 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -337,11 +337,14 @@ static int __jump_label_mod_text_reserved(void *start, void *end)
337{ 337{
338 struct module *mod; 338 struct module *mod;
339 339
340 preempt_disable();
340 mod = __module_text_address((unsigned long)start); 341 mod = __module_text_address((unsigned long)start);
342 WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
343 preempt_enable();
344
341 if (!mod) 345 if (!mod)
342 return 0; 346 return 0;
343 347
344 WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
345 348
346 return __jump_label_text_reserved(mod->jump_entries, 349 return __jump_label_text_reserved(mod->jump_entries,
347 mod->jump_entries + mod->num_jump_entries, 350 mod->jump_entries + mod->num_jump_entries,
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 5c2bc1052691..8bbe50704621 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -309,7 +309,7 @@ static int klp_write_object_relocations(struct module *pmod,
309 break; 309 break;
310 } 310 }
311 311
312 module_enable_ro(pmod); 312 module_enable_ro(pmod, true);
313 return ret; 313 return ret;
314} 314}
315 315
diff --git a/kernel/module.c b/kernel/module.c
index a0f48b8b00da..529efae9f481 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -265,7 +265,7 @@ static void module_assert_mutex_or_preempt(void)
265 if (unlikely(!debug_locks)) 265 if (unlikely(!debug_locks))
266 return; 266 return;
267 267
268 WARN_ON(!rcu_read_lock_sched_held() && 268 WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
269 !lockdep_is_held(&module_mutex)); 269 !lockdep_is_held(&module_mutex));
270#endif 270#endif
271} 271}
@@ -337,7 +337,7 @@ static inline void add_taint_module(struct module *mod, unsigned flag,
337 * A thread that wants to hold a reference to a module only while it 337 * A thread that wants to hold a reference to a module only while it
338 * is running can call this to safely exit. nfsd and lockd use this. 338 * is running can call this to safely exit. nfsd and lockd use this.
339 */ 339 */
340void __module_put_and_exit(struct module *mod, long code) 340void __noreturn __module_put_and_exit(struct module *mod, long code)
341{ 341{
342 module_put(mod); 342 module_put(mod);
343 do_exit(code); 343 do_exit(code);
@@ -1694,8 +1694,7 @@ static int module_add_modinfo_attrs(struct module *mod)
1694 1694
1695 temp_attr = mod->modinfo_attrs; 1695 temp_attr = mod->modinfo_attrs;
1696 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { 1696 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1697 if (!attr->test || 1697 if (!attr->test || attr->test(mod)) {
1698 (attr->test && attr->test(mod))) {
1699 memcpy(temp_attr, attr, sizeof(*temp_attr)); 1698 memcpy(temp_attr, attr, sizeof(*temp_attr));
1700 sysfs_attr_init(&temp_attr->attr); 1699 sysfs_attr_init(&temp_attr->attr);
1701 error = sysfs_create_file(&mod->mkobj.kobj, 1700 error = sysfs_create_file(&mod->mkobj.kobj,
@@ -1859,10 +1858,11 @@ static void mod_sysfs_teardown(struct module *mod)
1859 * from modification and any data from execution. 1858 * from modification and any data from execution.
1860 * 1859 *
1861 * General layout of module is: 1860 * General layout of module is:
1862 * [text] [read-only-data] [writable data] 1861 * [text] [read-only-data] [ro-after-init] [writable data]
1863 * text_size -----^ ^ ^ 1862 * text_size -----^ ^ ^ ^
1864 * ro_size ------------------------| | 1863 * ro_size ------------------------| | |
1865 * size -------------------------------------------| 1864 * ro_after_init_size -----------------------------| |
1865 * size -----------------------------------------------------------|
1866 * 1866 *
1867 * These values are always page-aligned (as is base) 1867 * These values are always page-aligned (as is base)
1868 */ 1868 */
@@ -1885,14 +1885,24 @@ static void frob_rodata(const struct module_layout *layout,
1885 (layout->ro_size - layout->text_size) >> PAGE_SHIFT); 1885 (layout->ro_size - layout->text_size) >> PAGE_SHIFT);
1886} 1886}
1887 1887
1888static void frob_ro_after_init(const struct module_layout *layout,
1889 int (*set_memory)(unsigned long start, int num_pages))
1890{
1891 BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1));
1892 BUG_ON((unsigned long)layout->ro_size & (PAGE_SIZE-1));
1893 BUG_ON((unsigned long)layout->ro_after_init_size & (PAGE_SIZE-1));
1894 set_memory((unsigned long)layout->base + layout->ro_size,
1895 (layout->ro_after_init_size - layout->ro_size) >> PAGE_SHIFT);
1896}
1897
1888static void frob_writable_data(const struct module_layout *layout, 1898static void frob_writable_data(const struct module_layout *layout,
1889 int (*set_memory)(unsigned long start, int num_pages)) 1899 int (*set_memory)(unsigned long start, int num_pages))
1890{ 1900{
1891 BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1)); 1901 BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1));
1892 BUG_ON((unsigned long)layout->ro_size & (PAGE_SIZE-1)); 1902 BUG_ON((unsigned long)layout->ro_after_init_size & (PAGE_SIZE-1));
1893 BUG_ON((unsigned long)layout->size & (PAGE_SIZE-1)); 1903 BUG_ON((unsigned long)layout->size & (PAGE_SIZE-1));
1894 set_memory((unsigned long)layout->base + layout->ro_size, 1904 set_memory((unsigned long)layout->base + layout->ro_after_init_size,
1895 (layout->size - layout->ro_size) >> PAGE_SHIFT); 1905 (layout->size - layout->ro_after_init_size) >> PAGE_SHIFT);
1896} 1906}
1897 1907
1898/* livepatching wants to disable read-only so it can frob module. */ 1908/* livepatching wants to disable read-only so it can frob module. */
@@ -1900,21 +1910,26 @@ void module_disable_ro(const struct module *mod)
1900{ 1910{
1901 frob_text(&mod->core_layout, set_memory_rw); 1911 frob_text(&mod->core_layout, set_memory_rw);
1902 frob_rodata(&mod->core_layout, set_memory_rw); 1912 frob_rodata(&mod->core_layout, set_memory_rw);
1913 frob_ro_after_init(&mod->core_layout, set_memory_rw);
1903 frob_text(&mod->init_layout, set_memory_rw); 1914 frob_text(&mod->init_layout, set_memory_rw);
1904 frob_rodata(&mod->init_layout, set_memory_rw); 1915 frob_rodata(&mod->init_layout, set_memory_rw);
1905} 1916}
1906 1917
1907void module_enable_ro(const struct module *mod) 1918void module_enable_ro(const struct module *mod, bool after_init)
1908{ 1919{
1909 frob_text(&mod->core_layout, set_memory_ro); 1920 frob_text(&mod->core_layout, set_memory_ro);
1910 frob_rodata(&mod->core_layout, set_memory_ro); 1921 frob_rodata(&mod->core_layout, set_memory_ro);
1911 frob_text(&mod->init_layout, set_memory_ro); 1922 frob_text(&mod->init_layout, set_memory_ro);
1912 frob_rodata(&mod->init_layout, set_memory_ro); 1923 frob_rodata(&mod->init_layout, set_memory_ro);
1924
1925 if (after_init)
1926 frob_ro_after_init(&mod->core_layout, set_memory_ro);
1913} 1927}
1914 1928
1915static void module_enable_nx(const struct module *mod) 1929static void module_enable_nx(const struct module *mod)
1916{ 1930{
1917 frob_rodata(&mod->core_layout, set_memory_nx); 1931 frob_rodata(&mod->core_layout, set_memory_nx);
1932 frob_ro_after_init(&mod->core_layout, set_memory_nx);
1918 frob_writable_data(&mod->core_layout, set_memory_nx); 1933 frob_writable_data(&mod->core_layout, set_memory_nx);
1919 frob_rodata(&mod->init_layout, set_memory_nx); 1934 frob_rodata(&mod->init_layout, set_memory_nx);
1920 frob_writable_data(&mod->init_layout, set_memory_nx); 1935 frob_writable_data(&mod->init_layout, set_memory_nx);
@@ -1923,6 +1938,7 @@ static void module_enable_nx(const struct module *mod)
1923static void module_disable_nx(const struct module *mod) 1938static void module_disable_nx(const struct module *mod)
1924{ 1939{
1925 frob_rodata(&mod->core_layout, set_memory_x); 1940 frob_rodata(&mod->core_layout, set_memory_x);
1941 frob_ro_after_init(&mod->core_layout, set_memory_x);
1926 frob_writable_data(&mod->core_layout, set_memory_x); 1942 frob_writable_data(&mod->core_layout, set_memory_x);
1927 frob_rodata(&mod->init_layout, set_memory_x); 1943 frob_rodata(&mod->init_layout, set_memory_x);
1928 frob_writable_data(&mod->init_layout, set_memory_x); 1944 frob_writable_data(&mod->init_layout, set_memory_x);
@@ -1965,6 +1981,8 @@ static void disable_ro_nx(const struct module_layout *layout)
1965 frob_text(layout, set_memory_rw); 1981 frob_text(layout, set_memory_rw);
1966 frob_rodata(layout, set_memory_rw); 1982 frob_rodata(layout, set_memory_rw);
1967 frob_rodata(layout, set_memory_x); 1983 frob_rodata(layout, set_memory_x);
1984 frob_ro_after_init(layout, set_memory_rw);
1985 frob_ro_after_init(layout, set_memory_x);
1968 frob_writable_data(layout, set_memory_x); 1986 frob_writable_data(layout, set_memory_x);
1969} 1987}
1970 1988
@@ -2307,6 +2325,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
2307 * finder in the two loops below */ 2325 * finder in the two loops below */
2308 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL }, 2326 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
2309 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL }, 2327 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
2328 { SHF_RO_AFTER_INIT | SHF_ALLOC, ARCH_SHF_SMALL },
2310 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL }, 2329 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
2311 { ARCH_SHF_SMALL | SHF_ALLOC, 0 } 2330 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
2312 }; 2331 };
@@ -2338,7 +2357,11 @@ static void layout_sections(struct module *mod, struct load_info *info)
2338 mod->core_layout.size = debug_align(mod->core_layout.size); 2357 mod->core_layout.size = debug_align(mod->core_layout.size);
2339 mod->core_layout.ro_size = mod->core_layout.size; 2358 mod->core_layout.ro_size = mod->core_layout.size;
2340 break; 2359 break;
2341 case 3: /* whole core */ 2360 case 2: /* RO after init */
2361 mod->core_layout.size = debug_align(mod->core_layout.size);
2362 mod->core_layout.ro_after_init_size = mod->core_layout.size;
2363 break;
2364 case 4: /* whole core */
2342 mod->core_layout.size = debug_align(mod->core_layout.size); 2365 mod->core_layout.size = debug_align(mod->core_layout.size);
2343 break; 2366 break;
2344 } 2367 }
@@ -2368,7 +2391,14 @@ static void layout_sections(struct module *mod, struct load_info *info)
2368 mod->init_layout.size = debug_align(mod->init_layout.size); 2391 mod->init_layout.size = debug_align(mod->init_layout.size);
2369 mod->init_layout.ro_size = mod->init_layout.size; 2392 mod->init_layout.ro_size = mod->init_layout.size;
2370 break; 2393 break;
2371 case 3: /* whole init */ 2394 case 2:
2395 /*
2396 * RO after init doesn't apply to init_layout (only
2397 * core_layout), so it just takes the value of ro_size.
2398 */
2399 mod->init_layout.ro_after_init_size = mod->init_layout.ro_size;
2400 break;
2401 case 4: /* whole init */
2372 mod->init_layout.size = debug_align(mod->init_layout.size); 2402 mod->init_layout.size = debug_align(mod->init_layout.size);
2373 break; 2403 break;
2374 } 2404 }
@@ -2688,13 +2718,18 @@ static inline void kmemleak_load_module(const struct module *mod,
2688#endif 2718#endif
2689 2719
2690#ifdef CONFIG_MODULE_SIG 2720#ifdef CONFIG_MODULE_SIG
2691static int module_sig_check(struct load_info *info) 2721static int module_sig_check(struct load_info *info, int flags)
2692{ 2722{
2693 int err = -ENOKEY; 2723 int err = -ENOKEY;
2694 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; 2724 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
2695 const void *mod = info->hdr; 2725 const void *mod = info->hdr;
2696 2726
2697 if (info->len > markerlen && 2727 /*
2728 * Require flags == 0, as a module with version information
2729 * removed is no longer the module that was signed
2730 */
2731 if (flags == 0 &&
2732 info->len > markerlen &&
2698 memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) { 2733 memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
2699 /* We truncate the module to discard the signature */ 2734 /* We truncate the module to discard the signature */
2700 info->len -= markerlen; 2735 info->len -= markerlen;
@@ -2713,7 +2748,7 @@ static int module_sig_check(struct load_info *info)
2713 return err; 2748 return err;
2714} 2749}
2715#else /* !CONFIG_MODULE_SIG */ 2750#else /* !CONFIG_MODULE_SIG */
2716static int module_sig_check(struct load_info *info) 2751static int module_sig_check(struct load_info *info, int flags)
2717{ 2752{
2718 return 0; 2753 return 0;
2719} 2754}
@@ -2921,8 +2956,12 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2921 return -ENOEXEC; 2956 return -ENOEXEC;
2922 } 2957 }
2923 2958
2924 if (!get_modinfo(info, "intree")) 2959 if (!get_modinfo(info, "intree")) {
2960 if (!test_taint(TAINT_OOT_MODULE))
2961 pr_warn("%s: loading out-of-tree module taints kernel.\n",
2962 mod->name);
2925 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); 2963 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
2964 }
2926 2965
2927 if (get_modinfo(info, "staging")) { 2966 if (get_modinfo(info, "staging")) {
2928 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); 2967 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
@@ -3091,6 +3130,8 @@ static int move_module(struct module *mod, struct load_info *info)
3091 3130
3092static int check_module_license_and_versions(struct module *mod) 3131static int check_module_license_and_versions(struct module *mod)
3093{ 3132{
3133 int prev_taint = test_taint(TAINT_PROPRIETARY_MODULE);
3134
3094 /* 3135 /*
3095 * ndiswrapper is under GPL by itself, but loads proprietary modules. 3136 * ndiswrapper is under GPL by itself, but loads proprietary modules.
3096 * Don't use add_taint_module(), as it would prevent ndiswrapper from 3137 * Don't use add_taint_module(), as it would prevent ndiswrapper from
@@ -3109,6 +3150,9 @@ static int check_module_license_and_versions(struct module *mod)
3109 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 3150 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
3110 LOCKDEP_NOW_UNRELIABLE); 3151 LOCKDEP_NOW_UNRELIABLE);
3111 3152
3153 if (!prev_taint && test_taint(TAINT_PROPRIETARY_MODULE))
3154 pr_warn("%s: module license taints kernel.\n", mod->name);
3155
3112#ifdef CONFIG_MODVERSIONS 3156#ifdef CONFIG_MODVERSIONS
3113 if ((mod->num_syms && !mod->crcs) 3157 if ((mod->num_syms && !mod->crcs)
3114 || (mod->num_gpl_syms && !mod->gpl_crcs) 3158 || (mod->num_gpl_syms && !mod->gpl_crcs)
@@ -3156,16 +3200,41 @@ int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
3156 return 0; 3200 return 0;
3157} 3201}
3158 3202
3203/* module_blacklist is a comma-separated list of module names */
3204static char *module_blacklist;
3205static bool blacklisted(char *module_name)
3206{
3207 const char *p;
3208 size_t len;
3209
3210 if (!module_blacklist)
3211 return false;
3212
3213 for (p = module_blacklist; *p; p += len) {
3214 len = strcspn(p, ",");
3215 if (strlen(module_name) == len && !memcmp(module_name, p, len))
3216 return true;
3217 if (p[len] == ',')
3218 len++;
3219 }
3220 return false;
3221}
3222core_param(module_blacklist, module_blacklist, charp, 0400);
3223
3159static struct module *layout_and_allocate(struct load_info *info, int flags) 3224static struct module *layout_and_allocate(struct load_info *info, int flags)
3160{ 3225{
3161 /* Module within temporary copy. */ 3226 /* Module within temporary copy. */
3162 struct module *mod; 3227 struct module *mod;
3228 unsigned int ndx;
3163 int err; 3229 int err;
3164 3230
3165 mod = setup_load_info(info, flags); 3231 mod = setup_load_info(info, flags);
3166 if (IS_ERR(mod)) 3232 if (IS_ERR(mod))
3167 return mod; 3233 return mod;
3168 3234
3235 if (blacklisted(mod->name))
3236 return ERR_PTR(-EPERM);
3237
3169 err = check_modinfo(mod, info, flags); 3238 err = check_modinfo(mod, info, flags);
3170 if (err) 3239 if (err)
3171 return ERR_PTR(err); 3240 return ERR_PTR(err);
@@ -3179,6 +3248,15 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
3179 /* We will do a special allocation for per-cpu sections later. */ 3248 /* We will do a special allocation for per-cpu sections later. */
3180 info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC; 3249 info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC;
3181 3250
3251 /*
3252 * Mark ro_after_init section with SHF_RO_AFTER_INIT so that
3253 * layout_sections() can put it in the right place.
3254 * Note: ro_after_init sections also have SHF_{WRITE,ALLOC} set.
3255 */
3256 ndx = find_sec(info, ".data..ro_after_init");
3257 if (ndx)
3258 info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT;
3259
3182 /* Determine total sizes, and put offsets in sh_entsize. For now 3260 /* Determine total sizes, and put offsets in sh_entsize. For now
3183 this is done generically; there doesn't appear to be any 3261 this is done generically; there doesn't appear to be any
3184 special cases for the architectures. */ 3262 special cases for the architectures. */
@@ -3345,12 +3423,14 @@ static noinline int do_init_module(struct module *mod)
3345 /* Switch to core kallsyms now init is done: kallsyms may be walking! */ 3423 /* Switch to core kallsyms now init is done: kallsyms may be walking! */
3346 rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); 3424 rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms);
3347#endif 3425#endif
3426 module_enable_ro(mod, true);
3348 mod_tree_remove_init(mod); 3427 mod_tree_remove_init(mod);
3349 disable_ro_nx(&mod->init_layout); 3428 disable_ro_nx(&mod->init_layout);
3350 module_arch_freeing_init(mod); 3429 module_arch_freeing_init(mod);
3351 mod->init_layout.base = NULL; 3430 mod->init_layout.base = NULL;
3352 mod->init_layout.size = 0; 3431 mod->init_layout.size = 0;
3353 mod->init_layout.ro_size = 0; 3432 mod->init_layout.ro_size = 0;
3433 mod->init_layout.ro_after_init_size = 0;
3354 mod->init_layout.text_size = 0; 3434 mod->init_layout.text_size = 0;
3355 /* 3435 /*
3356 * We want to free module_init, but be aware that kallsyms may be 3436 * We want to free module_init, but be aware that kallsyms may be
@@ -3442,8 +3522,7 @@ static int complete_formation(struct module *mod, struct load_info *info)
3442 /* This relies on module_mutex for list integrity. */ 3522 /* This relies on module_mutex for list integrity. */
3443 module_bug_finalize(info->hdr, info->sechdrs, mod); 3523 module_bug_finalize(info->hdr, info->sechdrs, mod);
3444 3524
3445 /* Set RO and NX regions */ 3525 module_enable_ro(mod, false);
3446 module_enable_ro(mod);
3447 module_enable_nx(mod); 3526 module_enable_nx(mod);
3448 3527
3449 /* Mark state as coming so strong_try_module_get() ignores us, 3528 /* Mark state as coming so strong_try_module_get() ignores us,
@@ -3499,7 +3578,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
3499 long err; 3578 long err;
3500 char *after_dashes; 3579 char *after_dashes;
3501 3580
3502 err = module_sig_check(info); 3581 err = module_sig_check(info, flags);
3503 if (err) 3582 if (err)
3504 goto free_copy; 3583 goto free_copy;
3505 3584