Skip to content

Commit

Permalink
Merge tag 'module-for-linus' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/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
  • Loading branch information
torvalds committed May 24, 2012
2 parents d5b4bb4 + ef26a5a commit fb827ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,8 @@ static int copy_and_check(struct load_info *info,
goto free_hdr;
}

if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) {
if (hdr->e_shoff >= len ||
hdr->e_shnum * sizeof(Elf_Shdr) > len - hdr->e_shoff) {
err = -ENOEXEC;
goto free_hdr;
}
Expand Down
17 changes: 10 additions & 7 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,20 @@ static void sym_update_crc(const char *name, struct module *mod,
void *grab_file(const char *filename, unsigned long *size)
{
struct stat st;
void *map;
void *map = MAP_FAILED;
int fd;

fd = open(filename, O_RDONLY);
if (fd < 0 || fstat(fd, &st) != 0)
if (fd < 0)
return NULL;
if (fstat(fd, &st))
goto failed;

*size = st.st_size;
map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);

failed:
close(fd);
if (map == MAP_FAILED)
return NULL;
return map;
Expand Down Expand Up @@ -1850,14 +1853,14 @@ static void add_header(struct buffer *b, struct module *mod)
buf_printf(b, "\n");
buf_printf(b, "struct module __this_module\n");
buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
buf_printf(b, " .name = KBUILD_MODNAME,\n");
buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
if (mod->has_init)
buf_printf(b, " .init = init_module,\n");
buf_printf(b, "\t.init = init_module,\n");
if (mod->has_cleanup)
buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
" .exit = cleanup_module,\n"
"\t.exit = cleanup_module,\n"
"#endif\n");
buf_printf(b, " .arch = MODULE_ARCH_INIT,\n");
buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
buf_printf(b, "};\n");
}

Expand Down

0 comments on commit fb827ec

Please sign in to comment.