aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod
diff options
context:
space:
mode:
authorWanlong Gao <wanlong.gao@gmail.com>2017-06-30 10:07:03 -0400
committerJessica Yu <jeyu@kernel.org>2017-07-25 09:08:19 -0400
commit4fd3e4ef1f7e94299b42c2f473e196d0b8c114d0 (patch)
tree83acdc3581b72c357a89a3ebe639622e89237588 /scripts/mod
parent520eccdfe187591a51ea9ab4c1a024ae4d0f68d9 (diff)
modpost: abort if module name is too long
Module name has a limited length, but currently the build system allows the build finishing even if the module name is too long. CC /root/kprobe_example/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.mod.o /root/kprobe_example/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.mod.c:9:2: warning: initializer-string for array of chars is too long [enabled by default] .name = KBUILD_MODNAME, ^ but it's merely a warning. This patch adds the check of the module name length in modpost and stops the build properly. Signed-off-by: Wanlong Gao <wanlong.gao@gmail.com> Signed-off-by: Jessica Yu <jeyu@kernel.org>
Diffstat (limited to 'scripts/mod')
-rw-r--r--scripts/mod/modpost.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48397feb08fb..301c27740c5c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -47,6 +47,12 @@ enum export {
47 export_unused_gpl, export_gpl_future, export_unknown 47 export_unused_gpl, export_gpl_future, export_unknown
48}; 48};
49 49
50/* In kernel, this size is defined in linux/module.h;
51 * here we use Elf_Addr instead of long for covering cross-compile
52 */
53
54#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
55
50#define PRINTF __attribute__ ((format (printf, 1, 2))) 56#define PRINTF __attribute__ ((format (printf, 1, 2)))
51 57
52PRINTF void fatal(const char *fmt, ...) 58PRINTF void fatal(const char *fmt, ...)
@@ -2116,6 +2122,23 @@ static void check_exports(struct module *mod)
2116 } 2122 }
2117} 2123}
2118 2124
2125static int check_modname_len(struct module *mod)
2126{
2127 const char *mod_name;
2128
2129 mod_name = strrchr(mod->name, '/');
2130 if (mod_name == NULL)
2131 mod_name = mod->name;
2132 else
2133 mod_name++;
2134 if (strlen(mod_name) >= MODULE_NAME_LEN) {
2135 merror("module name is too long [%s.ko]\n", mod->name);
2136 return 1;
2137 }
2138
2139 return 0;
2140}
2141
2119/** 2142/**
2120 * Header for the generated file 2143 * Header for the generated file
2121 **/ 2144 **/
@@ -2155,11 +2178,6 @@ static void add_staging_flag(struct buffer *b, const char *name)
2155 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); 2178 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
2156} 2179}
2157 2180
2158/* In kernel, this size is defined in linux/module.h;
2159 * here we use Elf_Addr instead of long for covering cross-compile
2160 */
2161#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
2162
2163/** 2181/**
2164 * Record CRCs for unresolved symbols 2182 * Record CRCs for unresolved symbols
2165 **/ 2183 **/
@@ -2490,6 +2508,7 @@ int main(int argc, char **argv)
2490 2508
2491 buf.pos = 0; 2509 buf.pos = 0;
2492 2510
2511 err |= check_modname_len(mod);
2493 add_header(&buf, mod); 2512 add_header(&buf, mod);
2494 add_intree_flag(&buf, !external_module); 2513 add_intree_flag(&buf, !external_module);
2495 add_staging_flag(&buf, mod->name); 2514 add_staging_flag(&buf, mod->name);