Skip to content

Commit 2253257

Browse files
rgetzvapier
authored andcommitted
Blackfin: reject outdated/unused/wrong relocation types
All kernel modules are required to be built with -mlong-calls and thus should not generate any of these relocations. If they do, it means the module has not been compiled properly, so rather than trying to handle them (and running into random run time errors) just error out on module load to force the module to be compiled correctly. Signed-off-by: Robin Getz <robin.getz@analog.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
1 parent c014e15 commit 2253257

1 file changed

Lines changed: 8 additions & 34 deletions

File tree

‎arch/blackfin/kernel/module.c‎

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -243,40 +243,6 @@ apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
243243
#endif
244244
switch (ELF32_R_TYPE(rel[i].r_info)) {
245245

246-
case R_BFIN_PCREL24:
247-
case R_BFIN_PCREL24_JUMP_L:
248-
/* Add the value, subtract its postition */
249-
location16 =
250-
(uint16_t *) (sechdrs[sechdrs[relsec].sh_info].
251-
sh_addr + rel[i].r_offset - 2);
252-
location32 = (uint32_t *) location16;
253-
value -= (uint32_t) location32;
254-
value >>= 1;
255-
if ((value & 0xFF000000) != 0 &&
256-
(value & 0xFF000000) != 0xFF000000) {
257-
printk(KERN_ERR "module %s: relocation overflow\n",
258-
mod->name);
259-
return -ENOEXEC;
260-
}
261-
pr_debug("value is %x, before %x-%x after %x-%x\n", value,
262-
*location16, *(location16 + 1),
263-
(*location16 & 0xff00) | (value >> 16 & 0x00ff),
264-
value & 0xffff);
265-
*location16 =
266-
(*location16 & 0xff00) | (value >> 16 & 0x00ff);
267-
*(location16 + 1) = value & 0xffff;
268-
break;
269-
case R_BFIN_PCREL12_JUMP:
270-
case R_BFIN_PCREL12_JUMP_S:
271-
value -= (uint32_t) location32;
272-
value >>= 1;
273-
*location16 = (value & 0xfff);
274-
break;
275-
case R_BFIN_PCREL10:
276-
value -= (uint32_t) location32;
277-
value >>= 1;
278-
*location16 = (value & 0x3ff);
279-
break;
280246
case R_BFIN_LUIMM16:
281247
pr_debug("before %x after %x\n", *location16,
282248
(value & 0xffff));
@@ -302,6 +268,14 @@ apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
302268
pr_debug("before %x after %x\n", *location32, value);
303269
*location32 = value;
304270
break;
271+
case R_BFIN_PCREL24:
272+
case R_BFIN_PCREL24_JUMP_L:
273+
case R_BFIN_PCREL12_JUMP:
274+
case R_BFIN_PCREL12_JUMP_S:
275+
case R_BFIN_PCREL10:
276+
printk(KERN_ERR "module %s: Unsupported relocation: %u (no -mlong-calls?)\n"
277+
mod->name, ELF32_R_TYPE(rel[i].r_info));
278+
return -ENOEXEC;
305279
default:
306280
printk(KERN_ERR "module %s: Unknown relocation: %u\n",
307281
mod->name, ELF32_R_TYPE(rel[i].r_info));

0 commit comments

Comments
 (0)