Lines Matching +full:no +full:- +full:pc +full:- +full:write
1 // SPDX-License-Identifier: GPL-2.0+
25 #include <asm/nospec-branch.h>
79 module_memfree(mod->arch.trampolines_start); in module_arch_cleanup()
86 mod->state == MODULE_STATE_LIVE) in module_arch_freeing_init()
89 vfree(mod->arch.syminfo); in module_arch_freeing_init()
90 mod->arch.syminfo = NULL; in module_arch_freeing_init()
97 info = me->arch.syminfo + ELF_R_SYM (rela->r_info); in check_rela()
98 switch (ELF_R_TYPE (rela->r_info)) { in check_rela()
104 case R_390_GOTENT: /* 32 bit PC rel. to GOT entry shifted by 1. */ in check_rela()
111 if (info->got_offset == -1UL) { in check_rela()
112 info->got_offset = me->arch.got_size; in check_rela()
113 me->arch.got_size += sizeof(void*); in check_rela()
116 case R_390_PLT16DBL: /* 16 bit PC rel. PLT shifted by 1. */ in check_rela()
117 case R_390_PLT32DBL: /* 32 bit PC rel. PLT shifted by 1. */ in check_rela()
118 case R_390_PLT32: /* 32 bit PC relative PLT address. */ in check_rela()
119 case R_390_PLT64: /* 64 bit PC relative PLT address. */ in check_rela()
123 if (info->plt_offset == -1UL) { in check_rela()
124 info->plt_offset = me->arch.plt_size; in check_rela()
125 me->arch.plt_size += PLT_ENTRY_SIZE; in check_rela()
133 modules linked with -shared. */ in check_rela()
154 for (i = 0; i < hdr->e_shnum; i++) in module_frob_arch_sections()
161 printk(KERN_ERR "module %s: no symbol table\n", me->name); in module_frob_arch_sections()
162 return -ENOEXEC; in module_frob_arch_sections()
166 me->arch.nsyms = symtab->sh_size / sizeof(Elf_Sym); in module_frob_arch_sections()
167 me->arch.syminfo = vmalloc(array_size(sizeof(struct mod_arch_syminfo), in module_frob_arch_sections()
168 me->arch.nsyms)); in module_frob_arch_sections()
169 if (!me->arch.syminfo) in module_frob_arch_sections()
170 return -ENOMEM; in module_frob_arch_sections()
171 symbols = (void *) hdr + symtab->sh_offset; in module_frob_arch_sections()
172 strings = (void *) hdr + sechdrs[symtab->sh_link].sh_offset; in module_frob_arch_sections()
173 for (i = 0; i < me->arch.nsyms; i++) { in module_frob_arch_sections()
179 me->arch.syminfo[i].got_offset = -1UL; in module_frob_arch_sections()
180 me->arch.syminfo[i].plt_offset = -1UL; in module_frob_arch_sections()
181 me->arch.syminfo[i].got_initialized = 0; in module_frob_arch_sections()
182 me->arch.syminfo[i].plt_initialized = 0; in module_frob_arch_sections()
186 me->arch.got_size = me->arch.plt_size = 0; in module_frob_arch_sections()
187 for (i = 0; i < hdr->e_shnum; i++) { in module_frob_arch_sections()
198 mod_mem = &me->mem[MOD_TEXT]; in module_frob_arch_sections()
199 mod_mem->size = ALIGN(mod_mem->size, 4); in module_frob_arch_sections()
200 me->arch.got_offset = mod_mem->size; in module_frob_arch_sections()
201 mod_mem->size += me->arch.got_size; in module_frob_arch_sections()
202 me->arch.plt_offset = mod_mem->size; in module_frob_arch_sections()
203 if (me->arch.plt_size) { in module_frob_arch_sections()
205 me->arch.plt_size += PLT_ENTRY_SIZE; in module_frob_arch_sections()
206 mod_mem->size += me->arch.plt_size; in module_frob_arch_sections()
213 void *(*write)(void *dest, const void *src, size_t len)) in apply_rela_bits()
219 if (val & ((1UL << shift) - 1)) in apply_rela_bits()
220 return -ENOEXEC; in apply_rela_bits()
223 min = -(1L << (bits - 1)); in apply_rela_bits()
224 max = (1L << (bits - 1)) - 1; in apply_rela_bits()
226 return -ENOEXEC; in apply_rela_bits()
229 umax = ((1UL << (bits - 1)) << 1) - 1; in apply_rela_bits()
231 return -ENOEXEC; in apply_rela_bits()
236 write(dest, &tmp, 1); in apply_rela_bits()
240 write(dest, &tmp, 2); in apply_rela_bits()
243 write(dest, &tmp, 2); in apply_rela_bits()
247 write(dest, &tmp, 4); in apply_rela_bits()
250 write(dest, &tmp, 4); in apply_rela_bits()
253 write(dest, &tmp, 8); in apply_rela_bits()
260 void *(*write)(void *dest, const void *src, size_t len)) in apply_rela()
265 int rc = -ENOEXEC; in apply_rela()
268 loc = base + rela->r_offset; in apply_rela()
271 r_sym = ELF_R_SYM(rela->r_info); in apply_rela()
272 r_type = ELF_R_TYPE(rela->r_info); in apply_rela()
273 info = me->arch.syminfo + r_sym; in apply_rela()
277 case R_390_NONE: /* No relocation. */ in apply_rela()
286 val += rela->r_addend; in apply_rela()
288 rc = apply_rela_bits(loc, val, 0, 8, 0, write); in apply_rela()
290 rc = apply_rela_bits(loc, val, 0, 12, 0, write); in apply_rela()
292 rc = apply_rela_bits(loc, val, 0, 16, 0, write); in apply_rela()
294 rc = apply_rela_bits(loc, val, 1, 20, 0, write); in apply_rela()
296 rc = apply_rela_bits(loc, val, 0, 32, 0, write); in apply_rela()
298 rc = apply_rela_bits(loc, val, 0, 64, 0, write); in apply_rela()
300 case R_390_PC16: /* PC relative 16 bit. */ in apply_rela()
301 case R_390_PC16DBL: /* PC relative 16 bit shifted by 1. */ in apply_rela()
302 case R_390_PC32DBL: /* PC relative 32 bit shifted by 1. */ in apply_rela()
303 case R_390_PC32: /* PC relative 32 bit. */ in apply_rela()
304 case R_390_PC64: /* PC relative 64 bit. */ in apply_rela()
305 val += rela->r_addend - loc; in apply_rela()
307 rc = apply_rela_bits(loc, val, 1, 16, 0, write); in apply_rela()
309 rc = apply_rela_bits(loc, val, 1, 16, 1, write); in apply_rela()
311 rc = apply_rela_bits(loc, val, 1, 32, 1, write); in apply_rela()
313 rc = apply_rela_bits(loc, val, 1, 32, 0, write); in apply_rela()
315 rc = apply_rela_bits(loc, val, 1, 64, 0, write); in apply_rela()
322 case R_390_GOTENT: /* 32 bit PC rel. to GOT entry shifted by 1. */ in apply_rela()
329 if (info->got_initialized == 0) { in apply_rela()
330 Elf_Addr *gotent = me->mem[MOD_TEXT].base + in apply_rela()
331 me->arch.got_offset + in apply_rela()
332 info->got_offset; in apply_rela()
334 write(gotent, &val, sizeof(*gotent)); in apply_rela()
335 info->got_initialized = 1; in apply_rela()
337 val = info->got_offset + rela->r_addend; in apply_rela()
340 rc = apply_rela_bits(loc, val, 0, 12, 0, write); in apply_rela()
343 rc = apply_rela_bits(loc, val, 0, 16, 0, write); in apply_rela()
346 rc = apply_rela_bits(loc, val, 1, 20, 0, write); in apply_rela()
349 rc = apply_rela_bits(loc, val, 0, 32, 0, write); in apply_rela()
352 rc = apply_rela_bits(loc, val, 0, 64, 0, write); in apply_rela()
355 val += (Elf_Addr)me->mem[MOD_TEXT].base + in apply_rela()
356 me->arch.got_offset - loc; in apply_rela()
357 rc = apply_rela_bits(loc, val, 1, 32, 1, write); in apply_rela()
360 case R_390_PLT16DBL: /* 16 bit PC rel. PLT shifted by 1. */ in apply_rela()
361 case R_390_PLT32DBL: /* 32 bit PC rel. PLT shifted by 1. */ in apply_rela()
362 case R_390_PLT32: /* 32 bit PC relative PLT address. */ in apply_rela()
363 case R_390_PLT64: /* 64 bit PC relative PLT address. */ in apply_rela()
367 if (info->plt_initialized == 0) { in apply_rela()
372 plt_base = me->mem[MOD_TEXT].base + me->arch.plt_offset; in apply_rela()
373 ip = plt_base + info->plt_offset; in apply_rela()
379 jump_r1 = plt_base + me->arch.plt_size - in apply_rela()
383 *(int *)&insn[10] = (jump_r1 - (ip + 8)) / 2; in apply_rela()
389 write(ip, insn, sizeof(insn)); in apply_rela()
390 info->plt_initialized = 1; in apply_rela()
395 val = me->arch.plt_offset - me->arch.got_offset + in apply_rela()
396 info->plt_offset + rela->r_addend; in apply_rela()
399 val - loc + 0xffffUL < 0x1ffffeUL) || in apply_rela()
401 val - loc + 0xffffffffULL < 0x1fffffffeULL))) in apply_rela()
402 val = (Elf_Addr) me->mem[MOD_TEXT].base + in apply_rela()
403 me->arch.plt_offset + in apply_rela()
404 info->plt_offset; in apply_rela()
405 val += rela->r_addend - loc; in apply_rela()
408 rc = apply_rela_bits(loc, val, 1, 16, 1, write); in apply_rela()
410 rc = apply_rela_bits(loc, val, 0, 16, 0, write); in apply_rela()
412 rc = apply_rela_bits(loc, val, 1, 32, 1, write); in apply_rela()
415 rc = apply_rela_bits(loc, val, 0, 32, 0, write); in apply_rela()
418 rc = apply_rela_bits(loc, val, 0, 64, 0, write); in apply_rela()
423 val = val + rela->r_addend - in apply_rela()
424 ((Elf_Addr) me->mem[MOD_TEXT].base + me->arch.got_offset); in apply_rela()
426 rc = apply_rela_bits(loc, val, 0, 16, 0, write); in apply_rela()
428 rc = apply_rela_bits(loc, val, 0, 32, 0, write); in apply_rela()
430 rc = apply_rela_bits(loc, val, 0, 64, 0, write); in apply_rela()
432 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */ in apply_rela()
433 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */ in apply_rela()
434 val = (Elf_Addr) me->mem[MOD_TEXT].base + me->arch.got_offset + in apply_rela()
435 rela->r_addend - loc; in apply_rela()
437 rc = apply_rela_bits(loc, val, 1, 32, 0, write); in apply_rela()
439 rc = apply_rela_bits(loc, val, 1, 32, 1, write); in apply_rela()
446 modules linked with -shared. */ in apply_rela()
447 return -ENOEXEC; in apply_rela()
450 me->name, r_type); in apply_rela()
451 return -ENOEXEC; in apply_rela()
456 me->name, strtab + symtab[r_sym].st_name, in apply_rela()
466 void *(*write)(void *dest, const void *src, size_t len)) in __apply_relocate_add()
482 rc = apply_rela(rela, base, symtab, strtab, me, write); in __apply_relocate_add()
493 bool early = me->state == MODULE_STATE_UNFORMED; in apply_relocate_add()
494 void *(*write)(void *, const void *, size_t) = memcpy; in apply_relocate_add() local
497 write = s390_kernel_write; in apply_relocate_add()
500 write); in apply_relocate_add()
511 size = FTRACE_HOTPATCH_TRAMPOLINES_SIZE(s->sh_size); in module_alloc_ftrace_hotpatch_trampolines()
515 return -ENOMEM; in module_alloc_ftrace_hotpatch_trampolines()
519 me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start; in module_alloc_ftrace_hotpatch_trampolines()
520 me->arch.trampolines_end = (struct ftrace_hotpatch_trampoline *)end; in module_alloc_ftrace_hotpatch_trampolines()
521 me->arch.next_trampoline = me->arch.trampolines_start; in module_alloc_ftrace_hotpatch_trampolines()
539 !nospec_disable && me->arch.plt_size) { in module_finalize()
542 ij = me->mem[MOD_TEXT].base + me->arch.plt_offset + in module_finalize()
543 me->arch.plt_size - PLT_ENTRY_SIZE; in module_finalize()
549 secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; in module_finalize()
550 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) { in module_finalize()
551 aseg = (void *) s->sh_addr; in module_finalize()
552 secname = secstrings + s->sh_name; in module_finalize()
556 apply_alternatives(aseg, aseg + s->sh_size); in module_finalize()
560 nospec_revert(aseg, aseg + s->sh_size); in module_finalize()
564 nospec_revert(aseg, aseg + s->sh_size); in module_finalize()