aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-10-22 03:39:41 -0400
committerRusty Russell <rusty@rustcorp.com.au>2012-12-13 21:35:23 -0500
commit2f3238aebedb243804f58d62d57244edec4149b2 (patch)
tree984f7f4a6b2225649120c55a7b89e65e9de55ee2 /kernel
parent34e1169d996ab148490c01b65b4ee371cf8ffba2 (diff)
module: add flags arg to sys_finit_module()
Thanks to Michael Kerrisk for keeping us honest. These flags are actually useful for eliminating the only case where kmod has to mangle a module's internals: for overriding module versioning. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Acked-by: Lucas De Marchi <lucas.demarchi@profusion.mobi> Acked-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/module.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 6d2c4e4ca1f5..1395ca382fb5 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -60,6 +60,7 @@
60#include <linux/pfn.h> 60#include <linux/pfn.h>
61#include <linux/bsearch.h> 61#include <linux/bsearch.h>
62#include <linux/fips.h> 62#include <linux/fips.h>
63#include <uapi/linux/module.h>
63#include "module-internal.h" 64#include "module-internal.h"
64 65
65#define CREATE_TRACE_POINTS 66#define CREATE_TRACE_POINTS
@@ -2553,7 +2554,7 @@ static void free_copy(struct load_info *info)
2553 vfree(info->hdr); 2554 vfree(info->hdr);
2554} 2555}
2555 2556
2556static int rewrite_section_headers(struct load_info *info) 2557static int rewrite_section_headers(struct load_info *info, int flags)
2557{ 2558{
2558 unsigned int i; 2559 unsigned int i;
2559 2560
@@ -2581,7 +2582,10 @@ static int rewrite_section_headers(struct load_info *info)
2581 } 2582 }
2582 2583
2583 /* Track but don't keep modinfo and version sections. */ 2584 /* Track but don't keep modinfo and version sections. */
2584 info->index.vers = find_sec(info, "__versions"); 2585 if (flags & MODULE_INIT_IGNORE_MODVERSIONS)
2586 info->index.vers = 0; /* Pretend no __versions section! */
2587 else
2588 info->index.vers = find_sec(info, "__versions");
2585 info->index.info = find_sec(info, ".modinfo"); 2589 info->index.info = find_sec(info, ".modinfo");
2586 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; 2590 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC;
2587 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; 2591 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC;
@@ -2596,7 +2600,7 @@ static int rewrite_section_headers(struct load_info *info)
2596 * Return the temporary module pointer (we'll replace it with the final 2600 * Return the temporary module pointer (we'll replace it with the final
2597 * one when we move the module sections around). 2601 * one when we move the module sections around).
2598 */ 2602 */
2599static struct module *setup_load_info(struct load_info *info) 2603static struct module *setup_load_info(struct load_info *info, int flags)
2600{ 2604{
2601 unsigned int i; 2605 unsigned int i;
2602 int err; 2606 int err;
@@ -2607,7 +2611,7 @@ static struct module *setup_load_info(struct load_info *info)
2607 info->secstrings = (void *)info->hdr 2611 info->secstrings = (void *)info->hdr
2608 + info->sechdrs[info->hdr->e_shstrndx].sh_offset; 2612 + info->sechdrs[info->hdr->e_shstrndx].sh_offset;
2609 2613
2610 err = rewrite_section_headers(info); 2614 err = rewrite_section_headers(info, flags);
2611 if (err) 2615 if (err)
2612 return ERR_PTR(err); 2616 return ERR_PTR(err);
2613 2617
@@ -2645,11 +2649,14 @@ static struct module *setup_load_info(struct load_info *info)
2645 return mod; 2649 return mod;
2646} 2650}
2647 2651
2648static int check_modinfo(struct module *mod, struct load_info *info) 2652static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2649{ 2653{
2650 const char *modmagic = get_modinfo(info, "vermagic"); 2654 const char *modmagic = get_modinfo(info, "vermagic");
2651 int err; 2655 int err;
2652 2656
2657 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
2658 modmagic = NULL;
2659
2653 /* This is allowed: modprobe --force will invalidate it. */ 2660 /* This is allowed: modprobe --force will invalidate it. */
2654 if (!modmagic) { 2661 if (!modmagic) {
2655 err = try_to_force_load(mod, "bad vermagic"); 2662 err = try_to_force_load(mod, "bad vermagic");
@@ -2885,18 +2892,18 @@ int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
2885 return 0; 2892 return 0;
2886} 2893}
2887 2894
2888static struct module *layout_and_allocate(struct load_info *info) 2895static struct module *layout_and_allocate(struct load_info *info, int flags)
2889{ 2896{
2890 /* Module within temporary copy. */ 2897 /* Module within temporary copy. */
2891 struct module *mod; 2898 struct module *mod;
2892 Elf_Shdr *pcpusec; 2899 Elf_Shdr *pcpusec;
2893 int err; 2900 int err;
2894 2901
2895 mod = setup_load_info(info); 2902 mod = setup_load_info(info, flags);
2896 if (IS_ERR(mod)) 2903 if (IS_ERR(mod))
2897 return mod; 2904 return mod;
2898 2905
2899 err = check_modinfo(mod, info); 2906 err = check_modinfo(mod, info, flags);
2900 if (err) 2907 if (err)
2901 return ERR_PTR(err); 2908 return ERR_PTR(err);
2902 2909
@@ -3078,7 +3085,8 @@ static int may_init_module(void)
3078 3085
3079/* Allocate and load the module: note that size of section 0 is always 3086/* Allocate and load the module: note that size of section 0 is always
3080 zero, and we rely on this for optional sections. */ 3087 zero, and we rely on this for optional sections. */
3081static int load_module(struct load_info *info, const char __user *uargs) 3088static int load_module(struct load_info *info, const char __user *uargs,
3089 int flags)
3082{ 3090{
3083 struct module *mod, *old; 3091 struct module *mod, *old;
3084 long err; 3092 long err;
@@ -3092,7 +3100,7 @@ static int load_module(struct load_info *info, const char __user *uargs)
3092 goto free_copy; 3100 goto free_copy;
3093 3101
3094 /* Figure out module layout, and allocate all the memory. */ 3102 /* Figure out module layout, and allocate all the memory. */
3095 mod = layout_and_allocate(info); 3103 mod = layout_and_allocate(info, flags);
3096 if (IS_ERR(mod)) { 3104 if (IS_ERR(mod)) {
3097 err = PTR_ERR(mod); 3105 err = PTR_ERR(mod);
3098 goto free_copy; 3106 goto free_copy;
@@ -3241,10 +3249,10 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
3241 if (err) 3249 if (err)
3242 return err; 3250 return err;
3243 3251
3244 return load_module(&info, uargs); 3252 return load_module(&info, uargs, 0);
3245} 3253}
3246 3254
3247SYSCALL_DEFINE2(finit_module, int, fd, const char __user *, uargs) 3255SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
3248{ 3256{
3249 int err; 3257 int err;
3250 struct load_info info = { }; 3258 struct load_info info = { };
@@ -3253,13 +3261,17 @@ SYSCALL_DEFINE2(finit_module, int, fd, const char __user *, uargs)
3253 if (err) 3261 if (err)
3254 return err; 3262 return err;
3255 3263
3256 pr_debug("finit_module: fd=%d, uargs=%p\n", fd, uargs); 3264 pr_debug("finit_module: fd=%d, uargs=%p, flags=%i\n", fd, uargs, flags);
3265
3266 if (flags & ~(MODULE_INIT_IGNORE_MODVERSIONS
3267 |MODULE_INIT_IGNORE_VERMAGIC))
3268 return -EINVAL;
3257 3269
3258 err = copy_module_from_fd(fd, &info); 3270 err = copy_module_from_fd(fd, &info);
3259 if (err) 3271 if (err)
3260 return err; 3272 return err;
3261 3273
3262 return load_module(&info, uargs); 3274 return load_module(&info, uargs, flags);
3263} 3275}
3264 3276
3265static inline int within(unsigned long addr, void *start, unsigned long size) 3277static inline int within(unsigned long addr, void *start, unsigned long size)