perf tools: Fix generation of pmu list
[cascardo/linux.git] / kernel / module.c
index a4e6097..4edbd9c 100644 (file)
@@ -2429,7 +2429,8 @@ static int copy_and_check(struct load_info *info,
                goto free_hdr;
        }
 
-       if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) {
+       if (hdr->e_shoff >= len ||
+           hdr->e_shnum * sizeof(Elf_Shdr) > len - hdr->e_shoff) {
                err = -ENOEXEC;
                goto free_hdr;
        }