X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/3eb844672eec8235d234c882ec4b00e3c217dd0b..842f5cacc45a3ab140fb625f02170aa2c9197f86:/package/busybox/patches/470-insmod_search.patch diff --git a/package/busybox/patches/470-insmod_search.patch b/package/busybox/patches/470-insmod_search.patch index 29f1527fe..2a08fb74f 100644 --- a/package/busybox/patches/470-insmod_search.patch +++ b/package/busybox/patches/470-insmod_search.patch @@ -1,8 +1,6 @@ -Index: busybox-1.7.2/modutils/insmod.c -=================================================================== ---- busybox-1.7.2.orig/modutils/insmod.c 2007-10-24 18:20:56.857757117 +0200 -+++ busybox-1.7.2/modutils/insmod.c 2007-10-24 18:38:27.701641299 +0200 -@@ -61,19 +61,114 @@ +--- a/modutils/insmod.c ++++ b/modutils/insmod.c +@@ -61,21 +61,117 @@ #include "libbb.h" #include #include @@ -17,18 +15,19 @@ Index: busybox-1.7.2/modutils/insmod.c #define ENABLE_FEATURE_2_4_MODULES 1 #endif --#if !ENABLE_FEATURE_2_4_MODULES --#define insmod_ng_main insmod_main -+#if ENABLE_FEATURE_2_4_MODULES -+int insmod_main_24(int argc, char **argv); - #endif +-/* +- * Big piece of 2.4-specific code +- */ + #if ENABLE_FEATURE_2_4_MODULES - ++int insmod_main_24(int argc, char **argv); ++#endif #if ENABLE_FEATURE_2_6_MODULES --extern int insmod_ng_main( int argc, char **argv); +-static int insmod_ng_main(int argc, char **argv); +int insmod_main_26(int argc, char **argv); #endif -+int insmod_main(int argc, char **argv); -+ ++int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; + +static char *g_filename = NULL; +#define _PATH_MODULES "/lib/modules" + @@ -36,20 +35,18 @@ Index: busybox-1.7.2/modutils/insmod.c + void *userdata, int depth) +{ + char *fullname = (char *) userdata; ++ char *tmp; + + if (fullname[0] == '\0') + return FALSE; -+ else { -+ char *tmp, *tmp1 = xstrdup(filename); -+ tmp = bb_get_last_path_component(tmp1); -+ if (strcmp(tmp, fullname) == 0) { -+ free(tmp1); -+ /* Stop searching if we find a match */ -+ g_filename = xstrdup(filename); -+ return FALSE; -+ } -+ free(tmp1); ++ ++ tmp = bb_get_last_path_component_nostrip(filename); ++ if (strcmp(tmp, fullname) == 0) { ++ /* Stop searching if we find a match */ ++ g_filename = xstrdup(filename); ++ return FALSE; + } ++ + return TRUE; +} + @@ -118,61 +115,246 @@ Index: busybox-1.7.2/modutils/insmod.c + + return ret; +} ++ ++/* ++ * Big piece of 2.4-specific code ++ */ ++#if ENABLE_FEATURE_2_4_MODULES + #if ENABLE_FEATURE_INSMOD_LOADINKMEM + #define LOADBITS 0 + #else +@@ -184,7 +280,6 @@ + /* Microblaze */ + #if defined(__microblaze__) + #define USE_SINGLE +-#include + #define MATCH_MACHINE(x) (x == EM_XILINX_MICROBLAZE) + #define SHT_RELM SHT_RELA + #define Elf32_RelM Elf32_Rela +@@ -452,7 +547,7 @@ + /* The system calls unchanged between 2.0 and 2.1. */ + unsigned long create_module(const char *, size_t); +-int delete_module(const char *module, unsigned int flags); ++int delete_module(const char *); - #if ENABLE_FEATURE_2_4_MODULES -@@ -677,7 +772,6 @@ - #endif + #endif /* module.h */ +@@ -652,7 +747,7 @@ + + static enum obj_reloc arch_apply_relocation(struct obj_file *f, + struct obj_section *targsec, +- /*struct obj_section *symsec,*/ ++ struct obj_section *symsec, + struct obj_symbol *sym, + ElfW(RelM) *rel, ElfW(Addr) value); --#define _PATH_MODULES "/lib/modules" +@@ -673,6 +768,7 @@ + #define SPFX "" + #endif + ++ enum { STRVERSIONLEN = 64 }; /*======================================================================*/ -@@ -790,37 +884,6 @@ - static int n_ext_modules_used; - extern int delete_module(const char *); +@@ -788,28 +884,6 @@ + static char *m_fullName; + --static char *m_filename; --static char *m_fullName; -- -- -/*======================================================================*/ - - --static int check_module_name_match(const char *filename, struct stat *statbuf, -- void *userdata, int depth) +-static int check_module_name_match(const char *filename, +- struct stat *statbuf ATTRIBUTE_UNUSED, +- void *userdata, int depth ATTRIBUTE_UNUSED) -{ - char *fullname = (char *) userdata; +- char *tmp; - - if (fullname[0] == '\0') - return FALSE; -- else { -- char *tmp, *tmp1 = xstrdup(filename); -- tmp = bb_get_last_path_component(tmp1); -- if (strcmp(tmp, fullname) == 0) { -- free(tmp1); -- /* Stop searching if we find a match */ -- m_filename = xstrdup(filename); -- return FALSE; -- } -- free(tmp1); +- +- tmp = bb_get_last_path_component_nostrip(filename); +- if (strcmp(tmp, fullname) == 0) { +- /* Stop searching if we find a match */ +- m_filename = xstrdup(filename); +- return FALSE; - } - return TRUE; -} - -- --/*======================================================================*/ -- - static struct obj_file *arch_new_file(void) + + /*======================================================================*/ + +@@ -835,27 +909,18 @@ + static enum obj_reloc + arch_apply_relocation(struct obj_file *f, + struct obj_section *targsec, +- /*struct obj_section *symsec,*/ ++ struct obj_section *symsec, + struct obj_symbol *sym, + ElfW(RelM) *rel, ElfW(Addr) v) + { +-#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) \ +- || defined(__sh__) || defined(__s390__) || defined(__x86_64__) + struct arch_file *ifile = (struct arch_file *) f; +-#endif + enum obj_reloc ret = obj_reloc_ok; + ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset); +-#if defined(__arm__) || defined(__H8300H__) || defined(__H8300S__) \ +- || defined(__i386__) || defined(__mc68000__) || defined(__microblaze__) \ +- || defined(__mips__) || defined(__nios2__) || defined(__powerpc__) \ +- || defined(__s390__) || defined(__sh__) || defined(__x86_64__) + ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset; +-#endif + #if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES) + struct arch_symbol *isym = (struct arch_symbol *) sym; + #endif +-#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) \ +- || defined(__sh__) || defined(__s390__) ++#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) || defined(__sh__) || defined(__s390__) + #if defined(USE_GOT_ENTRIES) + ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0; + #endif +@@ -953,7 +1018,6 @@ + + case R_386_PLT32: + case R_386_PC32: +- case R_386_GOTOFF: + *loc += v - dot; + break; + +@@ -972,6 +1036,9 @@ + + case R_386_GOT32: + goto bb_use_got; ++ ++ case R_386_GOTOFF: ++ *loc += v - got; + break; + + #elif defined(__microblaze__) +@@ -1758,7 +1825,7 @@ + + #if defined(USE_SINGLE) + +-static int arch_single_init(/*ElfW(RelM) *rel,*/ struct arch_single_entry *single, ++static int arch_single_init(ElfW(RelM) *rel, struct arch_single_entry *single, + int offset, int size) + { + if (single->allocated == 0) { +@@ -1906,7 +1973,7 @@ + #if defined(USE_GOT_ENTRIES) + if (got_allocate) { + got_offset += arch_single_init( +- /*rel,*/ &intsym->gotent, ++ rel, &intsym->gotent, + got_offset, GOT_ENTRY_SIZE); + + got_needed = 1; +@@ -1920,7 +1987,7 @@ + plt_offset, PLT_ENTRY_SIZE); + #else + plt_offset += arch_single_init( +- /*rel,*/ &intsym->pltent, ++ rel, &intsym->pltent, + plt_offset, PLT_ENTRY_SIZE); + #endif + plt_needed = 1; +@@ -1958,8 +2025,7 @@ + while (n > 0) { + ch = *name++; + h = (h << 4) + ch; +- g = (h & 0xf0000000); +- if (g != 0) { ++ if ((g = (h & 0xf0000000)) != 0) { + h ^= g >> 24; + h &= ~g; + } +@@ -2038,7 +2104,7 @@ + int n_type = ELF_ST_TYPE(info); + int n_binding = ELF_ST_BIND(info); + +- for (sym = f->symtab[hash]; sym; sym = sym->next) { ++ for (sym = f->symtab[hash]; sym; sym = sym->next) + if (f->symbol_cmp(sym->name, name) == 0) { + int o_secidx = sym->secidx; + int o_info = sym->info; +@@ -2097,14 +2163,14 @@ + return sym; + } + } +- } + + /* Completely new symbol. */ + sym = arch_new_symbol(); + sym->next = f->symtab[hash]; + f->symtab[hash] = sym; + sym->ksymidx = -1; +- if (ELF_ST_BIND(info) == STB_LOCAL && symidx != (unsigned long)(-1)) { ++ ++ if (ELF_ST_BIND(info) == STB_LOCAL && symidx != -1) { + if (symidx >= f->local_symtab_size) + bb_error_msg("local symbol %s with index %ld exceeds local_symtab_size %ld", + name, (long) symidx, (long) f->local_symtab_size); +@@ -3227,7 +3293,7 @@ + + /* Do it! */ + switch (arch_apply_relocation +- (f, targsec, /*symsec,*/ intsym, rel, value) ++ (f, targsec, symsec, intsym, rel, value) + ) { + case obj_reloc_ok: + break; +@@ -3306,11 +3372,11 @@ + + /*======================================================================*/ + +-static struct obj_file *obj_load(FILE * fp, int loadprogbits ATTRIBUTE_UNUSED) ++static struct obj_file *obj_load(FILE * fp, int loadprogbits) + { + struct obj_file *f; + ElfW(Shdr) * section_headers; +- size_t shnum, i; ++ int shnum, i; + char *shstrtab; + + /* Read the file header. */ +@@ -3582,7 +3648,7 @@ + while (ptr < endptr) { + value = strchr(ptr, '='); + if (value && strncmp(ptr, "license", value-ptr) == 0) { +- unsigned i; ++ int i; + if (license) + *license = value+1; + for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) { +@@ -3686,9 +3752,6 @@ + * start of some sections. this info is used by ksymoops to do better + * debugging. + */ +-#if !ENABLE_FEATURE_INSMOD_VERSION_CHECKING +-#define get_module_version(f, str) get_module_version(str) +-#endif + static int + get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) { - struct arch_file *f; -@@ -3952,145 +4015,57 @@ +@@ -3721,8 +3784,7 @@ + struct obj_symbol *sym; + char *name, *absolute_filename; + char str[STRVERSIONLEN]; +- unsigned i; +- int l, lm_name, lfilename, use_ksymtab, version; ++ int i, l, lm_name, lfilename, use_ksymtab, version; + struct stat statbuf; + + /* WARNING: was using realpath, but replaced by readlink to stop using +@@ -3909,145 +3971,57 @@ void print_load_map(struct obj_file *f); #endif --int insmod_main( int argc, char **argv); --int insmod_main( int argc, char **argv) +-int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +-int insmod_main(int argc, char **argv) +int insmod_main_24( int argc, char **argv) { char *opt_o, *arg1; @@ -183,7 +365,7 @@ Index: busybox-1.7.2/modutils/insmod.c ElfW(Addr) m_addr; struct obj_file *f; - struct stat st; -- char *m_name = 0; +- char *m_name = NULL; - int exit_status = EXIT_FAILURE; + char *tmp = NULL, *m_name = NULL; + int ret = EINVAL; @@ -194,12 +376,11 @@ Index: busybox-1.7.2/modutils/insmod.c int m_version, m_crcs; #endif -#if ENABLE_FEATURE_CLEAN_UP -- FILE *fp = 0; + FILE *fp = NULL; -#else - FILE *fp; -#endif - int k_version = 0; -+ FILE *fp = NULL; + int k_version; struct utsname myuname; @@ -247,8 +428,8 @@ Index: busybox-1.7.2/modutils/insmod.c - len -= 2; - tmp[len] = '\0'; - } -- +- -#if ENABLE_FEATURE_2_6_MODULES - if (k_version > 4) - m_fullName = xasprintf("%s.ko", tmp); @@ -263,12 +444,10 @@ Index: busybox-1.7.2/modutils/insmod.c - m_name = tmp; - } else { - free(tmp1); -- tmp1 = 0; /* flag for free(m_name) before exit() */ -+ tmp = xstrdup(arg1); -+ m_name = basename(tmp); - } - -- /* Get a filedesc for the module. Check we we have a complete path */ +- tmp1 = NULL; /* flag for free(m_name) before exit() */ +- } +- +- /* Get a filedesc for the module. Check that we have a complete path */ - if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode) - || (fp = fopen(arg1, "r")) == NULL - ) { @@ -277,48 +456,50 @@ Index: busybox-1.7.2/modutils/insmod.c - if (k_version) { /* uname succeedd */ - char *module_dir; - char *tmdn; -- char real_module_dir[FILENAME_MAX]; - -- tmdn = concat_path_file(_PATH_MODULES, myuname.release); +- tmdn = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release); - /* Jump through hoops in case /lib/modules/`uname -r` - * is a symlink. We do not want recursive_action to - * follow symlinks, but we do want to follow the - * /lib/modules/`uname -r` dir, So resolve it ourselves - * if it is a link... */ -- if (realpath(tmdn, real_module_dir) == NULL) -- module_dir = tmdn; -- else -- module_dir = real_module_dir; +- module_dir = xmalloc_readlink(tmdn); +- if (!module_dir) +- module_dir = xstrdup(tmdn); - recursive_action(module_dir, ACTION_RECURSE, -- check_module_name_match, 0, m_fullName, 0); +- check_module_name_match, NULL, m_fullName, 0); +- free(module_dir); - free(tmdn); - } - - /* Check if we have found anything yet */ -- if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) { -- char module_dir[FILENAME_MAX]; +- if (!m_filename || ((fp = fopen(m_filename, "r")) == NULL)) { +- int r; +- char *module_dir; - - free(m_filename); -- m_filename = 0; -- if (realpath (_PATH_MODULES, module_dir) == NULL) -- strcpy(module_dir, _PATH_MODULES); +- m_filename = NULL; +- module_dir = xmalloc_readlink(CONFIG_DEFAULT_MODULES_DIR); +- if (!module_dir) +- module_dir = xstrdup(CONFIG_DEFAULT_MODULES_DIR); - /* No module found under /lib/modules/`uname -r`, this - * time cast the net a bit wider. Search /lib/modules/ */ -- if (!recursive_action(module_dir, ACTION_RECURSE, -- check_module_name_match, 0, m_fullName, 0) +- r = recursive_action(module_dir, ACTION_RECURSE, +- check_module_name_match, NULL, m_fullName, 0); +- if (r) +- bb_error_msg_and_die("%s: module not found", m_fullName); +- free(module_dir); +- if (m_filename == NULL +- || ((fp = fopen(m_filename, "r")) == NULL) - ) { -- if (m_filename == 0 -- || ((fp = fopen(m_filename, "r")) == NULL) -- ) { -- bb_error_msg("%s: no module by that name found", m_fullName); -- goto out; -- } -- } else -- bb_error_msg_and_die("%s: no module by that name found", m_fullName); -- } +- bb_error_msg_and_die("%s: module not found", m_fullName); +- } ++ tmp = xstrdup(arg1); ++ m_name = basename(tmp); + } - } else - m_filename = xstrdup(arg1); -- + - if (flag_verbose) - printf("Using %s\n", m_filename); - @@ -335,8 +516,8 @@ Index: busybox-1.7.2/modutils/insmod.c -#endif f = obj_load(fp, LOADBITS); - if (f == NULL) -@@ -4120,7 +4095,7 @@ + +@@ -4074,7 +4048,7 @@ "\t%s was compiled for kernel version %s\n" "\twhile this kernel is version %s", flag_force_load ? "warning: " : "", @@ -345,7 +526,7 @@ Index: busybox-1.7.2/modutils/insmod.c if (!flag_force_load) goto out; } -@@ -4173,7 +4148,7 @@ +@@ -4116,7 +4090,7 @@ hide_special_symbols(f); #if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS @@ -354,14 +535,44 @@ Index: busybox-1.7.2/modutils/insmod.c #endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */ new_create_module_ksymtab(f); -@@ -4220,30 +4195,22 @@ +@@ -4125,7 +4099,7 @@ + m_size = obj_load_size(f); + + m_addr = create_module(m_name, m_size); +- if (m_addr == (ElfW(Addr))(-1)) switch (errno) { ++ if (m_addr == -1) switch (errno) { + case EEXIST: + bb_error_msg_and_die("a module named %s already exists", m_name); + case ENOMEM: +@@ -4141,36 +4115,37 @@ + * now we can load them directly into the kernel memory + */ + if (!obj_load_progbits(fp, f, (char*)m_addr)) { +- delete_module(m_name, 0); ++ delete_module(m_name); + goto out; + } + #endif + + if (!obj_relocate(f, m_addr)) { +- delete_module(m_name, 0); ++ delete_module(m_name); + goto out; + } + + if (!new_init_module(m_name, f, m_size)) { +- delete_module(m_name, 0); ++ delete_module(m_name); + goto out; + } + if (flag_print_load_map) print_load_map(f); - exit_status = EXIT_SUCCESS; -- -+ ret = 0; - out: ++ ret = EXIT_SUCCESS; + + out: #if ENABLE_FEATURE_CLEAN_UP if (fp) fclose(fp); @@ -377,29 +588,36 @@ Index: busybox-1.7.2/modutils/insmod.c - return exit_status; + return ret; } -- -- - #endif -- + #endif /* ENABLE_FEATURE_2_4_MODULES */ +@@ -4182,15 +4157,8 @@ #if ENABLE_FEATURE_2_6_MODULES + + #include - --#include --#include --#include -- +-#if defined __UCLIBC__ && !ENABLE_FEATURE_2_4_MODULES +-/* big time suckage. The old prototype above renders our nice fwd-decl wrong */ +-extern int init_module(void *module, unsigned long len, const char *options); +-#else + #include + #include +-#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) +-#endif + /* We use error numbers in a loose translation... */ static const char *moderror(int err) - { -@@ -4261,19 +4228,32 @@ +@@ -4209,22 +4177,32 @@ } } --int insmod_ng_main(int argc, char **argv); --int insmod_ng_main(int argc, char **argv) +-#if !ENABLE_FEATURE_2_4_MODULES +-int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +-int insmod_main(int argc ATTRIBUTE_UNUSED, char **argv) +-#else +-static int insmod_ng_main(int argc ATTRIBUTE_UNUSED, char **argv) +-#endif +int insmod_main_26(int argc, char **argv) { -- long ret; - size_t len; + char *filename, *options; + struct utsname myuname; @@ -429,12 +647,20 @@ Index: busybox-1.7.2/modutils/insmod.c /* Rest is options */ options = xzalloc(1); optlen = 0; -@@ -4283,36 +4263,47 @@ +@@ -4234,41 +4212,47 @@ optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv); } -#if 0 -- /* Any special reason why mmap? It isn't performace critical... */ +- /* Any special reason why mmap? It isn't performance critical. -vda */ +- /* Yes, xmalloc'ing can use *alot* of RAM. Don't forget that there are +- * modules out there that are half a megabyte! mmap()ing is way nicer +- * for small mem boxes, i guess. */ +- /* But after load, these modules will take up that 0.5mb in kernel +- * anyway. Using malloc here causes only a transient spike to 1mb, +- * after module is loaded, we go back to normal 0.5mb usage +- * (in kernel). Also, mmap isn't magic - when we touch mapped data, +- * we use memory. -vda */ - int fd; - struct stat st; - unsigned long len; @@ -455,18 +681,19 @@ Index: busybox-1.7.2/modutils/insmod.c len = MAXINT(ssize_t); - map = xmalloc_open_read_close(filename, &len); -#endif -- + map = xmalloc_open_read_close(g_filename, &len); - ret = syscall(__NR_init_module, map, len, options); - if (ret != 0) { - bb_perror_msg_and_die("cannot insert '%s': %s (%li)", -- filename, moderror(errno), ret); ++ ret = syscall(__NR_init_module, map, len, options); ++ if (ret != 0) { ++ bb_perror_msg_and_die("cannot insert '%s': %s (%li)", + g_filename, moderror(errno), ret); - } ++ } +done: + if (g_filename && (g_filename != filename)) + free(g_filename); +- if (init_module(map, len, options) != 0) +- bb_error_msg_and_die("cannot insert '%s': %s", +- filename, moderror(errno)); - return 0; + return ret; }