From 3a611c3cfba2106aed3187b90903855e776e2761 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 27 Jul 2014 07:23:01 +0930 Subject: modules: Fix build error in moduleloader.h Fengguang Wu's build bot detected that if moduleloader.h is included in a C file (used by ftrace and kprobes to access module_alloc() when available), that it can fail to build if CONFIG_MODULES and CONFIG_MODULES_USE_ELF_REL is not defined. This is because there's a printk() that dereferences struct module to print the name of the module. But as struct module does not exist when CONFIG_MODULES is not defined we get this error: include/linux/moduleloader.h: In function 'apply_relocate': >> include/linux/moduleloader.h:48:63: error: dereferencing pointer to >> incomplete type printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); ^ Reported-by: kbuild test robot Based-on-the-true-story-by: Steven Rostedt Confirms-rustys-story-ends-the-same-by: Steven Rostedt Signed-off-by: Rusty Russell --- include/linux/moduleloader.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 560ca53a75fa..7eeb9bbfb816 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -45,7 +45,8 @@ static inline int apply_relocate(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me)); return -ENOEXEC; } #endif @@ -67,7 +68,8 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me)); return -ENOEXEC; } #endif -- cgit v1.2.3-59-g8ed1b From 9b20a352d78a7651aa68a9220f77ccb03009d892 Mon Sep 17 00:00:00 2001 From: Petr Mladek Date: Sun, 27 Jul 2014 07:24:01 +0930 Subject: module: add within_module() function It is just a small optimization that allows to replace few occurrences of within_module_init() || within_module_core() with a single call. Signed-off-by: Petr Mladek Signed-off-by: Rusty Russell --- include/linux/module.h | 5 +++++ kernel/module.c | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index f520a767c86c..61d8fb2d0873 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -408,6 +408,11 @@ static inline int within_module_init(unsigned long addr, const struct module *mo addr < (unsigned long)mod->module_init + mod->init_size; } +static inline int within_module(unsigned long addr, const struct module *mod) +{ + return within_module_init(addr, mod) || within_module_core(addr, mod); +} + /* Search for module by name: must hold module_mutex. */ struct module *find_module(const char *name); diff --git a/kernel/module.c b/kernel/module.c index 81e727cf6df9..e87fdd2fc3c2 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3448,8 +3448,7 @@ const char *module_address_lookup(unsigned long addr, list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; - if (within_module_init(addr, mod) || - within_module_core(addr, mod)) { + if (within_module(addr, mod)) { if (modname) *modname = mod->name; ret = get_ksymbol(mod, addr, size, offset); @@ -3473,8 +3472,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; - if (within_module_init(addr, mod) || - within_module_core(addr, mod)) { + if (within_module(addr, mod)) { const char *sym; sym = get_ksymbol(mod, addr, NULL, NULL); @@ -3499,8 +3497,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; - if (within_module_init(addr, mod) || - within_module_core(addr, mod)) { + if (within_module(addr, mod)) { const char *sym; sym = get_ksymbol(mod, addr, size, offset); @@ -3764,8 +3761,7 @@ struct module *__module_address(unsigned long addr) list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; - if (within_module_core(addr, mod) - || within_module_init(addr, mod)) + if (within_module(addr, mod)) return mod; } return NULL; -- cgit v1.2.3-59-g8ed1b From 76681c8faa07f9e07caa3cc69f235c8719b2a6ea Mon Sep 17 00:00:00 2001 From: Petr Mladek Date: Sun, 27 Jul 2014 07:25:01 +0930 Subject: module: return bool from within_module*() The within_module*() functions return only true or false. Let's use bool as the return type. Note that it should not change kABI because these are inline functions. Signed-off-by: Petr Mladek Signed-off-by: Rusty Russell --- include/linux/module.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 61d8fb2d0873..71f282a4e307 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -396,19 +396,21 @@ bool is_module_address(unsigned long addr); bool is_module_percpu_address(unsigned long addr); bool is_module_text_address(unsigned long addr); -static inline int within_module_core(unsigned long addr, const struct module *mod) +static inline bool within_module_core(unsigned long addr, + const struct module *mod) { return (unsigned long)mod->module_core <= addr && addr < (unsigned long)mod->module_core + mod->core_size; } -static inline int within_module_init(unsigned long addr, const struct module *mod) +static inline bool within_module_init(unsigned long addr, + const struct module *mod) { return (unsigned long)mod->module_init <= addr && addr < (unsigned long)mod->module_init + mod->init_size; } -static inline int within_module(unsigned long addr, const struct module *mod) +static inline bool within_module(unsigned long addr, const struct module *mod) { return within_module_init(addr, mod) || within_module_core(addr, mod); } -- cgit v1.2.3-59-g8ed1b From 37549e94c77a94a9c32b5ae3313a3801cb66adf9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 27 Jul 2014 07:26:01 +0930 Subject: sysfs: disallow world-writable files. This check was introduced in 2006 by Alexey Dobriyan (9774a1f54f173) for module parameters; we removed it when we unified the check into VERIFY_OCTAL_PERMISSIONS() as sysfs didn't have the same requirement. Now all those users are fixed, reintroduce it. Cc: Alexey Dobriyan Cc: Dave Jones Cc: Joe Perches Signed-off-by: Rusty Russell --- include/linux/kernel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4c52907a6d8b..43e1c6a9683e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -849,5 +849,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } /* User perms >= group perms >= other perms */ \ BUILD_BUG_ON_ZERO(((perms) >> 6) < (((perms) >> 3) & 7)) + \ BUILD_BUG_ON_ZERO((((perms) >> 3) & 7) < ((perms) & 7)) + \ + /* Other writable? Generally considered a bad idea. */ \ + BUILD_BUG_ON_ZERO((perms) & 2) + \ (perms)) #endif -- cgit v1.2.3-59-g8ed1b From fcd38ed0ff263156c3917c70c2fb0b7e91bfeab1 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Sun, 27 Jul 2014 07:27:01 +0930 Subject: scripts: modpost: fix compilation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scripts/mod/modpost.c triggers the following warning: scripts/mod/modpost.c: In function ‘remove_dot’: scripts/mod/modpost.c:1710:10: warning: ignoring return value of ‘strtoul’, declared with attribute warn_unused_result [-Wunused-result] The remove_dot function that calls strtoul does not care about the numeric value of the string that is parsed but only looks for the end of the numeric sequence. As such, it's equivalent to just skip over all digits. Signed-off-by: Michal Nazarewicz Signed-off-by: Rusty Russell --- scripts/mod/modpost.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9d9c5b905b35..5ba203b9eddf 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1703,12 +1703,11 @@ static void check_sec_ref(struct module *mod, const char *modname, static char *remove_dot(char *s) { - char *end; - int n = strcspn(s, "."); + size_t n = strcspn(s, "."); - if (n > 0 && s[n] != 0) { - strtoul(s + n + 1, &end, 10); - if (end > s + n + 1 && (*end == '.' || *end == 0)) + if (n && s[n]) { + size_t m = strspn(s + n + 1, "0123456789"); + if (m && (s[n + m] == '.' || s[n + m] == 0)) s[n] = 0; } return s; -- cgit v1.2.3-59-g8ed1b From a0d8f8037468a3b5f964417f71853ccf301b9f39 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Sun, 27 Jul 2014 07:28:01 +0930 Subject: scripts: modpost: Remove numeric suffix pattern matching For several years, the pattern "foo$" has effectively been treated as equivalent to "foo" due to a bug in the (misnamed) helper number_prefix(). This hasn't been observed to cause any problems, so remove the broken $ functionality and change all foo$ patterns to foo. Signed-off-by: Rasmus Villemoes Signed-off-by: Rusty Russell --- scripts/mod/modpost.c | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 5ba203b9eddf..091d90573b63 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -772,32 +772,10 @@ static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) sechdr->sh_name; } -/* if sym is empty or point to a string - * like ".[0-9]+" then return 1. - * This is the optional prefix added by ld to some sections - */ -static int number_prefix(const char *sym) -{ - if (*sym++ == '\0') - return 1; - if (*sym != '.') - return 0; - do { - char c = *sym++; - if (c < '0' || c > '9') - return 0; - } while (*sym); - return 1; -} - /* The pattern is an array of simple patterns. * "foo" will match an exact string equal to "foo" * "*foo" will match a string that ends with "foo" * "foo*" will match a string that begins with "foo" - * "foo$" will match a string equal to "foo" or "foo.1" - * where the '1' can be any number including several digits. - * The $ syntax is for sections where ld append a dot number - * to make section name unique. */ static int match(const char *sym, const char * const pat[]) { @@ -816,13 +794,6 @@ static int match(const char *sym, const char * const pat[]) if (strncmp(sym, p, strlen(p) - 1) == 0) return 1; } - /* "foo$" */ - else if (*endp == '$') { - if (strncmp(sym, p, strlen(p) - 1) == 0) { - if (number_prefix(sym + strlen(p) - 1)) - return 1; - } - } /* no wildcards */ else { if (strcmp(p, sym) == 0) @@ -880,20 +851,20 @@ static void check_section(const char *modname, struct elf_info *elf, #define ALL_INIT_DATA_SECTIONS \ - ".init.setup$", ".init.rodata$", ".meminit.rodata$", \ - ".init.data$", ".meminit.data$" + ".init.setup", ".init.rodata", ".meminit.rodata", \ + ".init.data", ".meminit.data" #define ALL_EXIT_DATA_SECTIONS \ - ".exit.data$", ".memexit.data$" + ".exit.data", ".memexit.data" #define ALL_INIT_TEXT_SECTIONS \ - ".init.text$", ".meminit.text$" + ".init.text", ".meminit.text" #define ALL_EXIT_TEXT_SECTIONS \ - ".exit.text$", ".memexit.text$" + ".exit.text", ".memexit.text" #define ALL_PCI_INIT_SECTIONS \ - ".pci_fixup_early$", ".pci_fixup_header$", ".pci_fixup_final$", \ - ".pci_fixup_enable$", ".pci_fixup_resume$", \ - ".pci_fixup_resume_early$", ".pci_fixup_suspend$" + ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \ + ".pci_fixup_enable", ".pci_fixup_resume", \ + ".pci_fixup_resume_early", ".pci_fixup_suspend" #define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS #define ALL_XXXEXIT_SECTIONS MEM_EXIT_SECTIONS @@ -901,8 +872,8 @@ static void check_section(const char *modname, struct elf_info *elf, #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS -#define DATA_SECTIONS ".data$", ".data.rel$" -#define TEXT_SECTIONS ".text$", ".text.unlikely$" +#define DATA_SECTIONS ".data", ".data.rel" +#define TEXT_SECTIONS ".text", ".text.unlikely" #define INIT_SECTIONS ".init.*" #define MEM_INIT_SECTIONS ".meminit.*" -- cgit v1.2.3-59-g8ed1b From 2e3a10a1551d6ceea005e6a62ca58183b8976217 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Jul 2014 07:29:01 +0930 Subject: ARM: avoid ARM binutils leaking ELF local symbols Symbols starting with .L are ELF local symbols and should not appear in ELF symbol tables. However, unfortunately ARM binutils leaks the .LANCHOR symbols into the symbol table, which leads kallsyms to report these symbols rather than the real name. It is not very useful when %pf reports symbols against these leaked .LANCHOR symbols. Arrange for kallsyms to ignore these symbols using the same mechanism that is used for the ARM mapping symbols. Signed-off-by: Russell King Signed-off-by: Rusty Russell --- kernel/module.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index e87fdd2fc3c2..cd9bce918cdf 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3385,6 +3385,8 @@ static inline int within(unsigned long addr, void *start, unsigned long size) */ static inline int is_arm_mapping_symbol(const char *str) { + if (str[0] == '.' && str[1] == 'L') + return true; return str[0] == '$' && strchr("atd", str[1]) && (str[2] == '\0' || str[2] == '.'); } -- cgit v1.2.3-59-g8ed1b From 82867936b00a8b73d38796577a66357024cd22fc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 6 Aug 2014 10:15:36 +0930 Subject: drivers/video/fbdev/s3c2410fb.c: don't make debug world-writable. We don't want random users to be able to spam the logs, and commit 37549e94c77a94a9c32b5ae3313a3801cb66adf9 (sysfs: disallow world-writable files.) finally makes this a build error. Signed-off-by: Rusty Russell --- drivers/video/fbdev/s3c2410fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/s3c2410fb.c b/drivers/video/fbdev/s3c2410fb.c index 81af5a63e9e1..6796d9d6c871 100644 --- a/drivers/video/fbdev/s3c2410fb.c +++ b/drivers/video/fbdev/s3c2410fb.c @@ -616,7 +616,7 @@ static int s3c2410fb_debug_store(struct device *dev, return len; } -static DEVICE_ATTR(debug, 0666, s3c2410fb_debug_show, s3c2410fb_debug_store); +static DEVICE_ATTR(debug, 0664, s3c2410fb_debug_show, s3c2410fb_debug_store); static struct fb_ops s3c2410fb_ops = { .owner = THIS_MODULE, -- cgit v1.2.3-59-g8ed1b From 6656c21ca10e54a84673d0ec2f0cf5f676e66a40 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 6 Aug 2014 10:15:36 +0930 Subject: arch/powerpc/platforms/powernv/opal-elog.c: fix world-writable sysfs files If you don't have a store function, you're not writable anyway! Signed-off-by: Rusty Russell Acked-by: Stewart Smith --- arch/powerpc/platforms/powernv/opal-elog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-elog.c b/arch/powerpc/platforms/powernv/opal-elog.c index 10268c41d830..925bad993e30 100644 --- a/arch/powerpc/platforms/powernv/opal-elog.c +++ b/arch/powerpc/platforms/powernv/opal-elog.c @@ -82,9 +82,9 @@ static ssize_t elog_ack_store(struct elog_obj *elog_obj, } static struct elog_attribute id_attribute = - __ATTR(id, 0666, elog_id_show, NULL); + __ATTR(id, S_IRUGO, elog_id_show, NULL); static struct elog_attribute type_attribute = - __ATTR(type, 0666, elog_type_show, NULL); + __ATTR(type, S_IRUGO, elog_type_show, NULL); static struct elog_attribute ack_attribute = __ATTR(acknowledge, 0660, elog_ack_show, elog_ack_store); -- cgit v1.2.3-59-g8ed1b From 76215b04fd297c008b91ece732ed36e67e0181fa Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 7 Aug 2014 22:38:55 +0930 Subject: arch/powerpc/platforms/powernv/opal-dump.c: fix world-writable sysfs files If you don't have a store function, you're not writable anyway! Signed-off-by: Rusty Russell --- arch/powerpc/platforms/powernv/opal-dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-dump.c b/arch/powerpc/platforms/powernv/opal-dump.c index 788a1977b9a5..85bb8fff7947 100644 --- a/arch/powerpc/platforms/powernv/opal-dump.c +++ b/arch/powerpc/platforms/powernv/opal-dump.c @@ -102,9 +102,9 @@ static ssize_t dump_ack_store(struct dump_obj *dump_obj, * due to the dynamic size of the dump */ static struct dump_attribute id_attribute = - __ATTR(id, 0666, dump_id_show, NULL); + __ATTR(id, S_IRUGO, dump_id_show, NULL); static struct dump_attribute type_attribute = - __ATTR(type, 0666, dump_type_show, NULL); + __ATTR(type, S_IRUGO, dump_type_show, NULL); static struct dump_attribute ack_attribute = __ATTR(acknowledge, 0660, dump_ack_show, dump_ack_store); -- cgit v1.2.3-59-g8ed1b