]> git.ipfire.org Git - people/ms/linux.git/blobdiff - scripts/mod/modpost.c
Importing "grsecurity-3.1-3.19.2-201503201903.patch"
[people/ms/linux.git] / scripts / mod / modpost.c
index d439856f81760b7e12497e2167d641120ccb4a39..10c1eacf774930915fd1b4ad239578b1f091863a 100644 (file)
@@ -921,6 +921,7 @@ enum mismatch {
        ANY_INIT_TO_ANY_EXIT,
        ANY_EXIT_TO_ANY_INIT,
        EXPORT_TO_INIT_EXIT,
+       DATA_TO_TEXT
 };
 
 struct sectioncheck {
@@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
        .tosec   = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
        .mismatch = EXPORT_TO_INIT_EXIT,
        .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
+},
+/* Do not reference code from writable data */
+{
+       .fromsec = { DATA_SECTIONS, NULL },
+       .tosec   = { TEXT_SECTIONS, NULL },
+       .mismatch = DATA_TO_TEXT
 }
 };
 
@@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
                        continue;
                if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
                        continue;
-               if (sym->st_value == addr)
-                       return sym;
                /* Find a symbol nearby - addr are maybe negative */
                d = sym->st_value - addr;
+               if (d == 0)
+                       return sym;
                if (d < 0)
                        d = addr - sym->st_value;
                if (d < distance) {
@@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
                tosym, prl_to, prl_to, tosym);
                free(prl_to);
                break;
+       case DATA_TO_TEXT:
+#if 0
+               fprintf(stderr,
+               "The %s %s:%s references\n"
+               "the %s %s:%s%s\n",
+               from, fromsec, fromsym, to, tosec, tosym, to_p);
+#endif
+               break;
        }
        fprintf(stderr, "\n");
 }
@@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
 static void check_sec_ref(struct module *mod, const char *modname,
                          struct elf_info *elf)
 {
-       int i;
+       unsigned int i;
        Elf_Shdr *sechdrs = elf->sechdrs;
 
        /* Walk through all sections */
@@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
        va_end(ap);
 }
 
-void buf_write(struct buffer *buf, const char *s, int len)
+void buf_write(struct buffer *buf, const char *s, unsigned int len)
 {
        if (buf->size - buf->pos < len) {
                buf->size += len + SZ;
@@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
        if (fstat(fileno(file), &st) < 0)
                goto close_write;
 
-       if (st.st_size != b->pos)
+       if (st.st_size != (off_t)b->pos)
                goto close_write;
 
        tmp = NOFAIL(malloc(b->pos));