arm64: module: don't BUG when exceeding preallocated PLT count
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 6 Mar 2018 17:15:31 +0000 (17:15 +0000)
committerWill Deacon <will.deacon@arm.com>
Thu, 8 Mar 2018 13:49:26 +0000 (13:49 +0000)
When PLTs are emitted at relocation time, we really should not exceed
the number that we counted when parsing the relocation tables, and so
currently, we BUG() on this condition. However, even though this is a
clear bug in this particular piece of code, we can easily recover by
failing to load the module.

So instead, return 0 from module_emit_plt_entry() if this condition
occurs, which is not a valid kernel address, and can hence serve as
a flag value that makes the relocation routine bail out.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/kernel/module-plts.c
arch/arm64/kernel/module.c

index ea640f92fe5adaf92526ee252fb8fbc73348d0b6..6bf07c602bd445f03f1ded03a6a0bfb6a55a9eba 100644 (file)
@@ -36,7 +36,8 @@ u64 module_emit_plt_entry(struct module *mod, void *loc, const Elf64_Rela *rela,
                return (u64)&plt[i - 1];
 
        pltsec->plt_num_entries++;
-       BUG_ON(pltsec->plt_num_entries > pltsec->plt_max_entries);
+       if (WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries))
+               return 0;
 
        return (u64)&plt[i];
 }
index f469e04359031c1a172570f756769eb96366675f..c8c6c2828b79058b0d5eb9cd99ee084dc20ea47a 100644 (file)
@@ -386,6 +386,8 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
                        if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
                            ovf == -ERANGE) {
                                val = module_emit_plt_entry(me, loc, &rel[i], sym);
+                               if (!val)
+                                       return -ENOEXEC;
                                ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2,
                                                     26, AARCH64_INSN_IMM_26);
                        }