aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:34:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:34:09 -0400
commitfb827ec68446c83e9e8754fa9b55aed27ecc4661 (patch)
treee953aedce01fa1c90a8e7b591e40310c3c1e7447
parentd5b4bb4d103cd601d8009f2d3a7e44586c9ae7cc (diff)
parentef26a5a6eadb7cd0637e1e9e246cd42505b8ec8c (diff)
Merge tag 'module-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
Pull module patches from Rusty Russell, who really sells them: "Three trivial patches of no real utility. Modules are boring." But to make things slightly more exciting, he adds: "Fortunately David Howells is looking to change this, with his module signing patchset. But that's for next merge window... Cheers, Rusty." * tag 'module-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus: Guard check in module loader against integer overflow modpost: use proper kernel style for autogenerated files modpost: Stop grab_file() from leaking filedescriptors if fstat() fails
-rw-r--r--kernel/module.c3
-rw-r--r--scripts/mod/modpost.c17
2 files changed, 12 insertions, 8 deletions
diff --git a/kernel/module.c b/kernel/module.c
index a4e60973ca73..4edbd9c11aca 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2429,7 +2429,8 @@ static int copy_and_check(struct load_info *info,
2429 goto free_hdr; 2429 goto free_hdr;
2430 } 2430 }
2431 2431
2432 if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) { 2432 if (hdr->e_shoff >= len ||
2433 hdr->e_shnum * sizeof(Elf_Shdr) > len - hdr->e_shoff) {
2433 err = -ENOEXEC; 2434 err = -ENOEXEC;
2434 goto free_hdr; 2435 goto free_hdr;
2435 } 2436 }
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index c4e7d1510f9d..0f84bb38eb0d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -337,17 +337,20 @@ static void sym_update_crc(const char *name, struct module *mod,
337void *grab_file(const char *filename, unsigned long *size) 337void *grab_file(const char *filename, unsigned long *size)
338{ 338{
339 struct stat st; 339 struct stat st;
340 void *map; 340 void *map = MAP_FAILED;
341 int fd; 341 int fd;
342 342
343 fd = open(filename, O_RDONLY); 343 fd = open(filename, O_RDONLY);
344 if (fd < 0 || fstat(fd, &st) != 0) 344 if (fd < 0)
345 return NULL; 345 return NULL;
346 if (fstat(fd, &st))
347 goto failed;
346 348
347 *size = st.st_size; 349 *size = st.st_size;
348 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); 350 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
349 close(fd);
350 351
352failed:
353 close(fd);
351 if (map == MAP_FAILED) 354 if (map == MAP_FAILED)
352 return NULL; 355 return NULL;
353 return map; 356 return map;
@@ -1850,14 +1853,14 @@ static void add_header(struct buffer *b, struct module *mod)
1850 buf_printf(b, "\n"); 1853 buf_printf(b, "\n");
1851 buf_printf(b, "struct module __this_module\n"); 1854 buf_printf(b, "struct module __this_module\n");
1852 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); 1855 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
1853 buf_printf(b, " .name = KBUILD_MODNAME,\n"); 1856 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
1854 if (mod->has_init) 1857 if (mod->has_init)
1855 buf_printf(b, " .init = init_module,\n"); 1858 buf_printf(b, "\t.init = init_module,\n");
1856 if (mod->has_cleanup) 1859 if (mod->has_cleanup)
1857 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" 1860 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
1858 " .exit = cleanup_module,\n" 1861 "\t.exit = cleanup_module,\n"
1859 "#endif\n"); 1862 "#endif\n");
1860 buf_printf(b, " .arch = MODULE_ARCH_INIT,\n"); 1863 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
1861 buf_printf(b, "};\n"); 1864 buf_printf(b, "};\n");
1862} 1865}
1863 1866