modpost: abort if a module symbol is too long
[firefly-linux-kernel-4.4.55.git] / scripts / mod / modpost.c
index 12d3db3bd46b491542090cd2db01637754467e99..d583c98fde317b0ba145e1b3159aad2b10d58dd4 100644 (file)
@@ -2133,6 +2133,11 @@ static void add_staging_flag(struct buffer *b, const char *name)
                buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
 }
 
+/* In kernel, this size is defined in linux/module.h;
+ * here we use Elf_Addr instead of long for covering cross-compile
+ */
+#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
+
 /**
  * Record CRCs for unresolved symbols
  **/
@@ -2177,6 +2182,12 @@ static int add_versions(struct buffer *b, struct module *mod)
                                s->name, mod->name);
                        continue;
                }
+               if (strlen(s->name) >= MODULE_NAME_LEN) {
+                       merror("too long symbol \"%s\" [%s.ko]\n",
+                              s->name, mod->name);
+                       err = 1;
+                       break;
+               }
                buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n",
                           s->crc, s->name);
        }