diff options
Diffstat (limited to 'arch/mips/kernel/module.c')
| -rw-r--r-- | arch/mips/kernel/module.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index a5066b1c3de3..4f8c3cba8c0c 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c | |||
| @@ -39,8 +39,6 @@ struct mips_hi16 { | |||
| 39 | Elf_Addr value; | 39 | Elf_Addr value; |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | static struct mips_hi16 *mips_hi16_list; | ||
| 43 | |||
| 44 | static LIST_HEAD(dbe_list); | 42 | static LIST_HEAD(dbe_list); |
| 45 | static DEFINE_SPINLOCK(dbe_lock); | 43 | static DEFINE_SPINLOCK(dbe_lock); |
| 46 | 44 | ||
| @@ -128,8 +126,8 @@ static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v) | |||
| 128 | 126 | ||
| 129 | n->addr = (Elf_Addr *)location; | 127 | n->addr = (Elf_Addr *)location; |
| 130 | n->value = v; | 128 | n->value = v; |
| 131 | n->next = mips_hi16_list; | 129 | n->next = me->arch.r_mips_hi16_list; |
| 132 | mips_hi16_list = n; | 130 | me->arch.r_mips_hi16_list = n; |
| 133 | 131 | ||
| 134 | return 0; | 132 | return 0; |
| 135 | } | 133 | } |
| @@ -142,18 +140,28 @@ static int apply_r_mips_hi16_rela(struct module *me, u32 *location, Elf_Addr v) | |||
| 142 | return 0; | 140 | return 0; |
| 143 | } | 141 | } |
| 144 | 142 | ||
| 143 | static void free_relocation_chain(struct mips_hi16 *l) | ||
| 144 | { | ||
| 145 | struct mips_hi16 *next; | ||
| 146 | |||
| 147 | while (l) { | ||
| 148 | next = l->next; | ||
| 149 | kfree(l); | ||
| 150 | l = next; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 145 | static int apply_r_mips_lo16_rel(struct module *me, u32 *location, Elf_Addr v) | 154 | static int apply_r_mips_lo16_rel(struct module *me, u32 *location, Elf_Addr v) |
| 146 | { | 155 | { |
| 147 | unsigned long insnlo = *location; | 156 | unsigned long insnlo = *location; |
| 157 | struct mips_hi16 *l; | ||
| 148 | Elf_Addr val, vallo; | 158 | Elf_Addr val, vallo; |
| 149 | 159 | ||
| 150 | /* Sign extend the addend we extract from the lo insn. */ | 160 | /* Sign extend the addend we extract from the lo insn. */ |
| 151 | vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000; | 161 | vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000; |
| 152 | 162 | ||
| 153 | if (mips_hi16_list != NULL) { | 163 | if (me->arch.r_mips_hi16_list != NULL) { |
| 154 | struct mips_hi16 *l; | 164 | l = me->arch.r_mips_hi16_list; |
| 155 | |||
| 156 | l = mips_hi16_list; | ||
| 157 | while (l != NULL) { | 165 | while (l != NULL) { |
| 158 | struct mips_hi16 *next; | 166 | struct mips_hi16 *next; |
| 159 | unsigned long insn; | 167 | unsigned long insn; |
| @@ -188,7 +196,7 @@ static int apply_r_mips_lo16_rel(struct module *me, u32 *location, Elf_Addr v) | |||
| 188 | l = next; | 196 | l = next; |
| 189 | } | 197 | } |
| 190 | 198 | ||
| 191 | mips_hi16_list = NULL; | 199 | me->arch.r_mips_hi16_list = NULL; |
| 192 | } | 200 | } |
| 193 | 201 | ||
| 194 | /* | 202 | /* |
| @@ -201,6 +209,9 @@ static int apply_r_mips_lo16_rel(struct module *me, u32 *location, Elf_Addr v) | |||
| 201 | return 0; | 209 | return 0; |
| 202 | 210 | ||
| 203 | out_danger: | 211 | out_danger: |
| 212 | free_relocation_chain(l); | ||
| 213 | me->arch.r_mips_hi16_list = NULL; | ||
| 214 | |||
| 204 | pr_err("module %s: dangerous R_MIPS_LO16 REL relocation\n", me->name); | 215 | pr_err("module %s: dangerous R_MIPS_LO16 REL relocation\n", me->name); |
| 205 | 216 | ||
| 206 | return -ENOEXEC; | 217 | return -ENOEXEC; |
| @@ -273,6 +284,7 @@ int apply_relocate(Elf_Shdr *sechdrs, const char *strtab, | |||
| 273 | pr_debug("Applying relocate section %u to %u\n", relsec, | 284 | pr_debug("Applying relocate section %u to %u\n", relsec, |
| 274 | sechdrs[relsec].sh_info); | 285 | sechdrs[relsec].sh_info); |
| 275 | 286 | ||
| 287 | me->arch.r_mips_hi16_list = NULL; | ||
| 276 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | 288 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { |
| 277 | /* This is where to make the change */ | 289 | /* This is where to make the change */ |
| 278 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | 290 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr |
| @@ -296,6 +308,19 @@ int apply_relocate(Elf_Shdr *sechdrs, const char *strtab, | |||
| 296 | return res; | 308 | return res; |
| 297 | } | 309 | } |
| 298 | 310 | ||
| 311 | /* | ||
| 312 | * Normally the hi16 list should be deallocated at this point. A | ||
| 313 | * malformed binary however could contain a series of R_MIPS_HI16 | ||
| 314 | * relocations not followed by a R_MIPS_LO16 relocation. In that | ||
| 315 | * case, free up the list and return an error. | ||
| 316 | */ | ||
| 317 | if (me->arch.r_mips_hi16_list) { | ||
| 318 | free_relocation_chain(me->arch.r_mips_hi16_list); | ||
| 319 | me->arch.r_mips_hi16_list = NULL; | ||
| 320 | |||
| 321 | return -ENOEXEC; | ||
| 322 | } | ||
| 323 | |||
| 299 | return 0; | 324 | return 0; |
| 300 | } | 325 | } |
| 301 | 326 | ||
